From 1512388b59efaa75c4f87e7139b878d0a58d8101 Mon Sep 17 00:00:00 2001 From: Gordon Klaus Date: Mon, 4 Aug 2025 09:37:08 +0200 Subject: [PATCH 01/42] [nrf noup] samples: bluetooth: Add support for nRF54lm20a to hci_uart Add support for nRF54lm20a to the hci_uart sample. Signed-off-by: Gordon Klaus --- .../boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay | 12 ++++++++++++ samples/bluetooth/hci_uart/sample.yaml | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 samples/bluetooth/hci_uart/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay diff --git a/samples/bluetooth/hci_uart/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay b/samples/bluetooth/hci_uart/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay new file mode 100644 index 00000000000..0388a57baec --- /dev/null +++ b/samples/bluetooth/hci_uart/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&uart20 { + compatible = "nordic,nrf-uarte"; + current-speed = <1000000>; + status = "okay"; + hw-flow-control; +}; diff --git a/samples/bluetooth/hci_uart/sample.yaml b/samples/bluetooth/hci_uart/sample.yaml index 97ad6c561b2..4dc5c6e9036 100644 --- a/samples/bluetooth/hci_uart/sample.yaml +++ b/samples/bluetooth/hci_uart/sample.yaml @@ -8,10 +8,14 @@ tests: - nrf52dk/nrf52832 - nrf52840dk/nrf52840 - nrf21540dk/nrf52840 + - nrf54l15dk/nrf54l15/cpuapp + - nrf54lm20dk/nrf54lm20a/cpuapp integration_platforms: - nrf52dk/nrf52832 - nrf52840dk/nrf52840 - nrf21540dk/nrf52840 + - nrf54l15dk/nrf54l15/cpuapp + - nrf54lm20dk/nrf54lm20a/cpuapp tags: - uart - bluetooth From 8d7b9c9d00552a89eb04755435e24d555894d819 Mon Sep 17 00:00:00 2001 From: Gordon Klaus Date: Mon, 4 Aug 2025 09:38:37 +0200 Subject: [PATCH 02/42] [nrf fromlist] samples: bluetooth: Add support for nRF54lm20a to two samples Add support for nRF54lm20a to the beacon and peripheral_hr samples. Upstream PR #: 93917 Signed-off-by: Gordon Klaus --- samples/bluetooth/beacon/sample.yaml | 2 ++ samples/bluetooth/peripheral_hr/sample.yaml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/samples/bluetooth/beacon/sample.yaml b/samples/bluetooth/beacon/sample.yaml index 819ac3d3002..00215341924 100644 --- a/samples/bluetooth/beacon/sample.yaml +++ b/samples/bluetooth/beacon/sample.yaml @@ -10,6 +10,7 @@ tests: - nrf52dk/nrf52832 - nrf54l15dk/nrf54l15/cpuapp - ophelia4ev/nrf54l15/cpuapp + - nrf54lm20dk/nrf54lm20a/cpuapp tags: bluetooth integration_platforms: - qemu_cortex_m3 @@ -17,6 +18,7 @@ tests: - nrf52dk/nrf52832 - nrf54l15dk/nrf54l15/cpuapp - ophelia4ev/nrf54l15/cpuapp + - nrf54lm20dk/nrf54lm20a/cpuapp sample.bluetooth.beacon-coex: extra_args: - CONF_FILE="prj-coex.conf" diff --git a/samples/bluetooth/peripheral_hr/sample.yaml b/samples/bluetooth/peripheral_hr/sample.yaml index 8b0722d169f..22bc7667461 100644 --- a/samples/bluetooth/peripheral_hr/sample.yaml +++ b/samples/bluetooth/peripheral_hr/sample.yaml @@ -15,6 +15,7 @@ tests: - nrf5340dk/nrf5340/cpuapp - nrf54l15dk/nrf54l15/cpuapp - ophelia4ev/nrf54l15/cpuapp + - nrf54lm20dk/nrf54lm20a/cpuapp integration_platforms: - qemu_cortex_m3 - nrf52_bsim @@ -25,6 +26,7 @@ tests: - nrf5340dk/nrf5340/cpuapp - nrf54l15dk/nrf54l15/cpuapp - ophelia4ev/nrf54l15/cpuapp + - nrf54lm20dk/nrf54lm20a/cpuapp tags: bluetooth sample.bluetooth.peripheral_hr.minimal: harness: bluetooth From 2e2beca20d6bd81740b32d2f2da8d741fec941dd Mon Sep 17 00:00:00 2001 From: Michal Kozikowski Date: Tue, 29 Jul 2025 12:44:13 +0200 Subject: [PATCH 03/42] Revert "[nrf noup] mcuboot: Add CONFIG_MCUBOOT_BOOTLOADER_USES_SHA512" This reverts commit 6b3791792fc6b221fd6f5bc634256d08e144a7c3. Changes were moved to upstream in PR #93813. Signed-off-by: Michal Kozikowski --- modules/Kconfig.mcuboot | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index 694f4069b90..c02ee43f5eb 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -288,11 +288,6 @@ config MCUBOOT_BOOTLOADER_NO_DOWNGRADE MCUBOOT_DOWNGRADE_PREVENTION option enabled. endif -config MCUBOOT_BOOTLOADER_USES_SHA512 - bool "MCUboot uses SHA512 for image hash" - help - MCUboot has been compiled to verify images using SHA512. - config MCUBOOT_APPLICATION_FIRMWARE_UPDATER bool "Application is firmware updater image" depends on MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER From c136755381da8ba816a7be35bc0ff8050fc559df Mon Sep 17 00:00:00 2001 From: Michal Kozikowski Date: Wed, 23 Jul 2025 09:53:11 +0200 Subject: [PATCH 04/42] [nrf fromtree] cmake: mcuboot: SHA512/pure image signing Update signing script to use proper arguments for imgtool when SHA512 or pure signature is needed. Signed-off-by: Michal Kozikowski (cherry picked from commit 6c72cd3e65e3d3a1c9b8026be5fd6207b06d8f81) --- cmake/mcuboot.cmake | 7 +++++++ modules/Kconfig.mcuboot | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/cmake/mcuboot.cmake b/cmake/mcuboot.cmake index d2fcf68e889..ac37b175a31 100644 --- a/cmake/mcuboot.cmake +++ b/cmake/mcuboot.cmake @@ -152,6 +152,13 @@ function(zephyr_mcuboot_tasks) set(imgtool_args --align ${write_block_size} ${imgtool_args}) endif() + # Set proper hash calculation algorithm for signing + if(CONFIG_MCUBOOT_BOOTLOADER_SIGNATURE_TYPE_PURE) + set(imgtool_args --pure ${imgtool_args}) + elseif(CONFIG_MCUBOOT_BOOTLOADER_USES_SHA512) + set(imgtool_args --sha 512 ${imgtool_args}) + endif() + # Extensionless prefix of any output file. set(output ${ZEPHYR_BINARY_DIR}/${KERNEL_NAME}) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index c02ee43f5eb..a95dc34b72f 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -288,6 +288,18 @@ config MCUBOOT_BOOTLOADER_NO_DOWNGRADE MCUBOOT_DOWNGRADE_PREVENTION option enabled. endif +config MCUBOOT_BOOTLOADER_USES_SHA512 + bool "MCUboot uses SHA512 for image hash" + help + MCUboot has been compiled to verify images using SHA512. + +config MCUBOOT_BOOTLOADER_SIGNATURE_TYPE_PURE + bool "Signature is verified over an image rather than sha of an image" + help + MCUboot has been compiled to verify images using pure signature + verification, i.e., the signature is verified over the image rather + than the SHA of the image. + config MCUBOOT_APPLICATION_FIRMWARE_UPDATER bool "Application is firmware updater image" depends on MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER From c1ddd14ed35f577e22cdd0021781a70bda2a0926 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 31 Jul 2025 14:26:40 +0200 Subject: [PATCH 05/42] [nrf noup] bluetooth: host: Allow auto swap feature without privacy Allow to use CONFIG_BT_ID_AUTO_SWAP_MATCHING_BONDS Kconfig option even if CONFIG_BT_PRIVACY is disabled. This is because CONFIG_BT_PRIVACY configures privacy of local device will still allows to resolve peer address. During pairing, peer device may send its Identity Address and IRK which then can be used for address resolution. This doesn't require CONFIG_BT_PRIVACY be enabled. nrf-squash! [nrf noup] bluetooth: host: Add support for bonding with same peer Signed-off-by: Pavel Vasilyev --- subsys/bluetooth/host/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 3830745417a..da1928758fd 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -633,7 +633,7 @@ config BT_ID_UNPAIR_MATCHING_BONDS config BT_ID_AUTO_SWAP_MATCHING_BONDS bool "Automatically swap conflicting entries in the Resolving List" depends on !BT_ID_UNPAIR_MATCHING_BONDS - depends on BT_PRIVACY && BT_PERIPHERAL && !BT_CENTRAL + depends on BT_SMP && BT_PERIPHERAL && !BT_CENTRAL help If this option is enabled, the Host will not add a new bond with the same peer address (or IRK) to the Resolving List if there is From 6fb16ab25d1adff73dbde6b89defcc6ce8a20734 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Tue, 29 Jul 2025 17:30:25 +0100 Subject: [PATCH 06/42] [nrf fromlist] doc: extensions: kconfig: Add support for sysbuild Adds support for outputting details on sysbuild Kconfigs for use with the documentation Kconfig lookup tool Upstream PR #: 93861 Signed-off-by: Jamie McCrae --- doc/_extensions/zephyr/kconfig/__init__.py | 276 +++++++++++---------- 1 file changed, 146 insertions(+), 130 deletions(-) diff --git a/doc/_extensions/zephyr/kconfig/__init__.py b/doc/_extensions/zephyr/kconfig/__init__.py index 6bf828a9088..eb1903b1898 100644 --- a/doc/_extensions/zephyr/kconfig/__init__.py +++ b/doc/_extensions/zephyr/kconfig/__init__.py @@ -70,19 +70,24 @@ ZEPHYR_BASE = Path(__file__).parents[4] -def kconfig_load(app: Sphinx) -> tuple[kconfiglib.Kconfig, dict[str, str]]: +def kconfig_load(app: Sphinx) -> tuple[kconfiglib.Kconfig, kconfiglib.Kconfig, dict[str, str]]: """Load Kconfig""" with TemporaryDirectory() as td: modules = zephyr_module.parse_modules(ZEPHYR_BASE) # generate Kconfig.modules file kconfig = "" + sysbuild_kconfig = "" for module in modules: kconfig += zephyr_module.process_kconfig(module.project, module.meta) + sysbuild_kconfig += zephyr_module.process_sysbuildkconfig(module.project, module.meta) with open(Path(td) / "Kconfig.modules", "w") as f: f.write(kconfig) + with open(Path(td) / "Kconfig.sysbuild.modules", "w") as f: + f.write(sysbuild_kconfig) + # generate dummy Kconfig.dts file kconfig = "" @@ -145,6 +150,13 @@ def kconfig_load(app: Sphinx) -> tuple[kconfiglib.Kconfig, dict[str, str]]: os.environ["BOARD"] = "boards" os.environ["KCONFIG_BOARD_DIR"] = str(Path(td) / "boards") + # Sysbuild runs first + os.environ["CONFIG_"] = "SB_CONFIG_" + sysbuild_output = kconfiglib.Kconfig(ZEPHYR_BASE / "share" / "sysbuild" / "Kconfig") + + # Normal Kconfig runs second + os.environ["CONFIG_"] = "CONFIG_" + # insert external Kconfigs to the environment module_paths = dict() for module in modules: @@ -172,7 +184,7 @@ def kconfig_load(app: Sphinx) -> tuple[kconfiglib.Kconfig, dict[str, str]]: if kconfig.exists(): os.environ[f"ZEPHYR_{name_var}_KCONFIG"] = str(kconfig) - return kconfiglib.Kconfig(ZEPHYR_BASE / "Kconfig"), module_paths + return kconfiglib.Kconfig(ZEPHYR_BASE / "Kconfig"), sysbuild_output, module_paths class KconfigSearchNode(nodes.Element): @@ -332,13 +344,15 @@ def add_option(self, option): def sc_fmt(sc): + prefix = os.environ["CONFIG_"] + if isinstance(sc, kconfiglib.Symbol): if sc.nodes: - return f'CONFIG_{sc.name}' + return f'{prefix}{sc.name}' elif isinstance(sc, kconfiglib.Choice): if not sc.name: return "<choice>" - return f'<choice CONFIG_{sc.name}>' + return f'<choice {prefix}{sc.name}>' return kconfiglib.standard_sc_expr_str(sc) @@ -350,137 +364,139 @@ def kconfig_build_resources(app: Sphinx) -> None: return with progress_message("Building Kconfig database..."): - kconfig, module_paths = kconfig_load(app) + kconfig, sysbuild_kconfig, module_paths = kconfig_load(app) db = list() - for sc in sorted( - chain(kconfig.unique_defined_syms, kconfig.unique_choices), - key=lambda sc: sc.name if sc.name else "", - ): - # skip nameless symbols - if not sc.name: - continue - - # store alternative defaults (from defconfig files) - alt_defaults = list() - for node in sc.nodes: - if "defconfig" not in node.filename: + for kconfig_obj in [kconfig, sysbuild_kconfig]: + os.environ["CONFIG_"] = kconfig_obj.config_prefix + for sc in sorted( + chain(kconfig_obj.unique_defined_syms, kconfig_obj.unique_choices), + key=lambda sc: sc.name if sc.name else "", + ): + # skip nameless symbols + if not sc.name: continue - for value, cond in node.orig_defaults: - fmt = kconfiglib.expr_str(value, sc_fmt) - if cond is not sc.kconfig.y: - fmt += f" if {kconfiglib.expr_str(cond, sc_fmt)}" - alt_defaults.append([fmt, node.filename]) - - # build list of symbols that select/imply the current one - # note: all reverse dependencies are ORed together, and conditionals - # (e.g. select/imply A if B) turns into A && B. So we first split - # by OR to include all entries, and we split each one by AND to just - # take the first entry. - selected_by = list() - if isinstance(sc, kconfiglib.Symbol) and sc.rev_dep != sc.kconfig.n: - for select in kconfiglib.split_expr(sc.rev_dep, kconfiglib.OR): - sym = kconfiglib.split_expr(select, kconfiglib.AND)[0] - selected_by.append(f"CONFIG_{sym.name}") - - implied_by = list() - if isinstance(sc, kconfiglib.Symbol) and sc.weak_rev_dep != sc.kconfig.n: - for select in kconfiglib.split_expr(sc.weak_rev_dep, kconfiglib.OR): - sym = kconfiglib.split_expr(select, kconfiglib.AND)[0] - implied_by.append(f"CONFIG_{sym.name}") - - # only process nodes with prompt or help - nodes = [node for node in sc.nodes if node.prompt or node.help] - - inserted_paths = list() - for node in nodes: - # avoid duplicate symbols by forcing unique paths. this can - # happen due to dependencies on 0, a trick used by some modules - path = f"{node.filename}:{node.linenr}" - if path in inserted_paths: - continue - inserted_paths.append(path) - - dependencies = None - if node.dep is not sc.kconfig.y: - dependencies = kconfiglib.expr_str(node.dep, sc_fmt) - - defaults = list() - for value, cond in node.orig_defaults: - fmt = kconfiglib.expr_str(value, sc_fmt) - if cond is not sc.kconfig.y: - fmt += f" if {kconfiglib.expr_str(cond, sc_fmt)}" - defaults.append(fmt) - - selects = list() - for value, cond in node.orig_selects: - fmt = kconfiglib.expr_str(value, sc_fmt) - if cond is not sc.kconfig.y: - fmt += f" if {kconfiglib.expr_str(cond, sc_fmt)}" - selects.append(fmt) - - implies = list() - for value, cond in node.orig_implies: - fmt = kconfiglib.expr_str(value, sc_fmt) - if cond is not sc.kconfig.y: - fmt += f" if {kconfiglib.expr_str(cond, sc_fmt)}" - implies.append(fmt) - - ranges = list() - for min, max, cond in node.orig_ranges: - fmt = ( - f"[{kconfiglib.expr_str(min, sc_fmt)}, " - f"{kconfiglib.expr_str(max, sc_fmt)}]" + # store alternative defaults (from defconfig files) + alt_defaults = list() + for node in sc.nodes: + if "defconfig" not in str(node.filename): + continue + + for value, cond in node.orig_defaults: + fmt = kconfiglib.expr_str(value, sc_fmt) + if cond is not sc.kconfig.y: + fmt += f" if {kconfiglib.expr_str(cond, sc_fmt)}" + alt_defaults.append([fmt, node.filename]) + + # build list of symbols that select/imply the current one + # note: all reverse dependencies are ORed together, and conditionals + # (e.g. select/imply A if B) turns into A && B. So we first split + # by OR to include all entries, and we split each one by AND to just + # take the first entry. + selected_by = list() + if isinstance(sc, kconfiglib.Symbol) and sc.rev_dep != sc.kconfig.n: + for select in kconfiglib.split_expr(sc.rev_dep, kconfiglib.OR): + sym = kconfiglib.split_expr(select, kconfiglib.AND)[0] + selected_by.append(f"{kconfig_obj.config_prefix}{sym.name}") + + implied_by = list() + if isinstance(sc, kconfiglib.Symbol) and sc.weak_rev_dep != sc.kconfig.n: + for select in kconfiglib.split_expr(sc.weak_rev_dep, kconfiglib.OR): + sym = kconfiglib.split_expr(select, kconfiglib.AND)[0] + implied_by.append(f"{kconfig_obj.config_prefix}{sym.name}") + + # only process nodes with prompt or help + nodes = [node for node in sc.nodes if node.prompt or node.help] + + inserted_paths = list() + for node in nodes: + # avoid duplicate symbols by forcing unique paths. this can + # happen due to dependencies on 0, a trick used by some modules + path = f"{node.filename}:{node.linenr}" + if path in inserted_paths: + continue + inserted_paths.append(path) + + dependencies = None + if node.dep is not sc.kconfig.y: + dependencies = kconfiglib.expr_str(node.dep, sc_fmt) + + defaults = list() + for value, cond in node.orig_defaults: + fmt = kconfiglib.expr_str(value, sc_fmt) + if cond is not sc.kconfig.y: + fmt += f" if {kconfiglib.expr_str(cond, sc_fmt)}" + defaults.append(fmt) + + selects = list() + for value, cond in node.orig_selects: + fmt = kconfiglib.expr_str(value, sc_fmt) + if cond is not sc.kconfig.y: + fmt += f" if {kconfiglib.expr_str(cond, sc_fmt)}" + selects.append(fmt) + + implies = list() + for value, cond in node.orig_implies: + fmt = kconfiglib.expr_str(value, sc_fmt) + if cond is not sc.kconfig.y: + fmt += f" if {kconfiglib.expr_str(cond, sc_fmt)}" + implies.append(fmt) + + ranges = list() + for min, max, cond in node.orig_ranges: + fmt = ( + f"[{kconfiglib.expr_str(min, sc_fmt)}, " + f"{kconfiglib.expr_str(max, sc_fmt)}]" + ) + if cond is not sc.kconfig.y: + fmt += f" if {kconfiglib.expr_str(cond, sc_fmt)}" + ranges.append(fmt) + + choices = list() + if isinstance(sc, kconfiglib.Choice): + for sym in sc.syms: + choices.append(kconfiglib.expr_str(sym, sc_fmt)) + + menupath = "" + iternode = node + while iternode.parent is not iternode.kconfig.top_node: + iternode = iternode.parent + if iternode.prompt: + title = iternode.prompt[0] + else: + title = kconfiglib.standard_sc_expr_str(iternode.item) + menupath = f" > {title}" + menupath + + menupath = "(Top)" + menupath + + filename = str(node.filename) + for name, path in module_paths.items(): + path += "/" + if str(node.filename).startswith(path): + filename = str(node.filename).replace(path, f"/") + break + + db.append( + { + "name": f"{kconfig_obj.config_prefix}{sc.name}", + "prompt": node.prompt[0] if node.prompt else None, + "type": kconfiglib.TYPE_TO_STR[sc.type], + "help": node.help, + "dependencies": dependencies, + "defaults": defaults, + "alt_defaults": alt_defaults, + "selects": selects, + "selected_by": selected_by, + "implies": implies, + "implied_by": implied_by, + "ranges": ranges, + "choices": choices, + "filename": filename, + "linenr": node.linenr, + "menupath": menupath, + } ) - if cond is not sc.kconfig.y: - fmt += f" if {kconfiglib.expr_str(cond, sc_fmt)}" - ranges.append(fmt) - - choices = list() - if isinstance(sc, kconfiglib.Choice): - for sym in sc.syms: - choices.append(kconfiglib.expr_str(sym, sc_fmt)) - - menupath = "" - iternode = node - while iternode.parent is not iternode.kconfig.top_node: - iternode = iternode.parent - if iternode.prompt: - title = iternode.prompt[0] - else: - title = kconfiglib.standard_sc_expr_str(iternode.item) - menupath = f" > {title}" + menupath - - menupath = "(Top)" + menupath - - filename = node.filename - for name, path in module_paths.items(): - path += "/" - if node.filename.startswith(path): - filename = node.filename.replace(path, f"/") - break - - db.append( - { - "name": f"CONFIG_{sc.name}", - "prompt": node.prompt[0] if node.prompt else None, - "type": kconfiglib.TYPE_TO_STR[sc.type], - "help": node.help, - "dependencies": dependencies, - "defaults": defaults, - "alt_defaults": alt_defaults, - "selects": selects, - "selected_by": selected_by, - "implies": implies, - "implied_by": implied_by, - "ranges": ranges, - "choices": choices, - "filename": filename, - "linenr": node.linenr, - "menupath": menupath, - } - ) app.env.kconfig_db = db # type: ignore From c09cc2f94af10b1996f9e0c726d25f252c434af0 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 27 Jun 2025 13:09:08 +0200 Subject: [PATCH 07/42] [nrf fromtree] manifest: Update nRF hw models to latest Update the HW models module to: 6e5961223f81aa2707c555db138819a5c1b7942c Including the following: 6e59612 CLOCK (52,53): Fix test interface with multiple instances ecf2292 54 CRACEN: Improve model 1277b16 irq controller: Remove out of date comment Signed-off-by: Alberto Escolar Piedras (cherry picked from commit e1c37f6292b0efa651e2a59b19b43870b9cf9262) Signed-off-by: Rubin Gerritsen --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 41fa45c8693..6ec17c12dce 100644 --- a/west.yml +++ b/west.yml @@ -325,7 +325,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: 968d55ff22579080466bf2f482596dd6e35361c6 + revision: 6e5961223f81aa2707c555db138819a5c1b7942c path: modules/bsim_hw_models/nrf_hw_models - name: nrf_wifi revision: 787eea1a3c8dd13c86214e204a919e6f9bcebf91 From 2c70598db1380173cedfaf193c93d9c540fdd72e Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 25 Jul 2025 10:12:12 +0200 Subject: [PATCH 08/42] [nrf fromtree] manifest: Update nRF hw models to latest Update the HW models module to: 8b6001d6bdd9e2c8bb858fdb26f696f6d5f73db5 Including the following: 8b6001d CLOCK (54): Fix XOTUNE subscription sideeffecting for nrf54L15 9af1ac8 nRF54LM20: Bugfix: Add missing UART configuration e6af4a7 RADIO: Fix register init for some devices (at least nRF54LM20) 2fe99ab CLOCK (54): Add XO24M/PLL24M/HFCLK24M ffd578a CLOCK (54): Fixes around XOTUNE Signed-off-by: Alberto Escolar Piedras (cherry picked from commit e7115d04ded2b17e91758cee73a4af807bf8ed44) Signed-off-by: Rubin Gerritsen --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 6ec17c12dce..853d84113a6 100644 --- a/west.yml +++ b/west.yml @@ -325,7 +325,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: 6e5961223f81aa2707c555db138819a5c1b7942c + revision: 8b6001d6bdd9e2c8bb858fdb26f696f6d5f73db5 path: modules/bsim_hw_models/nrf_hw_models - name: nrf_wifi revision: 787eea1a3c8dd13c86214e204a919e6f9bcebf91 From 10fd4547f9aba742598e82a3975222fe7b07e267 Mon Sep 17 00:00:00 2001 From: Yuxuan Cai Date: Fri, 1 Aug 2025 10:11:17 +0200 Subject: [PATCH 09/42] [nrf fromlist] drivers: firmware: remove duplicate function definitions tisci_cmd_get_fwl_region is defined three times which is causing doc build errors Upstream PR #: 93968 Signed-off-by: Yuxuan Cai --- include/zephyr/drivers/firmware/tisci/tisci.h | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/include/zephyr/drivers/firmware/tisci/tisci.h b/include/zephyr/drivers/firmware/tisci/tisci.h index 8097d6d4405..38fc58b9121 100644 --- a/include/zephyr/drivers/firmware/tisci/tisci.h +++ b/include/zephyr/drivers/firmware/tisci/tisci.h @@ -891,44 +891,6 @@ int tisci_cmd_set_fwl_region(const struct device *dev, const struct tisci_msg_fw */ int tisci_cmd_get_fwl_region(const struct device *dev, struct tisci_msg_fwl_region *region); -/* INCLUDE_ZEPHYR_DRIVERS_TISCI_H_ */ - -/* Firewall Management Functions */ -/* ... previous firewall functions ... */ - -/** - * @brief Get firewall region configuration - * - * Retrieves the configuration of a firewall region including permissions, - * addresses, and control settings. - * - * @param dev Pointer to the TI SCI device - * @param region Pointer to store the firewall region configuration. - * The fwl_id, region, and n_permission_regs fields must be - * set before calling this function. - * - * @return 0 if successful, or an error code - */ -int tisci_cmd_get_fwl_region(const struct device *dev, struct tisci_msg_fwl_region *region); - -/* Firewall Management Functions */ -/* ... previous firewall functions ... */ - -/** - * @brief Get firewall region configuration - * - * Retrieves the configuration of a firewall region including permissions, - * addresses, and control settings. - * - * @param dev Pointer to the TI SCI device - * @param region Pointer to store the firewall region configuration. - * The fwl_id, region, and n_permission_regs fields must be - * set before calling this function. - * - * @return 0 if successful, or an error code - */ -int tisci_cmd_get_fwl_region(const struct device *dev, struct tisci_msg_fwl_region *region); - /* Firewall Management Functions */ /* ... previous firewall functions ... */ From d6ac46be53344353db054fd4a6068868d1b99457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Wed, 30 Jul 2025 16:00:13 +0200 Subject: [PATCH 10/42] [nrf fromlist] drivers: hwinfo: nrf: extend supported reset reasons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added missing supported reset reasons based on conditional guards. Upstream PR #: 93910 Signed-off-by: Michał Stasiak --- drivers/hwinfo/hwinfo_nrf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/hwinfo/hwinfo_nrf.c b/drivers/hwinfo/hwinfo_nrf.c index f5a6ed38a20..3d3314ddf58 100644 --- a/drivers/hwinfo/hwinfo_nrf.c +++ b/drivers/hwinfo/hwinfo_nrf.c @@ -207,6 +207,15 @@ int z_impl_hwinfo_get_supported_reset_cause(uint32_t *supported) | RESET_SOFTWARE | RESET_CPU_LOCKUP | RESET_LOW_POWER_WAKE +#if NRFX_RESET_REASON_HAS_VBUS + | RESET_POR +#endif +#if NRFX_RESET_REASON_HAS_GRTC + | RESET_CLOCK +#endif +#if defined(NRFX_RESET_REASON_TAMPC_MASK) || defined(NRFX_RESET_REASON_SECTAMPER_MASK) + | RESET_SECURITY +#endif | RESET_DEBUG); return 0; From 49957e518f5cd614529c2bc69e606e870629c1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Thu, 31 Jul 2025 11:22:37 +0200 Subject: [PATCH 11/42] [nrf fromlist] samples: nordic: system_off: check for supported reset causes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check whether used reset causes are supported by hwinfo driver. Upstream PR #: 93910 Signed-off-by: Michał Stasiak --- samples/boards/nordic/system_off/src/main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/samples/boards/nordic/system_off/src/main.c b/samples/boards/nordic/system_off/src/main.c index d119eff87da..b4c2eeb2b1b 100644 --- a/samples/boards/nordic/system_off/src/main.c +++ b/samples/boards/nordic/system_off/src/main.c @@ -31,8 +31,17 @@ static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios); static const struct device *comp_dev = DEVICE_DT_GET(DT_NODELABEL(comp)); #endif -void print_reset_cause(uint32_t reset_cause) +int print_reset_cause(uint32_t reset_cause) { + int32_t ret; + uint32_t supported; + + ret = hwinfo_get_supported_reset_cause((uint32_t *) &supported); + + if (ret || !(reset_cause & supported)) { + return -ENOTSUP; + } + if (reset_cause & RESET_DEBUG) { printf("Reset by debugger.\n"); } else if (reset_cause & RESET_CLOCK) { @@ -42,6 +51,8 @@ void print_reset_cause(uint32_t reset_cause) } else { printf("Other wake up cause 0x%08X.\n", reset_cause); } + + return 0; } int main(void) @@ -57,7 +68,12 @@ int main(void) printf("\n%s system off demo\n", CONFIG_BOARD); hwinfo_get_reset_cause(&reset_cause); - print_reset_cause(reset_cause); + rc = print_reset_cause(reset_cause); + + if (rc < 0) { + printf("Reset cause not supported.\n"); + return 0; + } if (IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) { bool retained_ok = retained_validate(); From d45132712f2f0a846c04f0c171ec9fcbd43d8d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Laso=C5=84czyk?= Date: Tue, 29 Jul 2025 09:13:19 +0200 Subject: [PATCH 12/42] [nrf fromtree] soc: nordic: Extend address validation to cover GPREGRET MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extension of the validate_base_addresses.c file to cover GPREGRET in all Nordic SoCs. Signed-off-by: Karol Lasończyk (cherry picked from commit 8f2d3e7623d6abdaaccae8fe42a93230f53ae05f) --- soc/nordic/validate_base_addresses.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/soc/nordic/validate_base_addresses.c b/soc/nordic/validate_base_addresses.c index f3c9c8bf214..7426364417f 100644 --- a/soc/nordic/validate_base_addresses.c +++ b/soc/nordic/validate_base_addresses.c @@ -73,13 +73,19 @@ #define NRF_WDT0 NRF_WDT #endif +#if !defined(NRF_POWER_GPREGRET1) && defined(NRF_POWER) #if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) -#if !defined(NRF_POWER_GPREGRET1) && defined(NRF_POWER_BASE) -#define NRF_POWER_GPREGRET1 (0x51c + NRF_POWER_BASE) +#define NRF_POWER_GPREGRET1 (&NRF_POWER->GPREGRET) +#else +#define NRF_POWER_GPREGRET1 (&NRF_POWER->GPREGRET[0]) +#endif #endif -#if !defined(NRF_POWER_GPREGRET2) && defined(NRF_POWER_BASE) -#define NRF_POWER_GPREGRET2 (0x520 + NRF_POWER_BASE) +#if !defined(NRF_POWER_GPREGRET2) && defined(NRF_POWER) +#if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) +#define NRF_POWER_GPREGRET2 (&NRF_POWER->GPREGRET2) +#else +#define NRF_POWER_GPREGRET2 (&NRF_POWER->GPREGRET[1]) #endif #endif @@ -367,9 +373,5 @@ CHECK_DT_REG(cpurad_wdt010, NRF_RADIOCORE_WDT010); CHECK_DT_REG(cpurad_wdt011, NRF_RADIOCORE_WDT011); CHECK_DT_REG(wdt131, NRF_WDT131); CHECK_DT_REG(wdt132, NRF_WDT132); - -/* nRF51/nRF52-specific addresses */ -#if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) CHECK_DT_REG(gpregret1, NRF_POWER_GPREGRET1); CHECK_DT_REG(gpregret2, NRF_POWER_GPREGRET2); -#endif From b57c64b8fcf5a7e5e3b7a501074d364d36471f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Laso=C5=84czyk?= Date: Tue, 29 Jul 2025 09:12:23 +0200 Subject: [PATCH 13/42] [nrf fromtree] dts: nordic: Fix GPREGRET addresses for nRF54LM20A MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix for wrongly addressed GPREGRET space. Signed-off-by: Karol Lasończyk (cherry picked from commit d55ee09e1a1491172ffecb75ea4595a19e13c08b) --- dts/vendor/nordic/nrf54lm20a.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dts/vendor/nordic/nrf54lm20a.dtsi b/dts/vendor/nordic/nrf54lm20a.dtsi index d673ae94e50..d1e6d1b0d28 100644 --- a/dts/vendor/nordic/nrf54lm20a.dtsi +++ b/dts/vendor/nordic/nrf54lm20a.dtsi @@ -800,19 +800,19 @@ #address-cells = <1>; #size-cells = <1>; - gpregret1: gpregret1@51c { + gpregret1: gpregret1@500 { #address-cells = <1>; #size-cells = <1>; compatible = "nordic,nrf-gpregret"; - reg = <0x51c 0x1>; + reg = <0x500 0x1>; status = "disabled"; }; - gpregret2: gpregret2@520 { + gpregret2: gpregret2@504 { #address-cells = <1>; #size-cells = <1>; compatible = "nordic,nrf-gpregret"; - reg = <0x520 0x1>; + reg = <0x504 0x1>; status = "disabled"; }; }; From 1ed3c0dd5c9ddbccd5a1c19a5720d27880c7dd69 Mon Sep 17 00:00:00 2001 From: Omkar Kulkarni Date: Fri, 18 Jul 2025 15:15:35 +0200 Subject: [PATCH 14/42] [nrf fromtree] Bluetooth: Mesh: Blob Server considers friendship Fix Max Chunk reporting during Block_Information_Get: If friendship is established, then max possible chunk size for transfer is reported according to friend's queue size. ChunkSize = (FndQ sz * Bytes per seg (12)) - Opcode(1) - Chunk_Num (2)- 8 byte MIC (max) = (FndQ sz * 12) - 11 This allows all segments of Chunk_Transfer messages to fit in a friend queue. If this is not done, friend queue keeps overflowing systematically causing unstable PULL_MODE transfers. Fix Chunk requests: Adapt number of requested chunks according to current friend queue size. If friend queue is too small, at least 1 chunk is requested. Signed-off-by: Omkar Kulkarni (cherry picked from commit 602fd0d8898031f689f5682cda4f2124c519ea03) --- subsys/bluetooth/mesh/blob_srv.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/blob_srv.c b/subsys/bluetooth/mesh/blob_srv.c index 2d4ec561f83..c022352b040 100644 --- a/subsys/bluetooth/mesh/blob_srv.c +++ b/subsys/bluetooth/mesh/blob_srv.c @@ -151,8 +151,12 @@ static int pull_req_max(const struct bt_mesh_blob_srv *srv) BLOB_CHUNK_SDU_LEN(srv->state.xfer.chunk_size), BT_MESH_APP_SEG_SDU_MAX); - count = MIN(CONFIG_BT_MESH_BLOB_SRV_PULL_REQ_COUNT, - bt_mesh.lpn.queue_size / segments_per_chunk); + /* It is possible that the friend node cannot hold all segments per chunk. In this + * case, we should request at least 1 chunk. As requesting `0` would be invalid. + */ + count = MAX(1, MIN(CONFIG_BT_MESH_BLOB_SRV_PULL_REQ_COUNT, + bt_mesh.lpn.queue_size / segments_per_chunk)); + } #endif @@ -821,7 +825,27 @@ static int handle_info_get(const struct bt_mesh_model *mod, struct bt_mesh_msg_c net_buf_simple_add_u8(&rsp, BLOB_BLOCK_SIZE_LOG_MIN); net_buf_simple_add_u8(&rsp, BLOB_BLOCK_SIZE_LOG_MAX); net_buf_simple_add_le16(&rsp, CONFIG_BT_MESH_BLOB_CHUNK_COUNT_MAX); + +#if defined(CONFIG_BT_MESH_LOW_POWER) + /* If friendship is established, then chunk size is according to friend's queue size. + * Chunk size = (Queue size * Segment size) - (Opcode (1) - Chunk Number (2) + * - 8 byte MIC (max)) + */ + if (bt_mesh_lpn_established() && bt_mesh.lpn.queue_size > 0) { + uint16_t chunk_size = (bt_mesh.lpn.queue_size * 12) - 11; + + chunk_size = MIN(chunk_size, BLOB_RX_CHUNK_SIZE); + net_buf_simple_add_le16(&rsp, chunk_size); + if (bt_mesh.lpn.queue_size <= 2) { + LOG_WRN("FndQ too small %u", bt_mesh.lpn.queue_size); + } + } else { + net_buf_simple_add_le16(&rsp, BLOB_RX_CHUNK_SIZE); + } +#else net_buf_simple_add_le16(&rsp, BLOB_RX_CHUNK_SIZE); +#endif + net_buf_simple_add_le32(&rsp, CONFIG_BT_MESH_BLOB_SIZE_MAX); net_buf_simple_add_le16(&rsp, MTU_SIZE_MAX); net_buf_simple_add_u8(&rsp, BT_MESH_BLOB_XFER_MODE_ALL); From bb1a8e3fa07b0841fdacf487e1cebdf660915eef Mon Sep 17 00:00:00 2001 From: Bartosz Miller Date: Wed, 21 May 2025 11:41:09 +0200 Subject: [PATCH 15/42] [nrf fromtree] tests: boards: nrf: qdec: Add testing with multiple QDEC instances NRFX should support multiple QDEC devices operation. Signed-off-by: Bartosz Miller (cherry picked from commit 08cc78cc9f109855aac3526bf3b3915df5cf90a3) --- .../boards/nrf54h20dk_nrf54h20_cpuapp.overlay | 57 +++- .../boards/nrf54l15dk_nrf54l15_common.dtsi | 53 +++- tests/boards/nrf/qdec/src/main.c | 272 +++++++++++++----- 3 files changed, 300 insertions(+), 82 deletions(-) diff --git a/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay b/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay index 7e6da5a3458..78f3aa09ace 100644 --- a/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay +++ b/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay @@ -3,11 +3,21 @@ * SPDX-License-Identifier: Apache-2.0 */ +/* Required loopbacks + * P2.08 <-> P2.09 + * P2.10 <-> P2.11 + * P1.02 <-> P1.03 + * P7.01 <-> P1.05 + */ + / { aliases { qdec0 = &qdec130; + qdec1 = &qdec131; qenca = &phase_a; qencb = &phase_b; + qenca1 = &phase_a1; + qencb1 = &phase_b1; }; encoder-emulate { @@ -18,34 +28,73 @@ phase_b: phase_b { gpios = <&gpio2 11 GPIO_ACTIVE_HIGH>; }; + phase_a1: phase_a1 { + gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; + }; + phase_b1: phase_b1 { + gpios = <&gpio7 1 GPIO_ACTIVE_HIGH>; + }; }; }; &pinctrl { - qdec_pinctrl: qdec_pinctrl { + qdec_130_pinctrl: qdec_130_pinctrl { group1 { psels = , ; }; }; - qdec_sleep_pinctrl: qdec_sleep_pinctrl { + qdec_130_sleep_pinctrl: qdec_130_sleep_pinctrl { group1 { psels = , ; low-power-enable; }; }; + + qdec_131_pinctrl: qdec_131_pinctrl { + group1 { + psels = , + ; + }; + }; + + qdec_131_sleep_pinctrl: qdec_131_sleep_pinctrl { + group1 { + psels = , + ; + low-power-enable; + }; + }; +}; + +&gpio1 { + status = "okay"; }; &gpio2 { status = "okay"; }; +&gpio7 { + status = "okay"; +}; + &qdec130 { status = "okay"; - pinctrl-0 = <&qdec_pinctrl>; - pinctrl-1 = <&qdec_sleep_pinctrl>; + pinctrl-0 = <&qdec_130_pinctrl>; + pinctrl-1 = <&qdec_130_sleep_pinctrl>; + pinctrl-names = "default", "sleep"; + steps = <127>; + led-pre = <500>; + zephyr,pm-device-runtime-auto; +}; + +&qdec131 { + status = "okay"; + pinctrl-0 = <&qdec_131_pinctrl>; + pinctrl-1 = <&qdec_131_sleep_pinctrl>; pinctrl-names = "default", "sleep"; steps = <127>; led-pre = <500>; diff --git a/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_common.dtsi b/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_common.dtsi index 3fa426569b8..06a490d1da0 100644 --- a/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_common.dtsi +++ b/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_common.dtsi @@ -3,11 +3,21 @@ * SPDX-License-Identifier: Apache-2.0 */ +/* Required loopbacks + * P1.8 <-> P1.9 + * P1.10 >-> P1.11 + * P2.8 <-> P2.9 + * P2.10 <-> P1.14 + */ + / { aliases { qdec0 = &qdec20; + qdec1 = &qdec21; qenca = &phase_a; qencb = &phase_b; + qenca1 = &phase_a1; + qencb1 = &phase_b1; }; encoder-emulate { @@ -18,34 +28,69 @@ phase_b: phase_b { gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>; }; + phase_a1: phase_a1 { + gpios = <&gpio2 9 GPIO_ACTIVE_HIGH>; + }; + phase_b1: phase_b1 { + gpios = <&gpio1 14 GPIO_ACTIVE_HIGH>; + }; }; }; &pinctrl { - qdec_pinctrl: qdec_pinctrl { + qdec_20_pinctrl: qdec_20_pinctrl { group1 { psels = , ; }; }; - qdec_sleep_pinctrl: qdec_sleep_pinctrl { + qdec_20_sleep_pinctrl: qdec_20_sleep_pinctrl { group1 { psels = , ; low-power-enable; }; }; + + qdec_21_pinctrl: qdec_21_pinctrl { + group1 { + psels = , + ; + }; + }; + + qdec_21_sleep_pinctrl: qdec_21_sleep_pinctrl { + group1 { + psels = , + ; + low-power-enable; + }; + }; }; &gpio1 { status = "okay"; }; +&gpio2 { + status = "okay"; +}; + &qdec20 { status = "okay"; - pinctrl-0 = <&qdec_pinctrl>; - pinctrl-1 = <&qdec_sleep_pinctrl>; + pinctrl-0 = <&qdec_20_pinctrl>; + pinctrl-1 = <&qdec_20_sleep_pinctrl>; + pinctrl-names = "default", "sleep"; + steps = <127>; + led-pre = <500>; + zephyr,pm-device-runtime-auto; +}; + +&qdec21 { + status = "okay"; + pinctrl-0 = <&qdec_21_pinctrl>; + pinctrl-1 = <&qdec_21_sleep_pinctrl>; pinctrl-names = "default", "sleep"; steps = <127>; led-pre = <500>; diff --git a/tests/boards/nrf/qdec/src/main.c b/tests/boards/nrf/qdec/src/main.c index d87feb22f42..0df3ee2ab95 100644 --- a/tests/boards/nrf/qdec/src/main.c +++ b/tests/boards/nrf/qdec/src/main.c @@ -16,6 +16,15 @@ static const struct gpio_dt_spec phase_a = GPIO_DT_SPEC_GET(DT_ALIAS(qenca), gpi static const struct gpio_dt_spec phase_b = GPIO_DT_SPEC_GET(DT_ALIAS(qencb), gpios); static const struct device *const qdec_dev = DEVICE_DT_GET(DT_ALIAS(qdec0)); static const uint32_t qdec_config_step = DT_PROP(DT_ALIAS(qdec0), steps); + +#if DT_NODE_EXISTS(DT_ALIAS(qdec1)) +#define SECOND_QDEC_INSTANCE + +static const struct gpio_dt_spec phase_a1 = GPIO_DT_SPEC_GET(DT_ALIAS(qenca1), gpios); +static const struct gpio_dt_spec phase_b1 = GPIO_DT_SPEC_GET(DT_ALIAS(qencb1), gpios); +static const struct device *const qdec_1_dev = DEVICE_DT_GET(DT_ALIAS(qdec1)); +static const uint32_t qdec_1_config_step = DT_PROP(DT_ALIAS(qdec1), steps); +#endif static struct sensor_trigger qdec_trigger = {.type = SENSOR_TRIG_DATA_READY, .chan = SENSOR_CHAN_ROTATION}; static bool toggle_a = true; @@ -24,7 +33,6 @@ static void qdec_trigger_handler(const struct device *dev, const struct sensor_t { zassert_not_null(dev); zassert_not_null(trigger); - zassert_equal_ptr(dev, qdec_dev); /* trigger should be stored as a pointer in a driver * thus this address should match */ @@ -37,8 +45,14 @@ static void qenc_emulate_work_handler(struct k_work *work) { if (toggle_a) { gpio_pin_toggle_dt(&phase_a); +#if defined(SECOND_QDEC_INSTANCE) + gpio_pin_toggle_dt(&phase_a1); +#endif } else { gpio_pin_toggle_dt(&phase_b); +#if defined(SECOND_QDEC_INSTANCE) + gpio_pin_toggle_dt(&phase_b1); +#endif } toggle_a = !toggle_a; } @@ -75,6 +89,10 @@ static void qenc_emulate_start(k_timeout_t period, bool forward) { qenc_emulate_reset_pin(&phase_a); qenc_emulate_reset_pin(&phase_b); +#if defined(SECOND_QDEC_INSTANCE) + qenc_emulate_reset_pin(&phase_a1); + qenc_emulate_reset_pin(&phase_b1); +#endif toggle_a = !forward; @@ -87,15 +105,20 @@ static void qenc_emulate_stop(void) qenc_emulate_reset_pin(&phase_a); qenc_emulate_reset_pin(&phase_b); +#if defined(SECOND_QDEC_INSTANCE) + qenc_emulate_reset_pin(&phase_a1); + qenc_emulate_reset_pin(&phase_b1); +#endif } -static void qenc_emulate_verify_reading(int emulator_period_ms, int emulation_duration_ms, - bool forward, bool overflow_expected) +static void qenc_emulate_verify_reading(const struct device *const dev, int emulator_period_ms, + int emulation_duration_ms, bool forward, bool overflow_expected, + const uint32_t config_step) { int rc; struct sensor_value val = {0}; int32_t expected_steps = emulation_duration_ms / emulator_period_ms; - int32_t expected_reading = 360 * expected_steps / qdec_config_step; + int32_t expected_reading = 360 * expected_steps / config_step; int32_t delta = expected_reading / 5; if (!forward) { @@ -104,10 +127,10 @@ static void qenc_emulate_verify_reading(int emulator_period_ms, int emulation_du qenc_emulate_start(K_MSEC(emulator_period_ms), forward); - /* wait for some readings*/ + /* wait for some readings */ k_msleep(emulation_duration_ms); - rc = sensor_sample_fetch(qdec_dev); + rc = sensor_sample_fetch(dev); if (!overflow_expected) { zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); @@ -115,9 +138,11 @@ static void qenc_emulate_verify_reading(int emulator_period_ms, int emulation_du zassert_true(rc == -EOVERFLOW, "Failed to detect overflow"); } - rc = sensor_channel_get(qdec_dev, SENSOR_CHAN_ROTATION, &val); + rc = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &val); zassert_true(rc == 0, "Failed to get sample (%d)", rc); + TC_PRINT("Expected reading: %d, actual value: %d, delta: %d\n", + expected_reading, val.val1, delta); if (!overflow_expected) { zassert_within(val.val1, expected_reading, delta, "Expected reading: %d, but got: %d", expected_reading, val.val1); @@ -128,30 +153,26 @@ static void qenc_emulate_verify_reading(int emulator_period_ms, int emulation_du /* wait and get readings to clear state */ k_msleep(100); - rc = sensor_sample_fetch(qdec_dev); + rc = sensor_sample_fetch(dev); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); - rc = sensor_channel_get(qdec_dev, SENSOR_CHAN_ROTATION, &val); + rc = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &val); zassert_true(rc == 0, "Failed to get sample (%d)", rc); } -/** - * @brief sensor_trigger_set test disable trigger - * - * Confirm trigger happens after set and stops after being disabled - * - */ -ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable) +static void sensor_trigger_set_and_disable(const struct device *const dev) { int rc; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(qdec_dev); + pm_device_runtime_get(dev); } + k_sem_give(&sem); + qdec_trigger.type = SENSOR_TRIG_DATA_READY; qdec_trigger.chan = SENSOR_CHAN_ALL; - rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler); + rc = sensor_trigger_set(dev, &qdec_trigger, qdec_trigger_handler); zassume_true(rc != -ENOSYS, "sensor_trigger_set not supported"); zassert_true(rc == 0, "sensor_trigger_set failed: %d", rc); @@ -168,7 +189,7 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable) rc = k_sem_take(&sem, K_MSEC(200)); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(qdec_dev); + pm_device_runtime_put(dev); } /* there should be no triggers now*/ @@ -176,11 +197,11 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable) zassert_true(rc == -EAGAIN, "qdec handler should not be triggered (%d)", rc); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(qdec_dev); + pm_device_runtime_get(dev); } /* register empty trigger - disable trigger */ - rc = sensor_trigger_set(qdec_dev, &qdec_trigger, NULL); + rc = sensor_trigger_set(dev, &qdec_trigger, NULL); zassert_true(rc == 0, "sensor_trigger_set failed: %d", rc); qenc_emulate_start(K_MSEC(10), true); @@ -190,28 +211,39 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable) zassert_true(rc == -EAGAIN, "qdec handler should not be triggered (%d)", rc); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(qdec_dev); + pm_device_runtime_put(dev); } } /** - * @brief sensor_trigger_set test + * @brief sensor_trigger_set test disable trigger * - * Confirm trigger happens after set + * Confirm trigger happens after set and stops after being disabled * */ -ZTEST(qdec_sensor, test_sensor_trigger_set) +ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable) +{ + TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); + sensor_trigger_set_and_disable(qdec_dev); +#if defined(SECOND_QDEC_INSTANCE) + TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); + sensor_trigger_set_and_disable(qdec_1_dev); +#endif + +} + +static void sensor_trigger_set_test(const struct device *const dev) { int rc; struct sensor_value val = {0}; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(qdec_dev); + pm_device_runtime_get(dev); } qdec_trigger.type = SENSOR_TRIG_DATA_READY; qdec_trigger.chan = SENSOR_CHAN_ROTATION; - rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler); + rc = sensor_trigger_set(dev, &qdec_trigger, qdec_trigger_handler); zassume_true(rc != -ENOSYS, "sensor_trigger_set not supported"); zassert_true(rc == 0, "sensor_trigger_set failed: %d", rc); @@ -222,54 +254,80 @@ ZTEST(qdec_sensor, test_sensor_trigger_set) rc = k_sem_take(&sem, K_MSEC(200)); zassert_true(rc == 0, "qdec handler should be triggered (%d)", rc); - rc = sensor_sample_fetch(qdec_dev); + rc = sensor_sample_fetch(dev); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); - rc = sensor_channel_get(qdec_dev, SENSOR_CHAN_ROTATION, &val); + rc = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &val); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); TC_PRINT("QDEC reading: %d\n", val.val1); zassert_true(val.val1 != 0, "No readings from QDEC"); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(qdec_dev); + pm_device_runtime_put(dev); } } /** - * @brief sensor_trigger_set test negative + * @brief sensor_trigger_set test * - * Confirm setting trigger with invalid data does not work + * Confirm trigger happens after set * */ -ZTEST(qdec_sensor, test_sensor_trigger_set_negative) +ZTEST(qdec_sensor, test_sensor_trigger_set) +{ + TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); + sensor_trigger_set_test(qdec_dev); +#if defined(SECOND_QDEC_INSTANCE) + TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); + sensor_trigger_set_test(qdec_1_dev); +#endif +} + +static void sensor_trigger_set_negative(const struct device *const dev) { int rc; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(qdec_dev); + pm_device_runtime_get(dev); } - rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler); + rc = sensor_trigger_set(dev, &qdec_trigger, qdec_trigger_handler); zassume_true(rc != -ENOSYS, "sensor_trigger_set not supported"); qdec_trigger.type = SENSOR_TRIG_MAX; qdec_trigger.chan = SENSOR_CHAN_ROTATION; - rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler); + rc = sensor_trigger_set(dev, &qdec_trigger, qdec_trigger_handler); zassume_true(rc < 0, "sensor_trigger_set should fail due to invalid trigger type"); qdec_trigger.type = SENSOR_TRIG_DATA_READY; qdec_trigger.chan = SENSOR_CHAN_MAX; - rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler); + rc = sensor_trigger_set(dev, &qdec_trigger, qdec_trigger_handler); zassume_true(rc < 0, "sensor_trigger_set should fail due to invalid channel"); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(qdec_dev); + pm_device_runtime_put(dev); } } +/** + * @brief sensor_trigger_set test negative + * + * Confirm setting trigger with invalid data does not work + * + */ +ZTEST(qdec_sensor, test_sensor_trigger_set_negative) +{ + TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); + sensor_trigger_set_negative(qdec_dev); +#if defined(SECOND_QDEC_INSTANCE) + TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); + sensor_trigger_set_negative(qdec_1_dev); +#endif +} + /** * @brief QDEC readings tests * @@ -282,68 +340,90 @@ ZTEST(qdec_sensor, test_qdec_readings) pm_device_runtime_get(qdec_dev); } - qenc_emulate_verify_reading(10, 100, true, false); - qenc_emulate_verify_reading(2, 500, true, false); - qenc_emulate_verify_reading(10, 200, false, false); - qenc_emulate_verify_reading(1, 1000, false, true); - qenc_emulate_verify_reading(1, 1000, true, true); + TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); + qenc_emulate_verify_reading(qdec_dev, 10, 100, true, false, qdec_config_step); + qenc_emulate_verify_reading(qdec_dev, 2, 500, true, false, qdec_config_step); + qenc_emulate_verify_reading(qdec_dev, 10, 200, false, false, qdec_config_step); + qenc_emulate_verify_reading(qdec_dev, 1, 1000, false, true, qdec_config_step); + qenc_emulate_verify_reading(qdec_dev, 1, 1000, true, true, qdec_config_step); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { pm_device_runtime_put(qdec_dev); } + +#if defined(SECOND_QDEC_INSTANCE) + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(qdec_1_dev); + } + + TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); + qenc_emulate_verify_reading(qdec_1_dev, 10, 100, true, false, qdec_1_config_step); + qenc_emulate_verify_reading(qdec_1_dev, 2, 500, true, false, qdec_1_config_step); + qenc_emulate_verify_reading(qdec_1_dev, 10, 200, false, false, qdec_1_config_step); + qenc_emulate_verify_reading(qdec_1_dev, 1, 1000, false, true, qdec_1_config_step); + qenc_emulate_verify_reading(qdec_1_dev, 1, 1000, true, true, qdec_1_config_step); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(qdec_1_dev); + } +#endif } -/** - * @brief sensor_channel_get test with no emulation - * - * Confirm getting empty reading from QDEC - * - */ -ZTEST(qdec_sensor, test_sensor_channel_get_empty) +static void sensor_channel_get_empty(const struct device *const dev) { int rc; struct sensor_value val = {0}; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(qdec_dev); + pm_device_runtime_get(dev); } /* wait for potential new readings */ k_msleep(100); - rc = sensor_sample_fetch(qdec_dev); + rc = sensor_sample_fetch(dev); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); /* get readings but ignore them, as they may include reading from time * when emulation was still working (i.e. during previous test) */ - rc = sensor_channel_get(qdec_dev, SENSOR_CHAN_ROTATION, &val); + rc = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &val); zassert_true(rc == 0, "Failed to get sample (%d)", rc); /* wait for potential new readings */ k_msleep(100); - rc = sensor_sample_fetch(qdec_dev); + rc = sensor_sample_fetch(dev); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); /* emulation was not working, expect no readings */ - rc = sensor_channel_get(qdec_dev, SENSOR_CHAN_ROTATION, &val); + rc = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &val); zassert_true(rc == 0, "Failed to get sample (%d)", rc); zassert_true(val.val1 == 0, "Expected no readings but got: %d", val.val1); zassert_true(val.val2 == 0, "Expected no readings but got: %d", val.val2); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(qdec_dev); + pm_device_runtime_put(dev); } } /** - * @brief sensor_channel_get test with emulation + * @brief sensor_channel_get test with no emulation * - * Confirm getting readings from QDEC + * Confirm getting empty reading from QDEC * */ -ZTEST(qdec_sensor, test_sensor_channel_get) +ZTEST(qdec_sensor, test_sensor_channel_get_empty) +{ + TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); + sensor_channel_get_empty(qdec_dev); +#if defined(SECOND_QDEC_INSTANCE) + TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); + sensor_channel_get_empty(qdec_1_dev); +#endif +} + +static void sensor_channel_get_test(const struct device *const dev) { int rc; struct sensor_value val_first = {0}; @@ -391,18 +471,28 @@ ZTEST(qdec_sensor, test_sensor_channel_get) } /** - * @brief sensor_channel_get test negative + * @brief sensor_channel_get test with emulation * - * Confirm getting readings from QDEC with invalid channel + * Confirm getting readings from QDEC * */ -ZTEST(qdec_sensor, test_sensor_channel_get_negative) +ZTEST(qdec_sensor, test_sensor_channel_get) +{ + TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); + sensor_channel_get_test(qdec_dev); +#if defined(SECOND_QDEC_INSTANCE) + TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); + sensor_channel_get_test(qdec_1_dev); +#endif +} + +static void sensor_channel_get_negative(const struct device *const dev) { int rc; struct sensor_value val = {0}; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(qdec_dev); + pm_device_runtime_get(dev); } qenc_emulate_start(K_MSEC(10), true); @@ -410,47 +500,73 @@ ZTEST(qdec_sensor, test_sensor_channel_get_negative) /* wait for some readings*/ k_msleep(100); - rc = sensor_sample_fetch(qdec_dev); + rc = sensor_sample_fetch(dev); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); - rc = sensor_channel_get(qdec_dev, SENSOR_CHAN_MAX, &val); + rc = sensor_channel_get(dev, SENSOR_CHAN_MAX, &val); zassert_true(rc < 0, "Should failed to get sample (%d)", rc); zassert_true(val.val1 == 0, "Some readings from QDEC: %d", val.val1); zassert_true(val.val2 == 0, "Some readings from QDEC: %d", val.val2); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(qdec_dev); + pm_device_runtime_put(dev); } } /** - * @brief sensor_sample_fetch(_chan) test + * @brief sensor_channel_get test negative * - * Confirm fetching work with QDEC specific channel - rotation + * Confirm getting readings from QDEC with invalid channel * */ -ZTEST(qdec_sensor, test_sensor_sample_fetch) +ZTEST(qdec_sensor, test_sensor_channel_get_negative) +{ + TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); + sensor_channel_get_negative(qdec_dev); +#if defined(SECOND_QDEC_INSTANCE) + TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); + sensor_channel_get_negative(qdec_1_dev); +#endif +} + +static void sensor_sample_fetch_test(const struct device *const dev) { int rc; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(qdec_dev); + pm_device_runtime_get(dev); } - rc = sensor_sample_fetch(qdec_dev); + rc = sensor_sample_fetch(dev); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); - rc = sensor_sample_fetch_chan(qdec_dev, SENSOR_CHAN_ROTATION); + rc = sensor_sample_fetch_chan(dev, SENSOR_CHAN_ROTATION); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); - rc = sensor_sample_fetch_chan(qdec_dev, SENSOR_CHAN_MAX); + rc = sensor_sample_fetch_chan(dev, SENSOR_CHAN_MAX); zassert_true(rc < 0, "Should fail to fetch sample from invalid channel (%d)", rc); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(qdec_dev); + pm_device_runtime_put(dev); } } +/** + * @brief sensor_sample_fetch(_chan) test + * + * Confirm fetching work with QDEC specific channel - rotation + * + */ +ZTEST(qdec_sensor, test_sensor_sample_fetch) +{ + TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); + sensor_sample_fetch_test(qdec_dev); +#if defined(SECOND_QDEC_INSTANCE) + TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); + sensor_sample_fetch_test(qdec_1_dev); +#endif +} + static void *setup(void) { int rc; @@ -461,6 +577,14 @@ static void *setup(void) qenc_emulate_setup_pin(&phase_a); qenc_emulate_setup_pin(&phase_b); +#if defined(SECOND_QDEC_INSTANCE) + rc = device_is_ready(qdec_1_dev); + zassert_true(rc, "QDEC 1 device not ready: %d", rc); + + qenc_emulate_setup_pin(&phase_a1); + qenc_emulate_setup_pin(&phase_b1); +#endif + return NULL; } From 64d730258d9ebfdb61cd2098ebbf3e1c1bf7dd51 Mon Sep 17 00:00:00 2001 From: Bartosz Miller Date: Tue, 24 Jun 2025 10:55:20 +0200 Subject: [PATCH 16/42] [nrf fromtree] tests: boards: nrf: qdec: Disable testing of 2nd instance until fixed Disable testing second QDEC instance until the issue with multiple QDEC instances support is resolved Signed-off-by: Bartosz Miller (cherry picked from commit 39b24514940b2acd7bfd1b71a951f1b3d30727d6) --- tests/boards/nrf/qdec/src/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/boards/nrf/qdec/src/main.c b/tests/boards/nrf/qdec/src/main.c index 0df3ee2ab95..7df97be2a43 100644 --- a/tests/boards/nrf/qdec/src/main.c +++ b/tests/boards/nrf/qdec/src/main.c @@ -17,7 +17,11 @@ static const struct gpio_dt_spec phase_b = GPIO_DT_SPEC_GET(DT_ALIAS(qencb), gpi static const struct device *const qdec_dev = DEVICE_DT_GET(DT_ALIAS(qdec0)); static const uint32_t qdec_config_step = DT_PROP(DT_ALIAS(qdec0), steps); -#if DT_NODE_EXISTS(DT_ALIAS(qdec1)) +/* Disable testing second QDEC instance + * until the issue with multiple + * QDEC instances support is resolved + */ +#if DT_NODE_EXISTS(DT_ALIAS(qdecX)) #define SECOND_QDEC_INSTANCE static const struct gpio_dt_spec phase_a1 = GPIO_DT_SPEC_GET(DT_ALIAS(qenca1), gpios); From e6948df926e1027caeb3914a2dc37430aca3d09c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bainczyk?= Date: Thu, 31 Jul 2025 13:09:12 +0200 Subject: [PATCH 17/42] [nrf fromlist] tests: boards: nrf: qdec: Fix test for multiple instances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed pin configuration for nRF54L15 (QDECs can use only port 1) - Changed the way the test handles testing multiple instances to make it possible to output quadrature signal to one QDEC instance at a time. Upstream PR #: 93927 Signed-off-by: Michał Bainczyk --- .../boards/bl54l15_dvk_nrf54l15_common.dtsi | 14 +- .../boards/bl54l15u_dvk_nrf54l15_common.dtsi | 14 +- .../qdec/boards/nrf52840dk_nrf52840.overlay | 7 + .../boards/nrf5340dk_nrf5340_cpuapp.overlay | 14 +- .../boards/nrf54h20dk_nrf54h20_cpuapp.overlay | 25 +- .../boards/nrf54l15dk_nrf54l15_common.dtsi | 45 +-- .../boards/nrf54lm20dk_nrf54lm20_common.dtsi | 14 +- .../qdec/dts/bindings/test-qdec-loopback.yaml | 20 ++ tests/boards/nrf/qdec/src/main.c | 313 ++++++++---------- 9 files changed, 237 insertions(+), 229 deletions(-) create mode 100644 tests/boards/nrf/qdec/dts/bindings/test-qdec-loopback.yaml diff --git a/tests/boards/nrf/qdec/boards/bl54l15_dvk_nrf54l15_common.dtsi b/tests/boards/nrf/qdec/boards/bl54l15_dvk_nrf54l15_common.dtsi index 4db67a49a5e..19ca5e83647 100644 --- a/tests/boards/nrf/qdec/boards/bl54l15_dvk_nrf54l15_common.dtsi +++ b/tests/boards/nrf/qdec/boards/bl54l15_dvk_nrf54l15_common.dtsi @@ -5,12 +5,6 @@ */ / { - aliases { - qdec0 = &qdec20; - qenca = &phase_a; - qencb = &phase_b; - }; - encoder-emulate { compatible = "gpio-leds"; @@ -22,6 +16,14 @@ gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>; }; }; + + qdec_loopbacks: loopbacks { + compatible = "test-qdec-loopbacks"; + loopback0 { + qdec = <&qdec20>; + qenc-emul-gpios = <&phase_a &phase_b>; + }; + }; }; &pinctrl { diff --git a/tests/boards/nrf/qdec/boards/bl54l15u_dvk_nrf54l15_common.dtsi b/tests/boards/nrf/qdec/boards/bl54l15u_dvk_nrf54l15_common.dtsi index 4db67a49a5e..19ca5e83647 100644 --- a/tests/boards/nrf/qdec/boards/bl54l15u_dvk_nrf54l15_common.dtsi +++ b/tests/boards/nrf/qdec/boards/bl54l15u_dvk_nrf54l15_common.dtsi @@ -5,12 +5,6 @@ */ / { - aliases { - qdec0 = &qdec20; - qenca = &phase_a; - qencb = &phase_b; - }; - encoder-emulate { compatible = "gpio-leds"; @@ -22,6 +16,14 @@ gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>; }; }; + + qdec_loopbacks: loopbacks { + compatible = "test-qdec-loopbacks"; + loopback0 { + qdec = <&qdec20>; + qenc-emul-gpios = <&phase_a &phase_b>; + }; + }; }; &pinctrl { diff --git a/tests/boards/nrf/qdec/boards/nrf52840dk_nrf52840.overlay b/tests/boards/nrf/qdec/boards/nrf52840dk_nrf52840.overlay index f227fb95c38..a495df07f7c 100644 --- a/tests/boards/nrf/qdec/boards/nrf52840dk_nrf52840.overlay +++ b/tests/boards/nrf/qdec/boards/nrf52840dk_nrf52840.overlay @@ -22,6 +22,13 @@ }; }; + qdec_loopbacks: loopbacks { + compatible = "test-qdec-loopbacks"; + loopback0 { + qdec = <&qdec0>; + qenc-emul-gpios = <&phase_a &phase_b>; + }; + }; }; &pinctrl { diff --git a/tests/boards/nrf/qdec/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/boards/nrf/qdec/boards/nrf5340dk_nrf5340_cpuapp.overlay index ed6a5587f5b..d1f008c8193 100644 --- a/tests/boards/nrf/qdec/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/tests/boards/nrf/qdec/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -4,12 +4,6 @@ */ / { - aliases { - qdec0 = &qdec1; - qenca = &phase_a; - qencb = &phase_b; - }; - encoder-emulate { compatible = "gpio-leds"; phase_a: phase_a { @@ -21,6 +15,14 @@ gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>; }; }; + + qdec_loopbacks: loopbacks { + compatible = "test-qdec-loopbacks"; + loopback0 { + qdec = <&qdec1>; + qenc-emul-gpios = <&phase_a &phase_b>; + }; + }; }; &pinctrl { diff --git a/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay b/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay index 78f3aa09ace..7e43c70dac0 100644 --- a/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay +++ b/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay @@ -11,21 +11,12 @@ */ / { - aliases { - qdec0 = &qdec130; - qdec1 = &qdec131; - qenca = &phase_a; - qencb = &phase_b; - qenca1 = &phase_a1; - qencb1 = &phase_b1; - }; - encoder-emulate { compatible = "gpio-leds"; - phase_a: phase_a { + phase_a0: phase_a0 { gpios = <&gpio2 9 GPIO_ACTIVE_HIGH>; }; - phase_b: phase_b { + phase_b0: phase_b0 { gpios = <&gpio2 11 GPIO_ACTIVE_HIGH>; }; phase_a1: phase_a1 { @@ -35,6 +26,18 @@ gpios = <&gpio7 1 GPIO_ACTIVE_HIGH>; }; }; + + qdec_loopbacks: loopbacks { + compatible = "test-qdec-loopbacks"; + loopback0 { + qdec = <&qdec130>; + qenc-emul-gpios = <&phase_a0 &phase_b0>; + }; + loopback1 { + qdec = <&qdec131>; + qenc-emul-gpios = <&phase_a1 &phase_b1>; + }; + }; }; &pinctrl { diff --git a/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_common.dtsi b/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_common.dtsi index 06a490d1da0..f2729414652 100644 --- a/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_common.dtsi +++ b/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_common.dtsi @@ -4,35 +4,38 @@ */ /* Required loopbacks - * P1.8 <-> P1.9 - * P1.10 >-> P1.11 - * P2.8 <-> P2.9 - * P2.10 <-> P1.14 + * P1.8 <-> P1.9 + * P1.10 <-> P1.11 + * P1.12 <-> P1.13 + * P1.14 <-> P2.10 */ / { - aliases { - qdec0 = &qdec20; - qdec1 = &qdec21; - qenca = &phase_a; - qencb = &phase_b; - qenca1 = &phase_a1; - qencb1 = &phase_b1; - }; - encoder-emulate { compatible = "gpio-leds"; - phase_a: phase_a { + phase_a0: phase_a0 { gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>; }; - phase_b: phase_b { + phase_b0: phase_b0 { gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>; }; phase_a1: phase_a1 { - gpios = <&gpio2 9 GPIO_ACTIVE_HIGH>; + gpios = <&gpio1 13 GPIO_ACTIVE_HIGH>; }; phase_b1: phase_b1 { - gpios = <&gpio1 14 GPIO_ACTIVE_HIGH>; + gpios = <&gpio2 10 GPIO_ACTIVE_HIGH>; + }; + }; + + qdec_loopbacks: loopbacks { + compatible = "test-qdec-loopbacks"; + loopback0 { + qdec = <&qdec20>; + qenc-emul-gpios = <&phase_a0 &phase_b0>; + }; + loopback1 { + qdec = <&qdec21>; + qenc-emul-gpios = <&phase_a1 &phase_b1>; }; }; }; @@ -55,15 +58,15 @@ qdec_21_pinctrl: qdec_21_pinctrl { group1 { - psels = , - ; + psels = , + ; }; }; qdec_21_sleep_pinctrl: qdec_21_sleep_pinctrl { group1 { - psels = , - ; + psels = , + ; low-power-enable; }; }; diff --git a/tests/boards/nrf/qdec/boards/nrf54lm20dk_nrf54lm20_common.dtsi b/tests/boards/nrf/qdec/boards/nrf54lm20dk_nrf54lm20_common.dtsi index 84e7b1dbc30..6f8f3a18431 100644 --- a/tests/boards/nrf/qdec/boards/nrf54lm20dk_nrf54lm20_common.dtsi +++ b/tests/boards/nrf/qdec/boards/nrf54lm20dk_nrf54lm20_common.dtsi @@ -11,12 +11,6 @@ */ / { - aliases { - qdec0 = &qdec20; - qenca = &phase_a; - qencb = &phase_b; - }; - encoder-emulate { compatible = "gpio-leds"; phase_a: phase_a { @@ -26,6 +20,14 @@ gpios = <&gpio1 23 GPIO_ACTIVE_HIGH>; }; }; + + qdec_loopbacks: loopbacks { + compatible = "test-qdec-loopbacks"; + loopback0 { + qdec = <&qdec20>; + qenc-emul-gpios = <&phase_a &phase_b>; + }; + }; }; &pinctrl { diff --git a/tests/boards/nrf/qdec/dts/bindings/test-qdec-loopback.yaml b/tests/boards/nrf/qdec/dts/bindings/test-qdec-loopback.yaml new file mode 100644 index 00000000000..e03b2ff3bc3 --- /dev/null +++ b/tests/boards/nrf/qdec/dts/bindings/test-qdec-loopback.yaml @@ -0,0 +1,20 @@ +description: | + Binding describing loopbacks required to run tests/boards/nrf/qdec test in Zephyr. + +compatible: "test-qdec-loopbacks" + +child-binding: + description: | + Binding describing a single loopback pair consisting of a QDEC device and two "gpio-leds" pins + working as a quadrature encoder for the test. + properties: + qdec: + type: phandle + required: true + description: Node of the QDEC device used to capture quadrature signal in the loopback. + qenc-emul-gpios: + type: phandles + required: true + description: | + Children nodes of "gpio-leds" compatible used to generate quadrature signal. The first + phandles outputs phase A signal, the second one outputs phase B signal. diff --git a/tests/boards/nrf/qdec/src/main.c b/tests/boards/nrf/qdec/src/main.c index 7df97be2a43..9d138d325fb 100644 --- a/tests/boards/nrf/qdec/src/main.c +++ b/tests/boards/nrf/qdec/src/main.c @@ -11,27 +11,40 @@ #include #include -static K_SEM_DEFINE(sem, 0, 1); -static const struct gpio_dt_spec phase_a = GPIO_DT_SPEC_GET(DT_ALIAS(qenca), gpios); -static const struct gpio_dt_spec phase_b = GPIO_DT_SPEC_GET(DT_ALIAS(qencb), gpios); -static const struct device *const qdec_dev = DEVICE_DT_GET(DT_ALIAS(qdec0)); -static const uint32_t qdec_config_step = DT_PROP(DT_ALIAS(qdec0), steps); - -/* Disable testing second QDEC instance - * until the issue with multiple - * QDEC instances support is resolved +/** + * Structure grouping gpio pins used for QENC emulation connected with a QDEC device + * with a loopback. */ -#if DT_NODE_EXISTS(DT_ALIAS(qdecX)) -#define SECOND_QDEC_INSTANCE - -static const struct gpio_dt_spec phase_a1 = GPIO_DT_SPEC_GET(DT_ALIAS(qenca1), gpios); -static const struct gpio_dt_spec phase_b1 = GPIO_DT_SPEC_GET(DT_ALIAS(qencb1), gpios); -static const struct device *const qdec_1_dev = DEVICE_DT_GET(DT_ALIAS(qdec1)); -static const uint32_t qdec_1_config_step = DT_PROP(DT_ALIAS(qdec1), steps); -#endif +struct qdec_qenc_loopback { + struct gpio_dt_spec qenc_phase_a; + struct gpio_dt_spec qenc_phase_b; + + const struct device *qdec; + uint32_t qdec_config_step; +}; + +static K_SEM_DEFINE(sem, 0, 1); + +#define GET_QDEC_QENC_LOOPBACK(x) \ + { \ + .qenc_phase_a = GPIO_DT_SPEC_GET(DT_PHANDLE_BY_IDX(x, qenc_emul_gpios, 0), gpios), \ + .qenc_phase_b = GPIO_DT_SPEC_GET(DT_PHANDLE_BY_IDX(x, qenc_emul_gpios, 1), gpios), \ + .qdec = DEVICE_DT_GET(DT_PHANDLE(x, qdec)), \ + .qdec_config_step = DT_PROP_BY_PHANDLE(x, qdec, steps) \ + } + + +struct qdec_qenc_loopback loopbacks[] = { + DT_FOREACH_CHILD_SEP(DT_NODELABEL(qdec_loopbacks), GET_QDEC_QENC_LOOPBACK, (,)) +}; + +#define TESTED_QDEC_COUNT ARRAY_SIZE(loopbacks) + static struct sensor_trigger qdec_trigger = {.type = SENSOR_TRIG_DATA_READY, .chan = SENSOR_CHAN_ROTATION}; + static bool toggle_a = true; +static struct qdec_qenc_loopback *loopback_currently_under_test; static void qdec_trigger_handler(const struct device *dev, const struct sensor_trigger *trigger) { @@ -48,15 +61,9 @@ static void qdec_trigger_handler(const struct device *dev, const struct sensor_t static void qenc_emulate_work_handler(struct k_work *work) { if (toggle_a) { - gpio_pin_toggle_dt(&phase_a); -#if defined(SECOND_QDEC_INSTANCE) - gpio_pin_toggle_dt(&phase_a1); -#endif + gpio_pin_toggle_dt(&loopback_currently_under_test->qenc_phase_a); } else { - gpio_pin_toggle_dt(&phase_b); -#if defined(SECOND_QDEC_INSTANCE) - gpio_pin_toggle_dt(&phase_b1); -#endif + gpio_pin_toggle_dt(&loopback_currently_under_test->qenc_phase_b); } toggle_a = !toggle_a; } @@ -89,52 +96,46 @@ static void qenc_emulate_setup_pin(const struct gpio_dt_spec *gpio_dt) zassert_true(rc == 0, "%s: pin configure failed: %d", gpio_dt->port->name, rc); } -static void qenc_emulate_start(k_timeout_t period, bool forward) +static void qenc_emulate_start(struct qdec_qenc_loopback *loopback, k_timeout_t period, + bool forward) { - qenc_emulate_reset_pin(&phase_a); - qenc_emulate_reset_pin(&phase_b); -#if defined(SECOND_QDEC_INSTANCE) - qenc_emulate_reset_pin(&phase_a1); - qenc_emulate_reset_pin(&phase_b1); -#endif + qenc_emulate_reset_pin(&loopback->qenc_phase_a); + qenc_emulate_reset_pin(&loopback->qenc_phase_b); toggle_a = !forward; - + loopback_currently_under_test = loopback; k_timer_start(&qenc_emulate_timer, period, period); } static void qenc_emulate_stop(void) { - k_timer_stop(&qenc_emulate_timer); - - qenc_emulate_reset_pin(&phase_a); - qenc_emulate_reset_pin(&phase_b); -#if defined(SECOND_QDEC_INSTANCE) - qenc_emulate_reset_pin(&phase_a1); - qenc_emulate_reset_pin(&phase_b1); -#endif + if (loopback_currently_under_test) { + k_timer_stop(&qenc_emulate_timer); + qenc_emulate_reset_pin(&loopback_currently_under_test->qenc_phase_a); + qenc_emulate_reset_pin(&loopback_currently_under_test->qenc_phase_b); + } } -static void qenc_emulate_verify_reading(const struct device *const dev, int emulator_period_ms, - int emulation_duration_ms, bool forward, bool overflow_expected, - const uint32_t config_step) +static void qenc_emulate_verify_reading(struct qdec_qenc_loopback *loopback, + int emulator_period_ms, int emulation_duration_ms, bool forward, + bool overflow_expected) { int rc; struct sensor_value val = {0}; int32_t expected_steps = emulation_duration_ms / emulator_period_ms; - int32_t expected_reading = 360 * expected_steps / config_step; - int32_t delta = expected_reading / 5; + int32_t expected_reading = 360 * expected_steps / loopback->qdec_config_step; + int32_t delta = expected_reading / 4; if (!forward) { expected_reading *= -1; } - qenc_emulate_start(K_MSEC(emulator_period_ms), forward); + qenc_emulate_start(loopback, K_MSEC(emulator_period_ms), forward); /* wait for some readings */ k_msleep(emulation_duration_ms); - rc = sensor_sample_fetch(dev); + rc = sensor_sample_fetch(loopback->qdec); if (!overflow_expected) { zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); @@ -142,7 +143,7 @@ static void qenc_emulate_verify_reading(const struct device *const dev, int emul zassert_true(rc == -EOVERFLOW, "Failed to detect overflow"); } - rc = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &val); + rc = sensor_channel_get(loopback->qdec, SENSOR_CHAN_ROTATION, &val); zassert_true(rc == 0, "Failed to get sample (%d)", rc); TC_PRINT("Expected reading: %d, actual value: %d, delta: %d\n", @@ -157,31 +158,31 @@ static void qenc_emulate_verify_reading(const struct device *const dev, int emul /* wait and get readings to clear state */ k_msleep(100); - rc = sensor_sample_fetch(dev); + rc = sensor_sample_fetch(loopback->qdec); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); - rc = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &val); + rc = sensor_channel_get(loopback->qdec, SENSOR_CHAN_ROTATION, &val); zassert_true(rc == 0, "Failed to get sample (%d)", rc); } -static void sensor_trigger_set_and_disable(const struct device *const dev) +static void sensor_trigger_set_and_disable(struct qdec_qenc_loopback *loopback) { int rc; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(dev); + pm_device_runtime_get(loopback->qdec); } k_sem_give(&sem); qdec_trigger.type = SENSOR_TRIG_DATA_READY; qdec_trigger.chan = SENSOR_CHAN_ALL; - rc = sensor_trigger_set(dev, &qdec_trigger, qdec_trigger_handler); + rc = sensor_trigger_set(loopback->qdec, &qdec_trigger, qdec_trigger_handler); zassume_true(rc != -ENOSYS, "sensor_trigger_set not supported"); zassert_true(rc == 0, "sensor_trigger_set failed: %d", rc); - qenc_emulate_start(K_MSEC(10), true); + qenc_emulate_start(loopback, K_MSEC(10), true); /* emulation working, handler should be called */ rc = k_sem_take(&sem, K_MSEC(200)); @@ -193,7 +194,7 @@ static void sensor_trigger_set_and_disable(const struct device *const dev) rc = k_sem_take(&sem, K_MSEC(200)); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(dev); + pm_device_runtime_put(loopback->qdec); } /* there should be no triggers now*/ @@ -201,21 +202,21 @@ static void sensor_trigger_set_and_disable(const struct device *const dev) zassert_true(rc == -EAGAIN, "qdec handler should not be triggered (%d)", rc); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(dev); + pm_device_runtime_get(loopback->qdec); } /* register empty trigger - disable trigger */ - rc = sensor_trigger_set(dev, &qdec_trigger, NULL); + rc = sensor_trigger_set(loopback->qdec, &qdec_trigger, NULL); zassert_true(rc == 0, "sensor_trigger_set failed: %d", rc); - qenc_emulate_start(K_MSEC(10), true); + qenc_emulate_start(loopback, K_MSEC(10), true); /* emulation working, but handler not set, thus should not be called */ rc = k_sem_take(&sem, K_MSEC(200)); zassert_true(rc == -EAGAIN, "qdec handler should not be triggered (%d)", rc); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(dev); + pm_device_runtime_put(loopback->qdec); } } @@ -227,49 +228,50 @@ static void sensor_trigger_set_and_disable(const struct device *const dev) */ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable) { - TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); - sensor_trigger_set_and_disable(qdec_dev); -#if defined(SECOND_QDEC_INSTANCE) - TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); - sensor_trigger_set_and_disable(qdec_1_dev); -#endif - + for (size_t i = 0; i < TESTED_QDEC_COUNT; i++) { + TC_PRINT("Testing QDEC index %d, address: %p\n", i, loopbacks[i].qdec); + sensor_trigger_set_and_disable(&loopbacks[i]); + } } -static void sensor_trigger_set_test(const struct device *const dev) +static void sensor_trigger_set_test(struct qdec_qenc_loopback *loopback) { int rc; struct sensor_value val = {0}; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(dev); + pm_device_runtime_get(loopback->qdec); } qdec_trigger.type = SENSOR_TRIG_DATA_READY; qdec_trigger.chan = SENSOR_CHAN_ROTATION; - rc = sensor_trigger_set(dev, &qdec_trigger, qdec_trigger_handler); + rc = sensor_trigger_set(loopback->qdec, &qdec_trigger, qdec_trigger_handler); zassume_true(rc != -ENOSYS, "sensor_trigger_set not supported"); zassert_true(rc == 0, "sensor_trigger_set failed: %d", rc); - qenc_emulate_start(K_MSEC(10), true); + qenc_emulate_start(loopback, K_MSEC(10), true); /* emulation working now */ rc = k_sem_take(&sem, K_MSEC(200)); zassert_true(rc == 0, "qdec handler should be triggered (%d)", rc); - rc = sensor_sample_fetch(dev); + rc = sensor_sample_fetch(loopback->qdec); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); - rc = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &val); + rc = sensor_channel_get(loopback->qdec, SENSOR_CHAN_ROTATION, &val); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); TC_PRINT("QDEC reading: %d\n", val.val1); zassert_true(val.val1 != 0, "No readings from QDEC"); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(dev); + pm_device_runtime_put(loopback->qdec); } + + qenc_emulate_stop(); + /* emulation not working, but there may be old trigger which needs to be cleaned up */ + rc = k_sem_take(&sem, K_MSEC(200)); } /** @@ -280,39 +282,37 @@ static void sensor_trigger_set_test(const struct device *const dev) */ ZTEST(qdec_sensor, test_sensor_trigger_set) { - TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); - sensor_trigger_set_test(qdec_dev); -#if defined(SECOND_QDEC_INSTANCE) - TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); - sensor_trigger_set_test(qdec_1_dev); -#endif + for (size_t i = 0; i < TESTED_QDEC_COUNT; i++) { + TC_PRINT("Testing QDEC index %d, address: %p\n", i, loopbacks[i].qdec); + sensor_trigger_set_test(&loopbacks[i]); + } } -static void sensor_trigger_set_negative(const struct device *const dev) +static void sensor_trigger_set_negative(struct qdec_qenc_loopback *loopback) { int rc; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(dev); + pm_device_runtime_get(loopback->qdec); } - rc = sensor_trigger_set(dev, &qdec_trigger, qdec_trigger_handler); + rc = sensor_trigger_set(loopback->qdec, &qdec_trigger, qdec_trigger_handler); zassume_true(rc != -ENOSYS, "sensor_trigger_set not supported"); qdec_trigger.type = SENSOR_TRIG_MAX; qdec_trigger.chan = SENSOR_CHAN_ROTATION; - rc = sensor_trigger_set(dev, &qdec_trigger, qdec_trigger_handler); + rc = sensor_trigger_set(loopback->qdec, &qdec_trigger, qdec_trigger_handler); zassume_true(rc < 0, "sensor_trigger_set should fail due to invalid trigger type"); qdec_trigger.type = SENSOR_TRIG_DATA_READY; qdec_trigger.chan = SENSOR_CHAN_MAX; - rc = sensor_trigger_set(dev, &qdec_trigger, qdec_trigger_handler); + rc = sensor_trigger_set(loopback->qdec, &qdec_trigger, qdec_trigger_handler); zassume_true(rc < 0, "sensor_trigger_set should fail due to invalid channel"); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(dev); + pm_device_runtime_put(loopback->qdec); } } @@ -324,12 +324,10 @@ static void sensor_trigger_set_negative(const struct device *const dev) */ ZTEST(qdec_sensor, test_sensor_trigger_set_negative) { - TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); - sensor_trigger_set_negative(qdec_dev); -#if defined(SECOND_QDEC_INSTANCE) - TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); - sensor_trigger_set_negative(qdec_1_dev); -#endif + for (size_t i = 0; i < TESTED_QDEC_COUNT; i++) { + TC_PRINT("Testing QDEC index %d, address: %p\n", i, loopbacks[i].qdec); + sensor_trigger_set_negative(&loopbacks[i]); + } } /** @@ -340,37 +338,22 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_negative) */ ZTEST(qdec_sensor, test_qdec_readings) { - if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(qdec_dev); + for (size_t i = 0; i < TESTED_QDEC_COUNT; i++) { + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(loopbacks[i].qdec); + } + + TC_PRINT("Testing QDEC index %d, address: %p\n", i, loopbacks[i].qdec); + qenc_emulate_verify_reading(&loopbacks[i], 10, 100, true, false); + qenc_emulate_verify_reading(&loopbacks[i], 2, 500, true, false); + qenc_emulate_verify_reading(&loopbacks[i], 10, 200, false, false); + qenc_emulate_verify_reading(&loopbacks[i], 1, 1000, false, true); + qenc_emulate_verify_reading(&loopbacks[i], 1, 1000, true, true); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(loopbacks[i].qdec); + } } - - TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); - qenc_emulate_verify_reading(qdec_dev, 10, 100, true, false, qdec_config_step); - qenc_emulate_verify_reading(qdec_dev, 2, 500, true, false, qdec_config_step); - qenc_emulate_verify_reading(qdec_dev, 10, 200, false, false, qdec_config_step); - qenc_emulate_verify_reading(qdec_dev, 1, 1000, false, true, qdec_config_step); - qenc_emulate_verify_reading(qdec_dev, 1, 1000, true, true, qdec_config_step); - - if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(qdec_dev); - } - -#if defined(SECOND_QDEC_INSTANCE) - if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(qdec_1_dev); - } - - TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); - qenc_emulate_verify_reading(qdec_1_dev, 10, 100, true, false, qdec_1_config_step); - qenc_emulate_verify_reading(qdec_1_dev, 2, 500, true, false, qdec_1_config_step); - qenc_emulate_verify_reading(qdec_1_dev, 10, 200, false, false, qdec_1_config_step); - qenc_emulate_verify_reading(qdec_1_dev, 1, 1000, false, true, qdec_1_config_step); - qenc_emulate_verify_reading(qdec_1_dev, 1, 1000, true, true, qdec_1_config_step); - - if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(qdec_1_dev); - } -#endif } static void sensor_channel_get_empty(const struct device *const dev) @@ -419,40 +402,38 @@ static void sensor_channel_get_empty(const struct device *const dev) */ ZTEST(qdec_sensor, test_sensor_channel_get_empty) { - TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); - sensor_channel_get_empty(qdec_dev); -#if defined(SECOND_QDEC_INSTANCE) - TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); - sensor_channel_get_empty(qdec_1_dev); -#endif + for (size_t i = 0; i < TESTED_QDEC_COUNT; i++) { + TC_PRINT("Testing QDEC index %d, address: %p\n", i, loopbacks[i].qdec); + sensor_channel_get_empty(loopbacks[i].qdec); + } } -static void sensor_channel_get_test(const struct device *const dev) +static void sensor_channel_get_test(struct qdec_qenc_loopback *loopback) { int rc; struct sensor_value val_first = {0}; struct sensor_value val_second = {0}; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(qdec_dev); + pm_device_runtime_get(loopback->qdec); } - qenc_emulate_start(K_MSEC(10), true); + qenc_emulate_start(loopback, K_MSEC(10), true); /* wait for some readings*/ k_msleep(100); - rc = sensor_sample_fetch(qdec_dev); + rc = sensor_sample_fetch(loopback->qdec); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); - rc = sensor_channel_get(qdec_dev, SENSOR_CHAN_ROTATION, &val_first); + rc = sensor_channel_get(loopback->qdec, SENSOR_CHAN_ROTATION, &val_first); zassert_true(rc == 0, "Failed to get sample (%d)", rc); zassert_true(val_first.val1 != 0, "No readings from QDEC"); /* wait for more readings*/ k_msleep(200); - rc = sensor_channel_get(qdec_dev, SENSOR_CHAN_ROTATION, &val_second); + rc = sensor_channel_get(loopback->qdec, SENSOR_CHAN_ROTATION, &val_second); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); zassert_true(val_second.val1 != 0, "No readings from QDEC"); @@ -470,7 +451,7 @@ static void sensor_channel_get_test(const struct device *const dev) val_second.val2); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(qdec_dev); + pm_device_runtime_put(loopback->qdec); } } @@ -482,38 +463,36 @@ static void sensor_channel_get_test(const struct device *const dev) */ ZTEST(qdec_sensor, test_sensor_channel_get) { - TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); - sensor_channel_get_test(qdec_dev); -#if defined(SECOND_QDEC_INSTANCE) - TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); - sensor_channel_get_test(qdec_1_dev); -#endif + for (size_t i = 0; i < TESTED_QDEC_COUNT; i++) { + TC_PRINT("Testing QDEC index %d, address: %p\n", i, loopbacks[i].qdec); + sensor_channel_get_test(&loopbacks[i]); + } } -static void sensor_channel_get_negative(const struct device *const dev) +static void sensor_channel_get_negative(struct qdec_qenc_loopback *loopback) { int rc; struct sensor_value val = {0}; if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_get(dev); + pm_device_runtime_get(loopback->qdec); } - qenc_emulate_start(K_MSEC(10), true); + qenc_emulate_start(loopback, K_MSEC(10), true); /* wait for some readings*/ k_msleep(100); - rc = sensor_sample_fetch(dev); + rc = sensor_sample_fetch(loopback->qdec); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); - rc = sensor_channel_get(dev, SENSOR_CHAN_MAX, &val); + rc = sensor_channel_get(loopback->qdec, SENSOR_CHAN_MAX, &val); zassert_true(rc < 0, "Should failed to get sample (%d)", rc); zassert_true(val.val1 == 0, "Some readings from QDEC: %d", val.val1); zassert_true(val.val2 == 0, "Some readings from QDEC: %d", val.val2); if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - pm_device_runtime_put(dev); + pm_device_runtime_put(loopback->qdec); } } @@ -525,12 +504,10 @@ static void sensor_channel_get_negative(const struct device *const dev) */ ZTEST(qdec_sensor, test_sensor_channel_get_negative) { - TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); - sensor_channel_get_negative(qdec_dev); -#if defined(SECOND_QDEC_INSTANCE) - TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); - sensor_channel_get_negative(qdec_1_dev); -#endif + for (size_t i = 0; i < TESTED_QDEC_COUNT; i++) { + TC_PRINT("Testing QDEC index %d, address: %p\n", i, loopbacks[i].qdec); + sensor_channel_get_negative(&loopbacks[i]); + } } static void sensor_sample_fetch_test(const struct device *const dev) @@ -563,32 +540,22 @@ static void sensor_sample_fetch_test(const struct device *const dev) */ ZTEST(qdec_sensor, test_sensor_sample_fetch) { - TC_PRINT("Testing QDEC-0, address: %p\n", qdec_dev); - sensor_sample_fetch_test(qdec_dev); -#if defined(SECOND_QDEC_INSTANCE) - TC_PRINT("Testing QDEC-1, address: %p\n", qdec_1_dev); - sensor_sample_fetch_test(qdec_1_dev); -#endif + for (size_t i = 0; i < TESTED_QDEC_COUNT; i++) { + TC_PRINT("Testing QDEC index %d, address: %p\n", i, loopbacks[i].qdec); + sensor_sample_fetch_test(loopbacks[i].qdec); + } } static void *setup(void) { - int rc; - - rc = device_is_ready(qdec_dev); - zassert_true(rc, "QDEC device not ready: %d", rc); + for (size_t i = 0; i < TESTED_QDEC_COUNT; i++) { + int rc = device_is_ready(loopbacks[i].qdec); - qenc_emulate_setup_pin(&phase_a); - qenc_emulate_setup_pin(&phase_b); - -#if defined(SECOND_QDEC_INSTANCE) - rc = device_is_ready(qdec_1_dev); - zassert_true(rc, "QDEC 1 device not ready: %d", rc); - - qenc_emulate_setup_pin(&phase_a1); - qenc_emulate_setup_pin(&phase_b1); -#endif + zassert_true(rc, "QDEC index %d not ready: %d", i, rc); + qenc_emulate_setup_pin(&loopbacks[i].qenc_phase_a); + qenc_emulate_setup_pin(&loopbacks[i].qenc_phase_b); + } return NULL; } From 8876f35b0208e315d554ca1fec6f66643340fd0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stine=20=C3=85kredalen?= Date: Mon, 4 Aug 2025 01:26:12 +0200 Subject: [PATCH 18/42] [nrf noup] samples: bluetooth: mesh: update stack sizes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Increased stack sizes for mesh provisoner sample. Values are based of thread analysis, plus added margin. Signed-off-by: Stine Åkredalen --- samples/bluetooth/mesh_provisioner/prj.conf | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/samples/bluetooth/mesh_provisioner/prj.conf b/samples/bluetooth/mesh_provisioner/prj.conf index 24176780516..0e5f6490ede 100644 --- a/samples/bluetooth/mesh_provisioner/prj.conf +++ b/samples/bluetooth/mesh_provisioner/prj.conf @@ -1,6 +1,10 @@ #CONFIG_INIT_STACKS=y -CONFIG_MAIN_STACK_SIZE=2048 -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 +# Stack sizes from thread analysis + 50% margin, rounded to nearest 100 +CONFIG_MAIN_STACK_SIZE=4400 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4800 +CONFIG_BT_MESH_SETTINGS_WORKQ_STACK_SIZE=1700 +CONFIG_BT_MESH_ADV_STACK_SIZE=4000 +CONFIG_BT_RX_STACK_SIZE=3300 # The Bluetooth API should not be used from a preemptive thread: CONFIG_MAIN_THREAD_PRIORITY=-2 From f10e671ae2b0ecfadb48592d51fae88800ce836b Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Tue, 17 Jun 2025 14:17:39 +0200 Subject: [PATCH 19/42] [nrf fromtree] soc: nordic: 54h20: bicr: Fix order of enum The order of the enumNames array needs to match the actual enum values array below it. Signed-off-by: Carles Cufi (cherry picked from commit d215f5efec6832ec52947e7384284414cdf0db14) --- soc/nordic/nrf54h/bicr/bicr-schema.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/soc/nordic/nrf54h/bicr/bicr-schema.json b/soc/nordic/nrf54h/bicr/bicr-schema.json index b43b7236a6b..70e133f6ae0 100644 --- a/soc/nordic/nrf54h/bicr/bicr-schema.json +++ b/soc/nordic/nrf54h/bicr/bicr-schema.json @@ -11,8 +11,8 @@ "title": "Power supply scheme", "enumNames": [ "Unconfigured (system will not boot)", - "VDDH supplied with 2.1-5.5 V and VDD regulated by the chip (inductor present)", - "Both VDD and VDDH supplied with 1.8 V (inductor present)" + "Both VDD and VDDH supplied with 1.8 V (inductor present)", + "VDDH supplied with 2.1-5.5 V and VDD regulated by the chip (inductor present)" ], "enum": [ "UNCONFIGURED", From 64848a42d2b6c12fc6f3ed89fad4272195ceadd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Amundsen?= Date: Thu, 26 Jun 2025 09:06:45 +0200 Subject: [PATCH 20/42] [nrf fromtree] soc: nordic: 54h20: fix typo ETX -> EXT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix typo in BICR schema Signed-off-by: Håkon Amundsen (cherry picked from commit e96a63ad82c6c7c20dbe7554777226a7ea4fca48) --- soc/nordic/nrf54h/bicr/bicr-schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soc/nordic/nrf54h/bicr/bicr-schema.json b/soc/nordic/nrf54h/bicr/bicr-schema.json index 70e133f6ae0..a43107a12b6 100644 --- a/soc/nordic/nrf54h/bicr/bicr-schema.json +++ b/soc/nordic/nrf54h/bicr/bicr-schema.json @@ -193,7 +193,7 @@ ], "enum": [ "CRYSTAL", - "ETX_SINE", + "EXT_SINE", "EXT_SQUARE" ], "default": "CRYSTAL" From 05746fdc63754ddf8eee3ce25485760dbcb86df4 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 5 Aug 2025 09:13:03 +0200 Subject: [PATCH 21/42] [nrf fromlist] drivers: adc: nrfx_saadc: Add support for DMM Add support for DMM which manages cache and dedicated memory spaces. Upstream PR #: 90751 Signed-off-by: Jakub Zymelka --- drivers/adc/adc_nrfx_saadc.c | 72 +++++++++++++++++------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index 2ba7b6efd00..7d442b482e6 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -13,6 +13,7 @@ #include #include #include +#include LOG_MODULE_REGISTER(adc_nrfx_saadc, CONFIG_ADC_LOG_LEVEL); @@ -97,34 +98,19 @@ BUILD_ASSERT((NRF_SAADC_AIN0 == NRF_SAADC_INPUT_AIN0) && "Definitions from nrf-adc.h do not match those from nrf_saadc.h"); #endif -#if defined(CONFIG_NRF_PLATFORM_HALTIUM) -#include -/* Haltium devices always use bounce buffers in RAM */ -static uint16_t adc_samples_buffer[SAADC_CH_NUM] DMM_MEMORY_SECTION(DT_NODELABEL(adc)); - -#define ADC_BUFFER_IN_RAM - -#endif /* defined(CONFIG_NRF_PLATFORM_HALTIUM) */ - struct driver_data { struct adc_context ctx; uint8_t single_ended_channels; - nrf_saadc_value_t *buffer; /* Pointer to the buffer with converted samples. */ uint8_t active_channel_cnt; - -#if defined(ADC_BUFFER_IN_RAM) - void *samples_buffer; + void *mem_reg; void *user_buffer; -#endif }; static struct driver_data m_data = { ADC_CONTEXT_INIT_TIMER(m_data, ctx), ADC_CONTEXT_INIT_LOCK(m_data, ctx), ADC_CONTEXT_INIT_SYNC(m_data, ctx), -#if defined(ADC_BUFFER_IN_RAM) - .samples_buffer = adc_samples_buffer, -#endif + .mem_reg = DMM_DEV_TO_REG(DT_NODELABEL(adc)), }; /* Forward declaration */ @@ -392,22 +378,29 @@ static void adc_context_start_sampling(struct adc_context *ctx) if (ret != NRFX_SUCCESS) { LOG_ERR("Cannot start sampling: 0x%08x", ret); - adc_context_complete(&m_data.ctx, -EIO); + adc_context_complete(ctx, -EIO); } } } static void adc_context_update_buffer_pointer(struct adc_context *ctx, bool repeat) { + void *samples_buffer; + if (!repeat) { -#if defined(ADC_BUFFER_IN_RAM) m_data.user_buffer = (uint16_t *)m_data.user_buffer + m_data.active_channel_cnt; -#else - nrf_saadc_value_t *buffer = (uint16_t *)m_data.buffer + m_data.active_channel_cnt; + } - nrfx_saadc_buffer_set(buffer, m_data.active_channel_cnt); -#endif + int error = dmm_buffer_in_prepare( + m_data.mem_reg, m_data.user_buffer, + NRFX_SAADC_SAMPLES_TO_BYTES(m_data.active_channel_cnt), + &samples_buffer); + if (error != 0) { + LOG_ERR("DMM buffer allocation failed err=%d", error); + adc_context_complete(ctx, -EIO); } + + nrfx_saadc_buffer_set(samples_buffer, m_data.active_channel_cnt); } static int get_resolution(const struct adc_sequence *sequence, nrf_saadc_resolution_t *resolution) @@ -502,12 +495,12 @@ static bool has_single_ended(const struct adc_sequence *sequence) return sequence->channels & m_data.single_ended_channels; } -static void correct_single_ended(const struct adc_sequence *sequence) +static void correct_single_ended(const struct adc_sequence *sequence, nrf_saadc_value_t *buffer) { uint16_t channel_bit = BIT(0); uint8_t selected_channels = sequence->channels; uint8_t single_ended_channels = m_data.single_ended_channels; - int16_t *sample = (int16_t *)m_data.buffer; + int16_t *sample = (int16_t *)buffer; while (channel_bit <= single_ended_channels) { if (channel_bit & selected_channels) { @@ -532,6 +525,7 @@ static int start_read(const struct device *dev, nrf_saadc_oversample_t oversampling; uint8_t active_channel_cnt = 0U; uint8_t channel_id = 0U; + void *samples_buffer; /* Signal an error if channel selection is invalid (no channels or * a non-existing one is selected). @@ -582,16 +576,21 @@ static int start_read(const struct device *dev, } m_data.active_channel_cnt = active_channel_cnt; -#if defined(ADC_BUFFER_IN_RAM) m_data.user_buffer = sequence->buffer; - nrfx_saadc_buffer_set(m_data.samples_buffer, active_channel_cnt); -#else + error = dmm_buffer_in_prepare(m_data.mem_reg, + m_data.user_buffer, + NRFX_SAADC_SAMPLES_TO_BYTES(active_channel_cnt), + &samples_buffer); + if (error != 0) { + LOG_ERR("DMM buffer allocation failed err=%d", error); + return error; + } + /* Buffer is filled in chunks, each chunk composed of number of samples equal to number * of active channels. Buffer pointer is advanced and reloaded after each chunk. */ - nrfx_saadc_buffer_set(sequence->buffer, active_channel_cnt); -#endif + nrfx_saadc_buffer_set(samples_buffer, active_channel_cnt); adc_context_start_read(&m_data.ctx, sequence); @@ -632,17 +631,14 @@ static void event_handler(const nrfx_saadc_evt_t *event) nrfx_err_t err; if (event->type == NRFX_SAADC_EVT_DONE) { - m_data.buffer = event->data.done.p_buffer; + dmm_buffer_in_release( + m_data.mem_reg, m_data.user_buffer, + NRFX_SAADC_SAMPLES_TO_BYTES(m_data.active_channel_cnt), + event->data.done.p_buffer); if (has_single_ended(&m_data.ctx.sequence)) { - correct_single_ended(&m_data.ctx.sequence); + correct_single_ended(&m_data.ctx.sequence, m_data.user_buffer); } - -#if defined(ADC_BUFFER_IN_RAM) - memcpy(m_data.user_buffer, m_data.samples_buffer, - NRFX_SAADC_SAMPLES_TO_BYTES(m_data.active_channel_cnt)); -#endif - adc_context_on_sampling_done(&m_data.ctx, DEVICE_DT_INST_GET(0)); } else if (event->type == NRFX_SAADC_EVT_CALIBRATEDONE) { err = nrfx_saadc_mode_trigger(); From 77289621634d9247a5b831dcd1c307889ba58104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 4 Aug 2025 14:56:28 +0200 Subject: [PATCH 22/42] Revert "[nrf fromlist] drivers: timer: nrf_grtc_timer: Optimize to reduce register access" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 8cba1f6198f880ce025d6f69625e42cdfdb0d4d0. Signed-off-by: Krzysztof Chruściński --- drivers/timer/nrf_grtc_timer.c | 94 +++++++++++----------------------- 1 file changed, 31 insertions(+), 63 deletions(-) diff --git a/drivers/timer/nrf_grtc_timer.c b/drivers/timer/nrf_grtc_timer.c index 43f6e8e97ca..2809d8b3d60 100644 --- a/drivers/timer/nrf_grtc_timer.c +++ b/drivers/timer/nrf_grtc_timer.c @@ -49,16 +49,12 @@ #define COUNTER_SPAN (GRTC_SYSCOUNTERL_VALUE_Msk | ((uint64_t)GRTC_SYSCOUNTERH_VALUE_Msk << 32)) #define MAX_ABS_TICKS (COUNTER_SPAN / CYC_PER_TICK) -/* To allow use of CCADD we need to limit max cycles to 31 bits. */ -#define MAX_REL_CYCLES BIT_MASK(31) -#define MAX_REL_TICKS (MAX_REL_CYCLES / CYC_PER_TICK) +#define MAX_TICKS \ + (((COUNTER_SPAN / CYC_PER_TICK) > INT_MAX) ? INT_MAX : (COUNTER_SPAN / CYC_PER_TICK)) -#define LFCLK_FREQUENCY_HZ DT_PROP(LFCLK_NODE, clock_frequency) +#define MAX_CYCLES (MAX_TICKS * CYC_PER_TICK) -/* Threshold used to determine if there is a risk of unexpected GRTC COMPARE event coming - * from previous CC value. - */ -#define LATENCY_THR_TICKS 200 +#define LFCLK_FREQUENCY_HZ DT_PROP(LFCLK_NODE, clock_frequency) #if defined(CONFIG_TEST) const int32_t z_sys_timer_irq_for_test = DT_IRQN(GRTC_NODE); @@ -66,10 +62,8 @@ const int32_t z_sys_timer_irq_for_test = DT_IRQN(GRTC_NODE); 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; /* Time (SYSCOUNTER value) @last sys_clock_announce() */ -static uint32_t last_elapsed; -static uint64_t cc_value; /* Value that is expected to be in CC register. */ -static uint64_t expired_cc; /* Value that is expected to be in CC register. */ static atomic_t int_mask; static uint8_t ext_channels_allocated; static uint64_t grtc_start_value; @@ -152,13 +146,17 @@ static void compare_int_unlock(int32_t chan, bool key) static void sys_clock_timeout_handler(int32_t id, uint64_t cc_val, void *p_context) { ARG_UNUSED(id); - ARG_UNUSED(cc_val); ARG_UNUSED(p_context); - uint32_t dticks; + uint64_t dticks; + uint64_t now = counter(); + + if (unlikely(now < cc_val)) { + return; + } dticks = counter_sub(cc_val, last_count) / CYC_PER_TICK; - last_count += (dticks * CYC_PER_TICK); - expired_cc = cc_val; + + last_count += dticks * CYC_PER_TICK; if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) { /* protection is not needed because we are in the GRTC interrupt @@ -167,7 +165,6 @@ static void sys_clock_timeout_handler(int32_t id, uint64_t cc_val, void *p_conte system_timeout_set_abs(last_count + CYC_PER_TICK); } - last_elapsed = 0; sys_clock_announce((int32_t)dticks); } @@ -371,7 +368,6 @@ uint64_t z_nrf_grtc_timer_startup_value_get(void) int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us) { nrfx_err_t err_code; - static struct k_spinlock lock; static uint8_t systemoff_channel; uint64_t now = counter(); nrfx_grtc_sleep_config_t sleep_cfg; @@ -434,12 +430,20 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us) uint32_t sys_clock_cycle_get_32(void) { - return nrf_grtc_sys_counter_low_get(NRF_GRTC); + 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) { - return counter(); + 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) @@ -448,9 +452,7 @@ uint32_t sys_clock_elapsed(void) return 0; } - last_elapsed = (uint32_t)counter_sub(counter(), last_count); - - return last_elapsed / CYC_PER_TICK; + return (uint32_t)(counter_sub(counter(), last_count) / CYC_PER_TICK); } static int sys_clock_driver_init(void) @@ -491,10 +493,6 @@ static int sys_clock_driver_init(void) last_count = (counter() / CYC_PER_TICK) * CYC_PER_TICK; grtc_start_value = last_count; - expired_cc = UINT64_MAX; - nrfx_grtc_channel_callback_set(system_clock_channel_data.channel, - sys_clock_timeout_handler, NULL); - int_mask = NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK; if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) { system_timeout_set_relative(CYC_PER_TICK); @@ -553,48 +551,18 @@ void sys_clock_set_timeout(int32_t ticks, bool idle) return; } - uint32_t ch = system_clock_channel_data.channel; - - if ((cc_value == expired_cc) && (ticks < MAX_REL_TICKS)) { - uint32_t cyc = ticks * CYC_PER_TICK; - - if (cyc == 0) { - /* GRTC will expire anyway since HW ensures that past value triggers an - * event but we need to ensure to always progress the cc_value as this - * if condition expects that cc_value will change after each call to - * set_timeout function. - */ - cyc = 1; - } + ticks = (ticks == K_TICKS_FOREVER) ? MAX_TICKS : MIN(MAX_TICKS, MAX(ticks, 0)); - /* If it's the first timeout setting after previous expiration and timeout - * is short so fast method can be used which utilizes relative CC configuration. - */ - cc_value += cyc; - nrfx_grtc_syscounter_cc_rel_set(ch, cyc, NRFX_GRTC_CC_RELATIVE_COMPARE); - return; - } + uint64_t delta_time = ticks * CYC_PER_TICK; - uint64_t cyc = (uint64_t)ticks * CYC_PER_TICK; - bool safe_setting = false; - int64_t prev_cc_val = cc_value; + uint64_t target_time = counter() + delta_time; - cc_value = last_count + last_elapsed + cyc; - - /* In case of timeout abort it may happen that CC is being set to a value - * that later than previous CC. If previous CC value is not far in the - * future, there is a risk that COMPARE event will be triggered for that - * previous CC value. If there is such risk safe procedure must be applied - * which is more time consuming but ensures that there will be no spurious - * event. + /* Rounded down target_time to the tick boundary + * (but not less than one tick after the last) */ - if (prev_cc_val < cc_value) { - int64_t now = last_count + last_elapsed; - - safe_setting = (prev_cc_val - now) < LATENCY_THR_TICKS; - } + target_time = MAX((target_time - last_count)/CYC_PER_TICK, 1)*CYC_PER_TICK + last_count; - nrfx_grtc_syscounter_cc_abs_set(ch, cc_value, safe_setting); + system_timeout_set_abs(target_time); } #if defined(CONFIG_NRF_GRTC_TIMER_APP_DEFINED_INIT) From 3d9083487d0e8797f9c55d785b3589b14e1122ee Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 5 Aug 2025 09:54:06 +0200 Subject: [PATCH 23/42] Revert "[nrf fromlist] net: l2: wifi: Fix the default keepalive value" This reverts commit d87f317227c9bbdc2c9712d195560841dd8740fd. Signed-off-by: Robert Lubos --- subsys/net/l2/wifi/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 49d061c7439..7728678cc97 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -158,7 +158,7 @@ endif # WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE config WIFI_MGMT_BSS_MAX_IDLE_TIME int "BSS max idle timeout in seconds" range 0 64000 - default 300 + default 30 help As per 802.11-2020: 11.21.13 BSS max idle period management If dot11WirelessManagementImplemented is true, dot11BSSMaxIdlePeriod is From c162fe25fefddc2f6c39c8ba0ca9dbd35d2119c5 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 5 Aug 2025 09:54:14 +0200 Subject: [PATCH 24/42] Revert "[nrf noup] net: l2: wifi: Configure BSS max idle period" This reverts commit 691b66e66d350d3e64e35f0fec1d490152cd2f53. Signed-off-by: Robert Lubos --- drivers/wifi/nrf_wifi/inc/fmac_main.h | 1 - drivers/wifi/nrf_wifi/inc/wifi_mgmt.h | 3 -- drivers/wifi/nrf_wifi/src/fmac_main.c | 4 -- drivers/wifi/nrf_wifi/src/wifi_mgmt.c | 53 ------------------------- drivers/wifi/nrf_wifi/src/wpa_supp_if.c | 6 +-- include/zephyr/net/wifi_mgmt.h | 16 -------- modules/hostap/src/supp_api.c | 13 ------ modules/hostap/src/supp_api.h | 8 ---- modules/hostap/src/supp_main.c | 1 - subsys/net/l2/wifi/Kconfig | 16 -------- subsys/net/l2/wifi/wifi_mgmt.c | 25 ------------ subsys/net/l2/wifi/wifi_shell.c | 32 --------------- 12 files changed, 2 insertions(+), 176 deletions(-) diff --git a/drivers/wifi/nrf_wifi/inc/fmac_main.h b/drivers/wifi/nrf_wifi/inc/fmac_main.h index 7a863d8b614..c193515ae2d 100644 --- a/drivers/wifi/nrf_wifi/inc/fmac_main.h +++ b/drivers/wifi/nrf_wifi/inc/fmac_main.h @@ -91,7 +91,6 @@ struct nrf_wifi_vif_ctx_zep { struct k_work_delayable nrf_wifi_rpu_recovery_bringup_work; #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ int rts_threshold_value; - unsigned short bss_max_idle_period; }; struct nrf_wifi_vif_ctx_map { diff --git a/drivers/wifi/nrf_wifi/inc/wifi_mgmt.h b/drivers/wifi/nrf_wifi/inc/wifi_mgmt.h index 9b84427cdca..a4ae2030210 100644 --- a/drivers/wifi/nrf_wifi/inc/wifi_mgmt.h +++ b/drivers/wifi/nrf_wifi/inc/wifi_mgmt.h @@ -77,7 +77,4 @@ int nrf_wifi_set_rts_threshold(const struct device *dev, int nrf_wifi_get_rts_threshold(const struct device *dev, unsigned int *rts_threshold); - -int nrf_wifi_set_bss_max_idle_period(const struct device *dev, - unsigned short bss_max_idle_period); #endif /* __ZEPHYR_WIFI_MGMT_H__ */ diff --git a/drivers/wifi/nrf_wifi/src/fmac_main.c b/drivers/wifi/nrf_wifi/src/fmac_main.c index f2d9aa55af9..379c3242b18 100644 --- a/drivers/wifi/nrf_wifi/src/fmac_main.c +++ b/drivers/wifi/nrf_wifi/src/fmac_main.c @@ -858,9 +858,6 @@ static int nrf_wifi_drv_main_zep(const struct device *dev) #endif /* CONFIG_NRF70_RADIO_TEST */ k_mutex_init(&rpu_drv_priv_zep.rpu_ctx_zep.rpu_lock); -#ifndef CONFIG_NRF70_RADIO_TEST - vif_ctx_zep->bss_max_idle_period = USHRT_MAX; -#endif /* !CONFIG_NRF70_RADIO_TEST */ return 0; #ifdef CONFIG_NRF70_RADIO_TEST fmac_deinit: @@ -888,7 +885,6 @@ static const struct wifi_mgmt_ops nrf_wifi_mgmt_ops = { .get_power_save_config = nrf_wifi_get_power_save_config, .set_rts_threshold = nrf_wifi_set_rts_threshold, .get_rts_threshold = nrf_wifi_get_rts_threshold, - .set_bss_max_idle_period = nrf_wifi_set_bss_max_idle_period, #endif #ifdef CONFIG_NRF70_SYSTEM_WITH_RAW_MODES .mode = nrf_wifi_mode, diff --git a/drivers/wifi/nrf_wifi/src/wifi_mgmt.c b/drivers/wifi/nrf_wifi/src/wifi_mgmt.c index e9755e80013..a323faf21dd 100644 --- a/drivers/wifi/nrf_wifi/src/wifi_mgmt.c +++ b/drivers/wifi/nrf_wifi/src/wifi_mgmt.c @@ -1077,56 +1077,3 @@ int nrf_wifi_get_rts_threshold(const struct device *dev, return ret; } - -int nrf_wifi_set_bss_max_idle_period(const struct device *dev, - unsigned short bss_max_idle_period) -{ - struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; - struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL; - int ret = -1; - - if (!dev) { - LOG_ERR("%s: dev is NULL", __func__); - return ret; - } - - vif_ctx_zep = dev->data; - - if (!vif_ctx_zep) { - LOG_ERR("%s: vif_ctx_zep is NULL", __func__); - return ret; - } - - rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; - - if (!rpu_ctx_zep) { - LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); - return ret; - } - - - if (!rpu_ctx_zep->rpu_ctx) { - LOG_ERR("%s: RPU context not initialized", __func__); - return ret; - } - - if (((int)bss_max_idle_period < 0) || - (bss_max_idle_period > 64000)) { - /* 0 or value less than 64000 is passed to f/w. - * All other values considered as invalid. - */ - LOG_ERR("%s: Invalid max_idle_period value : %d", - __func__, (int)bss_max_idle_period); - return ret; - } - - k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER); - - vif_ctx_zep->bss_max_idle_period = bss_max_idle_period; - - ret = 0; - - k_mutex_unlock(&vif_ctx_zep->vif_lock); - - return ret; -} diff --git a/drivers/wifi/nrf_wifi/src/wpa_supp_if.c b/drivers/wifi/nrf_wifi/src/wpa_supp_if.c index 21f7600ca80..34af00e6d38 100644 --- a/drivers/wifi/nrf_wifi/src/wpa_supp_if.c +++ b/drivers/wifi/nrf_wifi/src/wpa_supp_if.c @@ -931,10 +931,8 @@ int nrf_wifi_wpa_supp_associate(void *if_priv, struct wpa_driver_associate_param assoc_info.use_mfp = NRF_WIFI_MFP_REQUIRED; } - if (vif_ctx_zep->bss_max_idle_period == USHRT_MAX) { - assoc_info.bss_max_idle_time = CONFIG_WIFI_MGMT_BSS_MAX_IDLE_TIME; - } else { - assoc_info.bss_max_idle_time = vif_ctx_zep->bss_max_idle_period; + if (params->bss_max_idle_period) { + assoc_info.bss_max_idle_time = params->bss_max_idle_period; } assoc_info.conn_type = NRF_WIFI_CONN_TYPE_OPEN; diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 00c83a986ea..5477b6a3c0e 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -133,8 +133,6 @@ enum net_request_wifi_cmd { NET_REQUEST_WIFI_CMD_CANDIDATE_SCAN, /** AP WPS config */ NET_REQUEST_WIFI_CMD_AP_WPS_CONFIG, - /** Configure BSS maximum idle period */ - NET_REQUEST_WIFI_CMD_BSS_MAX_IDLE_PERIOD, /** @cond INTERNAL_HIDDEN */ NET_REQUEST_WIFI_CMD_MAX /** @endcond */ @@ -319,11 +317,6 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_START_ROAMING); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_NEIGHBOR_REP_COMPLETE); -#define NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD \ - (NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_BSS_MAX_IDLE_PERIOD) - -NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD); - /** @brief Wi-Fi management events */ enum net_event_wifi_cmd { /** Scan results available */ @@ -1566,15 +1559,6 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*start_11r_roaming)(const struct device *dev); - /** Set BSS max idle period - * - * @param dev Pointer to the device structure for the driver instance. - * @param BSS max idle period value - * - * @return 0 if ok, < 0 if error - */ - int (*set_bss_max_idle_period)(const struct device *dev, - unsigned short bss_max_idle_period); }; /** Wi-Fi management offload API */ diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 3679808b3d4..cde1ef95f47 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -1811,19 +1811,6 @@ int supplicant_legacy_roam(const struct device *dev) return ret; } -int supplicant_set_bss_max_idle_period(const struct device *dev, - unsigned short bss_max_idle_period) -{ - const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev); - - if (!wifi_mgmt_api || !wifi_mgmt_api->set_bss_max_idle_period) { - wpa_printf(MSG_ERROR, "set_bss_max_idle_period is not supported"); - return -ENOTSUP; - } - - return wifi_mgmt_api->set_bss_max_idle_period(dev, bss_max_idle_period); -} - #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM int supplicant_btm_query(const struct device *dev, uint8_t reason) { diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index 9d2b90b50fe..ddd3c3d6698 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -305,14 +305,6 @@ int supplicant_get_wifi_conn_params(const struct device *dev, */ int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params); -/** @ Set Wi-Fi max idle period - * - * @param dev Wi-Fi interface handle to use - * @param bss_max_idle_period Maximum idle period to set - * @return 0 for OK; -1 for ERROR - */ -int supplicant_set_bss_max_idle_period(const struct device *dev, - unsigned short bss_max_idle_period); #ifdef CONFIG_AP int set_ap_bandwidth(const struct device *dev, enum wifi_frequency_bandwidths bandwidth); diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index 849ba834ec1..c2a4866b921 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -83,7 +83,6 @@ static const struct wifi_mgmt_ops mgmt_ops = { #endif .get_conn_params = supplicant_get_wifi_conn_params, .wps_config = supplicant_wps_config, - .set_bss_max_idle_period = supplicant_set_bss_max_idle_period, #ifdef CONFIG_AP .ap_enable = supplicant_ap_enable, .ap_disable = supplicant_ap_disable, diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 7728678cc97..4b1d309066c 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -154,19 +154,3 @@ config HEAP_MEM_POOL_ADD_SIZE_WIFI_CERT endif # WIFI_SHELL_RUNTIME_CERTIFICATES endif # WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE - -config WIFI_MGMT_BSS_MAX_IDLE_TIME - int "BSS max idle timeout in seconds" - range 0 64000 - default 30 - help - As per 802.11-2020: 11.21.13 BSS max idle period management - If dot11WirelessManagementImplemented is true, dot11BSSMaxIdlePeriod is - nonzero and dot11BSSMaxIdlePeriodIndicationByNonAPSTA is true, then a - non-S1G non-AP STA shall include a BSS Max Idle Period element - in the (Re)Association Request frame. If the BSS Max Idle Period - element is present in the (Re)Association Request frame received - by a non-S1G AP that has dot11BSSMaxIdlePeriodIndicationByNonAPSTA - equal to true, then the non-S1G AP may choose the non-AP STA’s - preferred maximum idle period. The non-S1G AP indicates its chosen - value to the non-S1G STA in the (Re)Association Response frame. diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 67f1f68e5a5..dc52c42a5c2 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -1403,31 +1403,6 @@ static int wifi_set_enterprise_creds(uint32_t mgmt_request, struct net_if *iface NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_ENTERPRISE_CREDS, wifi_set_enterprise_creds); #endif -static int wifi_set_bss_max_idle_period(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); - unsigned short *bss_max_idle_period = data; - - if (wifi_mgmt_api == NULL || wifi_mgmt_api->set_bss_max_idle_period == NULL) { - return -ENOTSUP; - } - - if (!net_if_is_admin_up(iface)) { - return -ENETDOWN; - } - - if (!data || len != sizeof(*bss_max_idle_period)) { - return -EINVAL; - } - - return wifi_mgmt_api->set_bss_max_idle_period(dev, *bss_max_idle_period); -} - -NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD, - wifi_set_bss_max_idle_period); - #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 6ef17817aa4..07514b53a33 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -3455,32 +3455,6 @@ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[ return 0; } - -static int cmd_wifi_set_bss_max_idle_period(const struct shell *sh, size_t argc, char *argv[]) -{ - struct net_if *iface = get_iface(IFACE_TYPE_STA, argc, argv); - unsigned short bss_max_idle_period = 0; - int idx = 1; - unsigned long val = 0; - - if (!parse_number(sh, &val, argv[idx++], "bss_max_idle_period", 0, USHRT_MAX)) { - return -EINVAL; - } - - bss_max_idle_period = (unsigned short)val; - - if (net_mgmt(NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD, iface, - &bss_max_idle_period, sizeof(bss_max_idle_period))) { - shell_fprintf(sh, SHELL_WARNING, - "Setting BSS maximum idle period failed.\n"); - return -ENOEXEC; - } - - shell_fprintf(sh, SHELL_NORMAL, "BSS max idle period: %hu\n", bss_max_idle_period); - - return 0; -} - SHELL_STATIC_SUBCMD_SET_CREATE( wifi_cmd_ap, SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n" @@ -3956,12 +3930,6 @@ SHELL_SUBCMD_ADD((wifi), ps_exit_strategy, NULL, cmd_wifi_ps_exit_strategy, 2, 2); -SHELL_SUBCMD_ADD((wifi), bss_max_idle_period, NULL, - ".\n" - "[-i, --iface=] : Interface index.\n", - cmd_wifi_set_bss_max_idle_period, - 2, 2); - SHELL_CMD_REGISTER(wifi, &wifi_commands, "Wi-Fi commands", NULL); static int wifi_shell_init(void) From 8b3dda735e1b57360d80423698f4897c7a790c8b Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Thu, 24 Apr 2025 19:30:07 +0300 Subject: [PATCH 25/42] [nrf fromtree] net: mgmt: Convert the mgmt API to use 64-bit masks Instead of using 32 bit enum values for event numbers, convert the code to use 64 bit long bit fields. This means that the user API is changed to use 64 bit event values instead of 32 bit event values. Signed-off-by: Jukka Rissanen (cherry picked from commit 5a9a39caf3bf5195a38194bb844a428eaa7f2bb8) Signed-off-by: Robert Lubos --- .../networking/api/coap_server.rst | 2 +- doc/connectivity/networking/api/net_mgmt.rst | 6 +- drivers/modem/modem_cellular.c | 2 +- drivers/wifi/esp32/src/esp_wifi_drv.c | 2 +- include/zephyr/net/coap_mgmt.h | 20 +- include/zephyr/net/conn_mgr_connectivity.h | 14 +- include/zephyr/net/ethernet_mgmt.h | 20 +- include/zephyr/net/ieee802154_mgmt.h | 11 +- include/zephyr/net/net_event.h | 245 ++++++++++++------ include/zephyr/net/net_mgmt.h | 85 +++--- include/zephyr/net/ppp.h | 20 +- include/zephyr/net/socket_net_mgmt.h | 2 +- include/zephyr/net/wifi_mgmt.h | 63 +++-- modules/hostap/src/supp_events.h | 27 +- modules/hostap/src/supp_main.c | 4 +- samples/boards/nxp/s32/netc/src/main.c | 2 +- samples/net/capture/src/main.c | 4 +- samples/net/cloud/mqtt_azure/src/main.c | 2 +- samples/net/cloud/tagoio_http_post/src/wifi.c | 2 +- samples/net/common/net_sample_common.c | 2 +- samples/net/dhcpv4_client/src/main.c | 2 +- samples/net/dns_resolve/src/main.c | 2 +- samples/net/dsa/src/main.c | 2 +- samples/net/ipv4_autoconf/src/main.c | 2 +- samples/net/lwm2m_client/src/lwm2m-client.c | 4 +- samples/net/mqtt_sn_publisher/src/main.c | 2 +- .../secure_mqtt_sensor_actuator/src/main.c | 2 +- samples/net/sockets/coap_download/src/main.c | 2 +- samples/net/sockets/coap_server/src/events.c | 2 +- .../sockets/dumb_http_server_mt/src/main.c | 2 +- .../net/sockets/echo_client/src/echo-client.c | 4 +- .../net/sockets/echo_server/src/echo-server.c | 2 +- samples/net/sockets/packet/src/packet.c | 2 +- samples/net/sockets/txtime/src/main.c | 2 +- samples/net/wifi/apsta_mode/src/main.c | 2 +- samples/subsys/mgmt/updatehub/src/main.c | 2 +- subsys/logging/backends/log_backend_net.c | 2 +- subsys/mgmt/mcumgr/transport/src/smp_udp.c | 2 +- subsys/net/conn_mgr/conn_mgr_connectivity.c | 4 +- subsys/net/conn_mgr/events_handler.c | 16 +- subsys/net/ip/ipv4_autoconf.c | 2 +- subsys/net/ip/ipv6_pe.c | 2 +- subsys/net/ip/net_mgmt.c | 36 +-- subsys/net/ip/net_stats.c | 2 +- subsys/net/ip/pmtu.c | 1 - subsys/net/l2/ethernet/arp.c | 4 +- subsys/net/l2/ethernet/ethernet_mgmt.c | 4 +- subsys/net/l2/ethernet/ethernet_stats.c | 2 +- subsys/net/l2/ethernet/lldp/lldp.c | 4 +- subsys/net/l2/ieee802154/ieee802154_mgmt.c | 18 +- subsys/net/l2/ieee802154/ieee802154_shell.c | 4 +- subsys/net/l2/openthread/openthread.c | 2 +- subsys/net/l2/ppp/ppp_l2.c | 2 +- subsys/net/l2/virtual/virtual_mgmt.c | 4 +- subsys/net/l2/wifi/wifi_mgmt.c | 66 ++--- subsys/net/l2/wifi/wifi_shell.c | 4 +- subsys/net/lib/coap/coap.c | 2 +- subsys/net/lib/coap/coap_server.c | 2 +- subsys/net/lib/config/init.c | 26 +- subsys/net/lib/config/init_clock_sntp.c | 2 +- subsys/net/lib/dhcpv4/dhcpv4.c | 4 +- subsys/net/lib/dhcpv6/dhcpv6.c | 2 +- subsys/net/lib/dns/llmnr_responder.c | 2 +- subsys/net/lib/dns/mdns_responder.c | 8 +- subsys/net/lib/ptp/port.c | 2 +- subsys/net/lib/shell/events.c | 6 +- subsys/net/lib/sockets/sockets_net_mgmt.c | 4 +- subsys/shell/backends/shell_mqtt.c | 2 +- tests/boards/espressif/ethernet/src/main.c | 2 +- tests/boards/espressif/wifi/src/main.c | 2 +- tests/net/conn_mgr_conn/src/main.c | 2 +- tests/net/conn_mgr_monitor/src/main.c | 18 +- tests/net/conn_mgr_nsos/src/main.c | 2 +- tests/net/dhcpv4/client/prj.conf | 3 + tests/net/dhcpv4/client/src/main.c | 4 +- tests/net/dhcpv6/src/main.c | 2 +- tests/net/hostname/src/main.c | 2 +- .../ieee802154/l2/src/ieee802154_shell_test.c | 2 +- tests/net/igmp/src/main.c | 6 +- tests/net/lib/dns_addremove/src/main.c | 2 +- tests/net/mgmt/src/mgmt.c | 43 +-- tests/net/mld/src/main.c | 6 +- tests/net/pmtu/src/main.c | 6 +- 83 files changed, 546 insertions(+), 370 deletions(-) diff --git a/doc/connectivity/networking/api/coap_server.rst b/doc/connectivity/networking/api/coap_server.rst index a2d0d1b77c1..91ae5ecde47 100644 --- a/doc/connectivity/networking/api/coap_server.rst +++ b/doc/connectivity/networking/api/coap_server.rst @@ -243,7 +243,7 @@ following example simply prints when an event occurs. #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 coap_event_handler(uint64_t mgmt_event, struct net_if *iface, void *info, size_t info_length, void *user_data) { switch (mgmt_event) { diff --git a/doc/connectivity/networking/api/net_mgmt.rst b/doc/connectivity/networking/api/net_mgmt.rst index 2973ee82b04..7c47a63eee2 100644 --- a/doc/connectivity/networking/api/net_mgmt.rst +++ b/doc/connectivity/networking/api/net_mgmt.rst @@ -97,7 +97,7 @@ An example follows. struct net_mgmt_event_callback ipv4_callback; void callback_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { if (mgmt_event == NET_EVENT_IF_xxx) { @@ -139,7 +139,7 @@ Or similarly using :c:macro:`NET_MGMT_REGISTER_EVENT_HANDLER`. #define EVENT_IFACE_SET (NET_EVENT_IF_xxx | NET_EVENT_IF_yyy) #define EVENT_IPV4_SET (NET_EVENT_IPV4_xxx | NET_EVENT_IPV4_yyy) - static void event_handler(uint32_t mgmt_event, struct net_if *iface, + static void event_handler(uint64_t mgmt_event, struct net_if *iface, void *info, size_t info_length, void *user_data) { @@ -183,7 +183,7 @@ You define your handler modeled with this signature: .. code-block:: c - static int your_handler(uint32_t mgmt_event, struct net_if *iface, + static int your_handler(uint64_t mgmt_event, struct net_if *iface, void *data, size_t len); and then register it with an associated mgmt_request code: diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 1c00525b7d8..8eb87fd3608 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -1774,7 +1774,7 @@ static int modem_cellular_pm_action(const struct device *dev, enum pm_device_act } #endif /* CONFIG_PM_DEVICE */ -static void net_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void net_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { struct modem_cellular_data *data = diff --git a/drivers/wifi/esp32/src/esp_wifi_drv.c b/drivers/wifi/esp32/src/esp_wifi_drv.c index 305994d6a32..72c4c512717 100644 --- a/drivers/wifi/esp32/src/esp_wifi_drv.c +++ b/drivers/wifi/esp32/src/esp_wifi_drv.c @@ -77,7 +77,7 @@ struct esp32_wifi_runtime { static struct net_mgmt_event_callback esp32_dhcp_cb; -static void wifi_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void wifi_event_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { switch (mgmt_event) { diff --git a/include/zephyr/net/coap_mgmt.h b/include/zephyr/net/coap_mgmt.h index 961ca18d1ab..0cc25a9cb18 100644 --- a/include/zephyr/net/coap_mgmt.h +++ b/include/zephyr/net/coap_mgmt.h @@ -40,13 +40,25 @@ struct coap_service; struct coap_resource; struct coap_observer; +enum { + NET_EVENT_COAP_CMD_SERVICE_STARTED_VAL, + NET_EVENT_COAP_CMD_SERVICE_STOPPED_VAL, + NET_EVENT_COAP_CMD_OBSERVER_ADDED_VAL, + NET_EVENT_COAP_CMD_OBSERVER_REMOVED_VAL, + + NET_EVENT_COAP_CMD_MAX +}; + +BUILD_ASSERT(NET_EVENT_COAP_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_coap_cmd exceeds the limit"); + enum net_event_coap_cmd { /* Service events */ - NET_EVENT_COAP_CMD_SERVICE_STARTED = 1, - NET_EVENT_COAP_CMD_SERVICE_STOPPED, + NET_MGMT_CMD(NET_EVENT_COAP_CMD_SERVICE_STARTED), + NET_MGMT_CMD(NET_EVENT_COAP_CMD_SERVICE_STOPPED), /* Observer events */ - NET_EVENT_COAP_CMD_OBSERVER_ADDED, - NET_EVENT_COAP_CMD_OBSERVER_REMOVED, + NET_MGMT_CMD(NET_EVENT_COAP_CMD_OBSERVER_ADDED), + NET_MGMT_CMD(NET_EVENT_COAP_CMD_OBSERVER_REMOVED), }; /** @endcond */ diff --git a/include/zephyr/net/conn_mgr_connectivity.h b/include/zephyr/net/conn_mgr_connectivity.h index d1b0ea8106a..cb0f63fcfac 100644 --- a/include/zephyr/net/conn_mgr_connectivity.h +++ b/include/zephyr/net/conn_mgr_connectivity.h @@ -41,9 +41,19 @@ extern "C" { NET_MGMT_EVENT_BIT) #define NET_MGMT_CONN_IF_EVENT (NET_MGMT_IFACE_BIT | NET_MGMT_CONN_BASE) +enum { + NET_EVENT_CONN_CMD_IF_TIMEOUT_VAL, + NET_EVENT_CONN_CMD_IF_FATAL_ERROR_VAL, + + NET_EVENT_CONN_CMD_MAX +}; + +BUILD_ASSERT(NET_EVENT_CONN_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_conn_cmd exceeds the limit"); + enum net_event_conn_cmd { - NET_EVENT_CONN_CMD_IF_TIMEOUT = 1, - NET_EVENT_CONN_CMD_IF_FATAL_ERROR, + NET_MGMT_CMD(NET_EVENT_CONN_CMD_IF_TIMEOUT), + NET_MGMT_CMD(NET_EVENT_CONN_CMD_IF_FATAL_ERROR), }; /** @endcond */ diff --git a/include/zephyr/net/ethernet_mgmt.h b/include/zephyr/net/ethernet_mgmt.h index 750e899da20..79306e9195a 100644 --- a/include/zephyr/net/ethernet_mgmt.h +++ b/include/zephyr/net/ethernet_mgmt.h @@ -188,11 +188,23 @@ struct ethernet_req_params { }; }; +enum { + NET_EVENT_ETHERNET_CMD_CARRIER_ON_VAL, + NET_EVENT_ETHERNET_CMD_CARRIER_OFF_VAL, + NET_EVENT_ETHERNET_CMD_VLAN_TAG_ENABLED_VAL, + NET_EVENT_ETHERNET_CMD_VLAN_TAG_DISABLED_VAL, + + NET_EVENT_ETHERNET_CMD_MAX +}; + +BUILD_ASSERT(NET_EVENT_ETHERNET_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_ethernet_cmd exceeds the limit"); + enum net_event_ethernet_cmd { - NET_EVENT_ETHERNET_CMD_CARRIER_ON = 1, - NET_EVENT_ETHERNET_CMD_CARRIER_OFF, - NET_EVENT_ETHERNET_CMD_VLAN_TAG_ENABLED, - NET_EVENT_ETHERNET_CMD_VLAN_TAG_DISABLED, + NET_MGMT_CMD(NET_EVENT_ETHERNET_CMD_CARRIER_ON), + NET_MGMT_CMD(NET_EVENT_ETHERNET_CMD_CARRIER_OFF), + NET_MGMT_CMD(NET_EVENT_ETHERNET_CMD_VLAN_TAG_ENABLED), + NET_MGMT_CMD(NET_EVENT_ETHERNET_CMD_VLAN_TAG_DISABLED), }; #define NET_EVENT_ETHERNET_CARRIER_ON \ diff --git a/include/zephyr/net/ieee802154_mgmt.h b/include/zephyr/net/ieee802154_mgmt.h index bf20b49b720..970f8a89a9c 100644 --- a/include/zephyr/net/ieee802154_mgmt.h +++ b/include/zephyr/net/ieee802154_mgmt.h @@ -255,8 +255,17 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_GET_SECURITY_SETTINGS); * @cond INTERNAL_HIDDEN */ +enum { + NET_EVENT_IEEE802154_CMD_SCAN_RESULT_VAL, + + NET_EVENT_IEEE802154_CMD_MAX +}; + +BUILD_ASSERT(NET_EVENT_IEEE802154_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_ieee802154_cmd exceeds the limit"); + enum net_event_ieee802154_cmd { - NET_EVENT_IEEE802154_CMD_SCAN_RESULT = 1, + NET_MGMT_CMD(NET_EVENT_IEEE802154_CMD_SCAN_RESULT), }; /** diff --git a/include/zephyr/net/net_event.h b/include/zephyr/net/net_event.h index 0b8c995cd3e..3a948ca5ef9 100644 --- a/include/zephyr/net/net_event.h +++ b/include/zephyr/net/net_event.h @@ -34,11 +34,23 @@ extern "C" { NET_MGMT_LAYER(NET_IF_LAYER) | \ NET_MGMT_LAYER_CODE(NET_IF_CORE_CODE)) +enum { + NET_EVENT_IF_CMD_DOWN_VAL, + NET_EVENT_IF_CMD_UP_VAL, + NET_EVENT_IF_CMD_ADMIN_DOWN_VAL, + NET_EVENT_IF_CMD_ADMIN_UP_VAL, + + NET_EVENT_IF_CMD_MAX +}; + +BUILD_ASSERT(NET_EVENT_IF_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_if_cmd exceeds the limit"); + enum net_event_if_cmd { - NET_EVENT_IF_CMD_DOWN = 1, - NET_EVENT_IF_CMD_UP, - NET_EVENT_IF_CMD_ADMIN_DOWN, - NET_EVENT_IF_CMD_ADMIN_UP, + NET_MGMT_CMD(NET_EVENT_IF_CMD_DOWN), + NET_MGMT_CMD(NET_EVENT_IF_CMD_UP), + NET_MGMT_CMD(NET_EVENT_IF_CMD_ADMIN_DOWN), + NET_MGMT_CMD(NET_EVENT_IF_CMD_ADMIN_UP), }; /* IPv6 Events */ @@ -49,32 +61,65 @@ enum net_event_if_cmd { NET_MGMT_LAYER(NET_IPV6_LAYER) | \ NET_MGMT_LAYER_CODE(NET_IPV6_CORE_CODE)) +enum { + NET_EVENT_IPV6_CMD_ADDR_ADD_VAL, + NET_EVENT_IPV6_CMD_ADDR_DEL_VAL, + NET_EVENT_IPV6_CMD_MADDR_ADD_VAL, + NET_EVENT_IPV6_CMD_MADDR_DEL_VAL, + NET_EVENT_IPV6_CMD_PREFIX_ADD_VAL, + NET_EVENT_IPV6_CMD_PREFIX_DEL_VAL, + NET_EVENT_IPV6_CMD_MCAST_JOIN_VAL, + NET_EVENT_IPV6_CMD_MCAST_LEAVE_VAL, + NET_EVENT_IPV6_CMD_ROUTER_ADD_VAL, + NET_EVENT_IPV6_CMD_ROUTER_DEL_VAL, + NET_EVENT_IPV6_CMD_ROUTE_ADD_VAL, + NET_EVENT_IPV6_CMD_ROUTE_DEL_VAL, + NET_EVENT_IPV6_CMD_DAD_SUCCEED_VAL, + NET_EVENT_IPV6_CMD_DAD_FAILED_VAL, + NET_EVENT_IPV6_CMD_NBR_ADD_VAL, + NET_EVENT_IPV6_CMD_NBR_DEL_VAL, + NET_EVENT_IPV6_CMD_DHCP_START_VAL, + NET_EVENT_IPV6_CMD_DHCP_BOUND_VAL, + NET_EVENT_IPV6_CMD_DHCP_STOP_VAL, + NET_EVENT_IPV6_CMD_ADDR_DEPRECATED_VAL, + NET_EVENT_IPV6_CMD_PE_ENABLED_VAL, + NET_EVENT_IPV6_CMD_PE_DISABLED_VAL, + NET_EVENT_IPV6_CMD_PE_FILTER_ADD_VAL, + NET_EVENT_IPV6_CMD_PE_FILTER_DEL_VAL, + NET_EVENT_IPV6_CMD_PMTU_CHANGED_VAL, + + NET_EVENT_IPV6_CMD_MAX +}; + +BUILD_ASSERT(NET_EVENT_IPV6_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_ipv6_cmd exceeds the limit"); + enum net_event_ipv6_cmd { - NET_EVENT_IPV6_CMD_ADDR_ADD = 1, - NET_EVENT_IPV6_CMD_ADDR_DEL, - NET_EVENT_IPV6_CMD_MADDR_ADD, - NET_EVENT_IPV6_CMD_MADDR_DEL, - NET_EVENT_IPV6_CMD_PREFIX_ADD, - NET_EVENT_IPV6_CMD_PREFIX_DEL, - NET_EVENT_IPV6_CMD_MCAST_JOIN, - NET_EVENT_IPV6_CMD_MCAST_LEAVE, - NET_EVENT_IPV6_CMD_ROUTER_ADD, - NET_EVENT_IPV6_CMD_ROUTER_DEL, - NET_EVENT_IPV6_CMD_ROUTE_ADD, - NET_EVENT_IPV6_CMD_ROUTE_DEL, - NET_EVENT_IPV6_CMD_DAD_SUCCEED, - 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, - NET_EVENT_IPV6_CMD_ADDR_DEPRECATED, - NET_EVENT_IPV6_CMD_PE_ENABLED, - NET_EVENT_IPV6_CMD_PE_DISABLED, - NET_EVENT_IPV6_CMD_PE_FILTER_ADD, - NET_EVENT_IPV6_CMD_PE_FILTER_DEL, - NET_EVENT_IPV6_CMD_PMTU_CHANGED, + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_ADDR_ADD), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_ADDR_DEL), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_MADDR_ADD), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_MADDR_DEL), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_PREFIX_ADD), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_PREFIX_DEL), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_MCAST_JOIN), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_MCAST_LEAVE), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_ROUTER_ADD), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_ROUTER_DEL), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_ROUTE_ADD), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_ROUTE_DEL), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_DAD_SUCCEED), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_DAD_FAILED), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_NBR_ADD), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_NBR_DEL), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_DHCP_START), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_DHCP_BOUND), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_DHCP_STOP), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_ADDR_DEPRECATED), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_PE_ENABLED), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_PE_DISABLED), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_PE_FILTER_ADD), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_PE_FILTER_DEL), + NET_MGMT_CMD(NET_EVENT_IPV6_CMD_PMTU_CHANGED), }; /* IPv4 Events*/ @@ -85,22 +130,45 @@ enum net_event_ipv6_cmd { NET_MGMT_LAYER(NET_IPV4_LAYER) | \ NET_MGMT_LAYER_CODE(NET_IPV4_CORE_CODE)) +enum { + NET_EVENT_IPV4_CMD_ADDR_ADD_VAL, + NET_EVENT_IPV4_CMD_ADDR_DEL_VAL, + NET_EVENT_IPV4_CMD_MADDR_ADD_VAL, + NET_EVENT_IPV4_CMD_MADDR_DEL_VAL, + NET_EVENT_IPV4_CMD_ROUTER_ADD_VAL, + NET_EVENT_IPV4_CMD_ROUTER_DEL_VAL, + NET_EVENT_IPV4_CMD_DHCP_START_VAL, + NET_EVENT_IPV4_CMD_DHCP_BOUND_VAL, + NET_EVENT_IPV4_CMD_DHCP_STOP_VAL, + NET_EVENT_IPV4_CMD_MCAST_JOIN_VAL, + NET_EVENT_IPV4_CMD_MCAST_LEAVE_VAL, + NET_EVENT_IPV4_CMD_ACD_SUCCEED_VAL, + NET_EVENT_IPV4_CMD_ACD_FAILED_VAL, + NET_EVENT_IPV4_CMD_ACD_CONFLICT_VAL, + NET_EVENT_IPV4_CMD_PMTU_CHANGED_VAL, + + NET_EVENT_IPV4_CMD_MAX +}; + +BUILD_ASSERT(NET_EVENT_IPV4_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_ipv4_cmd exceeds the limit"); + enum net_event_ipv4_cmd { - NET_EVENT_IPV4_CMD_ADDR_ADD = 1, - NET_EVENT_IPV4_CMD_ADDR_DEL, - NET_EVENT_IPV4_CMD_MADDR_ADD, - NET_EVENT_IPV4_CMD_MADDR_DEL, - NET_EVENT_IPV4_CMD_ROUTER_ADD, - NET_EVENT_IPV4_CMD_ROUTER_DEL, - NET_EVENT_IPV4_CMD_DHCP_START, - NET_EVENT_IPV4_CMD_DHCP_BOUND, - NET_EVENT_IPV4_CMD_DHCP_STOP, - NET_EVENT_IPV4_CMD_MCAST_JOIN, - NET_EVENT_IPV4_CMD_MCAST_LEAVE, - NET_EVENT_IPV4_CMD_ACD_SUCCEED, - NET_EVENT_IPV4_CMD_ACD_FAILED, - NET_EVENT_IPV4_CMD_ACD_CONFLICT, - NET_EVENT_IPV4_CMD_PMTU_CHANGED, + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_ADDR_ADD), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_ADDR_DEL), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_MADDR_ADD), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_MADDR_DEL), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_ROUTER_ADD), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_ROUTER_DEL), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_DHCP_START), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_DHCP_BOUND), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_DHCP_STOP), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_MCAST_JOIN), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_MCAST_LEAVE), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_ACD_SUCCEED), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_ACD_FAILED), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_ACD_CONFLICT), + NET_MGMT_CMD(NET_EVENT_IPV4_CMD_PMTU_CHANGED), }; /* L4 network events */ @@ -111,22 +179,45 @@ enum net_event_ipv4_cmd { NET_MGMT_LAYER(NET_L4_LAYER) | \ NET_MGMT_LAYER_CODE(NET_L4_CORE_CODE)) +enum { + NET_EVENT_L4_CMD_CONNECTED_VAL, + NET_EVENT_L4_CMD_DISCONNECTED_VAL, + NET_EVENT_L4_CMD_IPV4_CONNECTED_VAL, + NET_EVENT_L4_CMD_IPV4_DISCONNECTED_VAL, + NET_EVENT_L4_CMD_IPV6_CONNECTED_VAL, + NET_EVENT_L4_CMD_IPV6_DISCONNECTED_VAL, + NET_EVENT_L4_CMD_DNS_SERVER_ADD_VAL, + NET_EVENT_L4_CMD_DNS_SERVER_DEL_VAL, + NET_EVENT_L4_CMD_HOSTNAME_CHANGED_VAL, + NET_EVENT_L4_CMD_CAPTURE_STARTED_VAL, + NET_EVENT_L4_CMD_CAPTURE_STOPPED_VAL, + NET_EVENT_L4_CMD_VPN_CONNECTED_VAL, + NET_EVENT_L4_CMD_VPN_DISCONNECTED_VAL, + NET_EVENT_L4_CMD_VPN_PEER_ADD_VAL, + NET_EVENT_L4_CMD_VPN_PEER_DEL_VAL, + + NET_EVENT_L4_CMD_MAX +}; + +BUILD_ASSERT(NET_EVENT_L4_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_l4_cmd exceeds the limit"); + enum net_event_l4_cmd { - NET_EVENT_L4_CMD_CONNECTED = 1, - NET_EVENT_L4_CMD_DISCONNECTED, - NET_EVENT_L4_CMD_IPV4_CONNECTED, - NET_EVENT_L4_CMD_IPV4_DISCONNECTED, - NET_EVENT_L4_CMD_IPV6_CONNECTED, - NET_EVENT_L4_CMD_IPV6_DISCONNECTED, - NET_EVENT_L4_CMD_DNS_SERVER_ADD, - NET_EVENT_L4_CMD_DNS_SERVER_DEL, - NET_EVENT_L4_CMD_HOSTNAME_CHANGED, - NET_EVENT_L4_CMD_CAPTURE_STARTED, - NET_EVENT_L4_CMD_CAPTURE_STOPPED, - NET_EVENT_L4_CMD_VPN_CONNECTED, - NET_EVENT_L4_CMD_VPN_DISCONNECTED, - NET_EVENT_L4_CMD_VPN_PEER_ADD, - NET_EVENT_L4_CMD_VPN_PEER_DEL, + NET_MGMT_CMD(NET_EVENT_L4_CMD_CONNECTED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_DISCONNECTED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_IPV4_CONNECTED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_IPV4_DISCONNECTED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_IPV6_CONNECTED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_IPV6_DISCONNECTED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_DNS_SERVER_ADD), + NET_MGMT_CMD(NET_EVENT_L4_CMD_DNS_SERVER_DEL), + NET_MGMT_CMD(NET_EVENT_L4_CMD_HOSTNAME_CHANGED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_CAPTURE_STARTED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_CAPTURE_STOPPED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_VPN_CONNECTED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_VPN_DISCONNECTED), + NET_MGMT_CMD(NET_EVENT_L4_CMD_VPN_PEER_ADD), + NET_MGMT_CMD(NET_EVENT_L4_CMD_VPN_PEER_DEL), }; /** @endcond */ @@ -153,11 +244,11 @@ enum net_event_l4_cmd { /** Event emitted when an IPv6 address is removed from the system. */ #define NET_EVENT_IPV6_ADDR_DEL \ - (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ADDR_DEL) + (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ADDR_DEL) /** Event emitted when an IPv6 multicast address is added to the system. */ #define NET_EVENT_IPV6_MADDR_ADD \ - (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MADDR_ADD) + (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MADDR_ADD) /** Event emitted when an IPv6 multicast address is removed from the system. */ #define NET_EVENT_IPV6_MADDR_DEL \ @@ -165,19 +256,19 @@ enum net_event_l4_cmd { /** Event emitted when an IPv6 prefix is added to the system. */ #define NET_EVENT_IPV6_PREFIX_ADD \ - (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_PREFIX_ADD) + (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_PREFIX_ADD) /** Event emitted when an IPv6 prefix is removed from the system. */ #define NET_EVENT_IPV6_PREFIX_DEL \ - (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_PREFIX_DEL) + (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_PREFIX_DEL) /** Event emitted when an IPv6 multicast group is joined. */ #define NET_EVENT_IPV6_MCAST_JOIN \ - (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MCAST_JOIN) + (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MCAST_JOIN) /** Event emitted when an IPv6 multicast group is left. */ #define NET_EVENT_IPV6_MCAST_LEAVE \ - (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MCAST_LEAVE) + (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MCAST_LEAVE) /** Event emitted when an IPv6 router is added to the system. */ #define NET_EVENT_IPV6_ROUTER_ADD \ @@ -213,15 +304,15 @@ enum net_event_l4_cmd { /** Event emitted when an IPv6 DHCP client starts. */ #define NET_EVENT_IPV6_DHCP_START \ - (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DHCP_START) + (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DHCP_START) /** Event emitted when an IPv6 DHCP client address is bound. */ #define NET_EVENT_IPV6_DHCP_BOUND \ - (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DHCP_BOUND) + (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DHCP_BOUND) /** Event emitted when an IPv6 DHCP client is stopped. */ #define NET_EVENT_IPV6_DHCP_STOP \ - (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DHCP_STOP) + (NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DHCP_STOP) /** IPv6 address is deprecated. */ #define NET_EVENT_IPV6_ADDR_DEPRECATED \ @@ -253,11 +344,11 @@ enum net_event_l4_cmd { /** Event emitted when an IPv4 address is removed from the system. */ #define NET_EVENT_IPV4_ADDR_DEL \ - (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ADDR_DEL) + (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ADDR_DEL) /** Event emitted when an IPv4 multicast address is added to the system. */ #define NET_EVENT_IPV4_MADDR_ADD \ - (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MADDR_ADD) + (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MADDR_ADD) /** Event emitted when an IPv4 multicast address is removed from the system. */ #define NET_EVENT_IPV4_MADDR_DEL \ @@ -265,31 +356,31 @@ enum net_event_l4_cmd { /** Event emitted when an IPv4 router is added to the system. */ #define NET_EVENT_IPV4_ROUTER_ADD \ - (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ROUTER_ADD) + (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ROUTER_ADD) /** Event emitted when an IPv4 router is removed from the system. */ #define NET_EVENT_IPV4_ROUTER_DEL \ - (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ROUTER_DEL) + (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ROUTER_DEL) /** Event emitted when an IPv4 DHCP client is started. */ #define NET_EVENT_IPV4_DHCP_START \ - (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_DHCP_START) + (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_DHCP_START) /** Event emitted when an IPv4 DHCP client address is bound. */ #define NET_EVENT_IPV4_DHCP_BOUND \ - (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_DHCP_BOUND) + (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_DHCP_BOUND) /** Event emitted when an IPv4 DHCP client is stopped. */ #define NET_EVENT_IPV4_DHCP_STOP \ - (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_DHCP_STOP) + (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_DHCP_STOP) /** Event emitted when an IPv4 multicast group is joined. */ #define NET_EVENT_IPV4_MCAST_JOIN \ - (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MCAST_JOIN) + (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MCAST_JOIN) /** Event emitted when an IPv4 multicast group is left. */ #define NET_EVENT_IPV4_MCAST_LEAVE \ - (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MCAST_LEAVE) + (NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MCAST_LEAVE) /** Event emitted when an IPv4 address conflict detection succeeds. */ #define NET_EVENT_IPV4_ACD_SUCCEED \ diff --git a/include/zephyr/net/net_mgmt.h b/include/zephyr/net/net_mgmt.h index 04e95cbb5ec..9c559b7fd8b 100644 --- a/include/zephyr/net/net_mgmt.h +++ b/include/zephyr/net/net_mgmt.h @@ -14,7 +14,6 @@ #include #include -#include #include #ifdef __cplusplus @@ -36,38 +35,30 @@ struct net_if; /** * @brief NET MGMT event mask basics, normalizing parts of bit fields */ -#define NET_MGMT_EVENT_MASK 0x80000000 -#define NET_MGMT_ON_IFACE_MASK 0x40000000 -#define NET_MGMT_LAYER_MASK 0x30000000 -#define NET_MGMT_SYNC_EVENT_MASK 0x08000000 -#define NET_MGMT_LAYER_CODE_MASK 0x07FF0000 -#define NET_MGMT_COMMAND_MASK 0x0000FFFF - -#define NET_MGMT_EVENT_BIT BIT(31) -#define NET_MGMT_IFACE_BIT BIT(30) -#define NET_MGMT_SYNC_EVENT_BIT BIT(27) - -#define NET_MGMT_LAYER(_layer) (_layer << 28) -#define NET_MGMT_LAYER_CODE(_code) (_code << 16) - -#define NET_MGMT_EVENT(mgmt_request) \ - (mgmt_request & NET_MGMT_EVENT_MASK) +#define NET_MGMT_EVENT_MASK GENMASK64(63, 63) /* 0x8000000000000000 */ +#define NET_MGMT_ON_IFACE_MASK GENMASK64(62, 62) /* 0x4000000000000000 */ +#define NET_MGMT_LAYER_MASK GENMASK64(61, 60) /* 0x3000000000000000 */ +#define NET_MGMT_SYNC_EVENT_MASK GENMASK64(59, 59) /* 0x0800000000000000 */ +#define NET_MGMT_LAYER_CODE_MASK GENMASK64(58, 52) /* 0x07F0000000000000 */ +#define NET_MGMT_COMMAND_MASK GENMASK64(51, 0) /* 0x000FFFFFFFFFFFFF */ -#define NET_MGMT_ON_IFACE(mgmt_request) \ - (mgmt_request & NET_MGMT_ON_IFACE_MASK) +#define NET_MGMT_MAX_COMMANDS 52 /* TODO: figure out the value from mask */ -#define NET_MGMT_EVENT_SYNCHRONOUS(mgmt_request) \ - (mgmt_request & NET_MGMT_SYNC_EVENT_MASK) +#define NET_MGMT_EVENT_BIT BIT64(63) +#define NET_MGMT_IFACE_BIT BIT64(62) +#define NET_MGMT_SYNC_EVENT_BIT BIT64(59) -#define NET_MGMT_GET_LAYER(mgmt_request) \ - ((mgmt_request & NET_MGMT_LAYER_MASK) >> 28) +#define NET_MGMT_LAYER(_layer) FIELD_PREP(NET_MGMT_LAYER_MASK, (_layer)) +#define NET_MGMT_LAYER_CODE(_code) FIELD_PREP(NET_MGMT_LAYER_CODE_MASK, (_code)) -#define NET_MGMT_GET_LAYER_CODE(mgmt_request) \ - ((mgmt_request & NET_MGMT_LAYER_CODE_MASK) >> 16) - -#define NET_MGMT_GET_COMMAND(mgmt_request) \ - (mgmt_request & NET_MGMT_COMMAND_MASK) +#define NET_MGMT_EVENT(mgmt_request) FIELD_GET(NET_MGMT_EVENT_MASK, mgmt_request) +#define NET_MGMT_ON_IFACE(mgmt_request) FIELD_GET(NET_MGMT_ON_IFACE_MASK, mgmt_request) +#define NET_MGMT_EVENT_SYNCHRONOUS(mgmt_request) FIELD_GET(NET_MGMT_SYNC_EVENT_MASK, mgmt_request) +#define NET_MGMT_GET_LAYER(mgmt_request) FIELD_GET(NET_MGMT_LAYER_MASK, mgmt_request) +#define NET_MGMT_GET_LAYER_CODE(mgmt_request) FIELD_GET(NET_MGMT_LAYER_CODE_MASK, mgmt_request) +#define NET_MGMT_GET_COMMAND(mgmt_request) FIELD_GET(NET_MGMT_COMMAND_MASK, mgmt_request) +#define NET_MGMT_CMD(cmd) cmd = BIT64(cmd ##_VAL) /* Useful generic definitions */ #define NET_MGMT_LAYER_L2 1 @@ -102,6 +93,8 @@ enum net_mgmt_layer_code { NET_MGMT_LAYER_CODE_RESERVED = 0x7F /**< Reserved layer code for future use */ }; +#include + /** * @typedef net_mgmt_request_handler_t * @brief Signature which all Net MGMT request handler need to follow @@ -113,7 +106,7 @@ enum net_mgmt_layer_code { * NULL otherwise. * @param len Length in byte of the memory pointed by data. */ -typedef int (*net_mgmt_request_handler_t)(uint32_t mgmt_request, +typedef int (*net_mgmt_request_handler_t)(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len); @@ -134,7 +127,7 @@ typedef int (*net_mgmt_request_handler_t)(uint32_t mgmt_request, * @param _mgmt_request Management event identifier */ #define NET_MGMT_DEFINE_REQUEST_HANDLER(_mgmt_request) \ - extern int net_mgmt_##_mgmt_request(uint32_t mgmt_request, \ + extern int net_mgmt_##_mgmt_request(uint64_t mgmt_request, \ struct net_if *iface, \ void *data, size_t len) @@ -158,7 +151,7 @@ struct net_mgmt_event_callback; * if it's an event on an iface. NULL otherwise. */ typedef void (*net_mgmt_event_handler_t)(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface); /** @@ -202,11 +195,11 @@ struct net_mgmt_event_callback { * receive events from multiple layers, one must have multiple * listeners registered, one for each layer being listened. */ - uint32_t event_mask; + uint64_t event_mask; /** Internal place holder when a synchronous event wait is * successfully unlocked on a event. */ - uint32_t raised_event; + uint64_t raised_event; }; }; @@ -221,7 +214,7 @@ struct net_mgmt_event_callback { * @param info_length Length in bytes of the memory pointed by @p info. * @param user_data Data provided by the user to the handler. */ -typedef void (*net_mgmt_event_static_handler_t)(uint32_t mgmt_event, +typedef void (*net_mgmt_event_static_handler_t)(uint64_t mgmt_event, struct net_if *iface, void *info, size_t info_length, void *user_data); @@ -230,7 +223,7 @@ typedef void (*net_mgmt_event_static_handler_t)(uint32_t mgmt_event, /* Structure for event handler registered at compile time */ struct net_mgmt_event_static_handler { - uint32_t event_mask; + uint64_t event_mask; net_mgmt_event_static_handler_t handler; void *user_data; }; @@ -267,7 +260,7 @@ struct net_mgmt_event_static_handler { static inline void net_mgmt_init_event_callback(struct net_mgmt_event_callback *cb, net_mgmt_event_handler_t handler, - uint32_t mgmt_event_mask) + uint64_t mgmt_event_mask) { __ASSERT(cb, "Callback pointer should not be NULL"); __ASSERT(handler, "Handler pointer should not be NULL"); @@ -313,7 +306,7 @@ void net_mgmt_del_event_callback(struct net_mgmt_event_callback *cb); * is not defined. */ #if defined(CONFIG_NET_MGMT_EVENT) -void net_mgmt_event_notify_with_info(uint32_t mgmt_event, struct net_if *iface, +void net_mgmt_event_notify_with_info(uint64_t mgmt_event, struct net_if *iface, const void *info, size_t length); #else #define net_mgmt_event_notify_with_info(...) @@ -326,7 +319,7 @@ void net_mgmt_event_notify_with_info(uint32_t mgmt_event, struct net_if *iface, * based on an iface. NULL otherwise. */ #if defined(CONFIG_NET_MGMT_EVENT) -static inline void net_mgmt_event_notify(uint32_t mgmt_event, +static inline void net_mgmt_event_notify(uint64_t mgmt_event, struct net_if *iface) { net_mgmt_event_notify_with_info(mgmt_event, iface, NULL, 0); @@ -356,15 +349,15 @@ static inline void net_mgmt_event_notify(uint32_t mgmt_event, * actual event. */ #ifdef CONFIG_NET_MGMT_EVENT -int net_mgmt_event_wait(uint32_t mgmt_event_mask, - uint32_t *raised_event, +int net_mgmt_event_wait(uint64_t mgmt_event_mask, + uint64_t *raised_event, struct net_if **iface, const void **info, size_t *info_length, k_timeout_t timeout); #else -static inline int net_mgmt_event_wait(uint32_t mgmt_event_mask, - uint32_t *raised_event, +static inline int net_mgmt_event_wait(uint64_t mgmt_event_mask, + uint64_t *raised_event, struct net_if **iface, const void **info, size_t *info_length, @@ -401,15 +394,15 @@ static inline int net_mgmt_event_wait(uint32_t mgmt_event_mask, */ #ifdef CONFIG_NET_MGMT_EVENT int net_mgmt_event_wait_on_iface(struct net_if *iface, - uint32_t mgmt_event_mask, - uint32_t *raised_event, + uint64_t mgmt_event_mask, + uint64_t *raised_event, const void **info, size_t *info_length, k_timeout_t timeout); #else static inline int net_mgmt_event_wait_on_iface(struct net_if *iface, - uint32_t mgmt_event_mask, - uint32_t *raised_event, + uint64_t mgmt_event_mask, + uint64_t *raised_event, const void **info, size_t *info_length, k_timeout_t timeout) diff --git a/include/zephyr/net/ppp.h b/include/zephyr/net/ppp.h index 7028e4f2d0f..82e02648380 100644 --- a/include/zephyr/net/ppp.h +++ b/include/zephyr/net/ppp.h @@ -574,11 +574,23 @@ void net_ppp_init(struct net_if *iface); NET_MGMT_LAYER_CODE(NET_PPP_CODE)) #define NET_PPP_EVENT (NET_PPP_BASE | NET_MGMT_EVENT_BIT) +enum { + NET_EVENT_PPP_CMD_CARRIER_ON_VAL, + NET_EVENT_PPP_CMD_CARRIER_OFF_VAL, + NET_EVENT_PPP_CMD_PHASE_RUNNING_VAL, + NET_EVENT_PPP_CMD_PHASE_DEAD_VAL, + + NET_EVENT_PPP_CMD_MAX +}; + +BUILD_ASSERT(NET_EVENT_PPP_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_ppp_cmd exceeds the limit"); + enum net_event_ppp_cmd { - NET_EVENT_PPP_CMD_CARRIER_ON = 1, - NET_EVENT_PPP_CMD_CARRIER_OFF, - NET_EVENT_PPP_CMD_PHASE_RUNNING, - NET_EVENT_PPP_CMD_PHASE_DEAD, + NET_MGMT_CMD(NET_EVENT_PPP_CMD_CARRIER_ON), + NET_MGMT_CMD(NET_EVENT_PPP_CMD_CARRIER_OFF), + NET_MGMT_CMD(NET_EVENT_PPP_CMD_PHASE_RUNNING), + NET_MGMT_CMD(NET_EVENT_PPP_CMD_PHASE_DEAD), }; struct net_if; diff --git a/include/zephyr/net/socket_net_mgmt.h b/include/zephyr/net/socket_net_mgmt.h index 8f3c5829ad3..337648d5d18 100644 --- a/include/zephyr/net/socket_net_mgmt.h +++ b/include/zephyr/net/socket_net_mgmt.h @@ -73,7 +73,7 @@ struct sockaddr_nm { uintptr_t nm_pid; /** net_mgmt mask */ - uint32_t nm_mask; + uint64_t nm_mask; }; diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 5477b6a3c0e..2c895afb36d 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -317,44 +317,73 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_START_ROAMING); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_NEIGHBOR_REP_COMPLETE); +/** @cond INTERNAL_HIDDEN */ + +enum { + NET_EVENT_WIFI_CMD_SCAN_RESULT_VAL, + NET_EVENT_WIFI_CMD_SCAN_DONE_VAL, + NET_EVENT_WIFI_CMD_CONNECT_RESULT_VAL, + NET_EVENT_WIFI_CMD_DISCONNECT_RESULT_VAL, + NET_EVENT_WIFI_CMD_IFACE_STATUS_VAL, + NET_EVENT_WIFI_CMD_TWT_VAL, + NET_EVENT_WIFI_CMD_TWT_SLEEP_STATE_VAL, + NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT_VAL, + NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE_VAL, + NET_EVENT_WIFI_CMD_SIGNAL_CHANGE_VAL, + NET_EVENT_WIFI_CMD_NEIGHBOR_REP_RECEIVED_VAL, + NET_EVENT_WIFI_CMD_NEIGHBOR_REP_COMPLETE_VAL, + NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT_VAL, + NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT_VAL, + NET_EVENT_WIFI_CMD_AP_STA_CONNECTED_VAL, + NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED_VAL, + NET_EVENT_WIFI_CMD_SUPPLICANT_VAL, + + NET_EVENT_WIFI_CMD_MAX, +}; + +BUILD_ASSERT(NET_EVENT_WIFI_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_wifi_cmd exceeds the limit"); + +/** @endcond */ + /** @brief Wi-Fi management events */ enum net_event_wifi_cmd { /** Scan results available */ - NET_EVENT_WIFI_CMD_SCAN_RESULT = 1, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_SCAN_RESULT), /** Scan done */ - NET_EVENT_WIFI_CMD_SCAN_DONE, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_SCAN_DONE), /** Connect result */ - NET_EVENT_WIFI_CMD_CONNECT_RESULT, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_CONNECT_RESULT), /** Disconnect result */ - NET_EVENT_WIFI_CMD_DISCONNECT_RESULT, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_DISCONNECT_RESULT), /** Interface status */ - NET_EVENT_WIFI_CMD_IFACE_STATUS, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_IFACE_STATUS), /** TWT events */ - NET_EVENT_WIFI_CMD_TWT, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_TWT), /** TWT sleep status: awake or sleeping, can be used by application * to determine if it can send data or not. */ - NET_EVENT_WIFI_CMD_TWT_SLEEP_STATE, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_TWT_SLEEP_STATE), /** Raw scan results available */ - NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT), /** Disconnect complete */ - NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE), /** Signal change event */ - NET_EVENT_WIFI_CMD_SIGNAL_CHANGE, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_SIGNAL_CHANGE), /** Neighbor Report */ - NET_EVENT_WIFI_CMD_NEIGHBOR_REP_RECEIVED, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_NEIGHBOR_REP_RECEIVED), /** Neighbor Report complete */ - NET_EVENT_WIFI_CMD_NEIGHBOR_REP_COMPLETE, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_NEIGHBOR_REP_COMPLETE), /** AP mode enable result */ - NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT), /** AP mode disable result */ - NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT), /** STA connected to AP */ - NET_EVENT_WIFI_CMD_AP_STA_CONNECTED, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_AP_STA_CONNECTED), /** STA disconnected from AP */ - NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED), /** Supplicant specific event */ - NET_EVENT_WIFI_CMD_SUPPLICANT, + NET_MGMT_CMD(NET_EVENT_WIFI_CMD_SUPPLICANT), }; /** Event emitted for Wi-Fi scan result */ diff --git a/modules/hostap/src/supp_events.h b/modules/hostap/src/supp_events.h index 09c30e7a37f..1c74af52849 100644 --- a/modules/hostap/src/supp_events.h +++ b/modules/hostap/src/supp_events.h @@ -17,14 +17,27 @@ NET_MGMT_IFACE_BIT) #define NET_MGMT_SUPPLICANT_EVENT (NET_MGMT_EVENT_BIT | NET_MGMT_SUPPLICANT_BASE) +enum { + NET_EVENT_SUPPLICANT_CMD_READY_VAL, + NET_EVENT_SUPPLICANT_CMD_NOT_READY_VAL, + NET_EVENT_SUPPLICANT_CMD_IFACE_ADDED_VAL, + NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVING_VAL, + NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED_VAL, + NET_EVENT_SUPPLICANT_CMD_INT_EVENT_VAL, + + NET_EVENT_SUPPLICANT_CMD_MAX +}; + +BUILD_ASSERT(NET_EVENT_SUPPLICANT_CMD_MAX <= NET_MGMT_MAX_COMMANDS, + "Number of events in net_event_supplicant_cmd exceeds the limit"); + enum net_event_supplicant_cmd { - NET_EVENT_SUPPLICANT_CMD_READY = 1, - NET_EVENT_SUPPLICANT_CMD_NOT_READY, - NET_EVENT_SUPPLICANT_CMD_IFACE_ADDED, - NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVING, - NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED, - NET_EVENT_SUPPLICANT_CMD_INT_EVENT, - NET_EVENT_WIFI_CMD_MAX + NET_MGMT_CMD(NET_EVENT_SUPPLICANT_CMD_READY), + NET_MGMT_CMD(NET_EVENT_SUPPLICANT_CMD_NOT_READY), + NET_MGMT_CMD(NET_EVENT_SUPPLICANT_CMD_IFACE_ADDED), + NET_MGMT_CMD(NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVING), + NET_MGMT_CMD(NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED), + NET_MGMT_CMD(NET_EVENT_SUPPLICANT_CMD_INT_EVENT), }; #define NET_EVENT_SUPPLICANT_READY \ diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index c2a4866b921..4549ab3160d 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -484,14 +484,14 @@ static void submit_iface_work(struct supplicant_context *ctx, } #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_INF_MON static void interface_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if ((mgmt_event & INTERFACE_EVENT_MASK) != mgmt_event) { return; } if (!is_wanted_interface(iface)) { - LOG_DBG("Ignoring event (0x%02x) from interface %d (%p)", + LOG_DBG("Ignoring event (0x%" PRIx64 ") from interface %d (%p)", mgmt_event, net_if_get_by_iface(iface), iface); return; } diff --git a/samples/boards/nxp/s32/netc/src/main.c b/samples/boards/nxp/s32/netc/src/main.c index 8399a7dd9b5..09e6cea9883 100644 --- a/samples/boards/nxp/s32/netc/src/main.c +++ b/samples/boards/nxp/s32/netc/src/main.c @@ -69,7 +69,7 @@ static int setup_iface(struct net_if *iface, const char *ipv6_addr, } static void iface_up_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if (mgmt_event == NET_EVENT_IF_UP) { k_sem_give(&iface_up); diff --git a/samples/net/capture/src/main.c b/samples/net/capture/src/main.c index 3feafc4eb25..1b68ee30afa 100644 --- a/samples/net/capture/src/main.c +++ b/samples/net/capture/src/main.c @@ -285,7 +285,7 @@ static int init_app(void) #define EVENT_MASK (NET_EVENT_CAPTURE_STARTED | NET_EVENT_CAPTURE_STOPPED) static void event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(iface); ARG_UNUSED(cb); @@ -307,7 +307,7 @@ int main(void) { static struct net_mgmt_event_callback mgmt_cb; struct net_if *iface; - uint32_t event; + uint64_t event; int ret; LOG_INF("Starting network capture sample"); diff --git a/samples/net/cloud/mqtt_azure/src/main.c b/samples/net/cloud/mqtt_azure/src/main.c index 841c1fb7ebe..538461af2d1 100644 --- a/samples/net/cloud/mqtt_azure/src/main.c +++ b/samples/net/cloud/mqtt_azure/src/main.c @@ -487,7 +487,7 @@ static void abort_mqtt_connection(void) } static void l4_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if ((mgmt_event & L4_EVENT_MASK) != mgmt_event) { return; diff --git a/samples/net/cloud/tagoio_http_post/src/wifi.c b/samples/net/cloud/tagoio_http_post/src/wifi.c index f9eb52b7a59..a0cd121d62b 100644 --- a/samples/net/cloud/tagoio_http_post/src/wifi.c +++ b/samples/net/cloud/tagoio_http_post/src/wifi.c @@ -26,7 +26,7 @@ static void handle_wifi_connect_result(struct net_mgmt_event_callback *cb) } static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { switch (mgmt_event) { case NET_EVENT_WIFI_CONNECT_RESULT: diff --git a/samples/net/common/net_sample_common.c b/samples/net/common/net_sample_common.c index e1b91c91122..0b570a64feb 100644 --- a/samples/net/common/net_sample_common.c +++ b/samples/net/common/net_sample_common.c @@ -20,7 +20,7 @@ LOG_MODULE_REGISTER(net_samples_common, LOG_LEVEL_DBG); static struct net_mgmt_event_callback l4_cb; static K_SEM_DEFINE(network_connected, 0, 1); -static void l4_event_handler(struct net_mgmt_event_callback *cb, uint32_t event, +static void l4_event_handler(struct net_mgmt_event_callback *cb, uint64_t event, struct net_if *iface) { switch (event) { diff --git a/samples/net/dhcpv4_client/src/main.c b/samples/net/dhcpv4_client/src/main.c index 00d48949d73..72f7a17f273 100644 --- a/samples/net/dhcpv4_client/src/main.c +++ b/samples/net/dhcpv4_client/src/main.c @@ -38,7 +38,7 @@ static void start_dhcpv4_client(struct net_if *iface, void *user_data) } static void handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { int i = 0; diff --git a/samples/net/dns_resolve/src/main.c b/samples/net/dns_resolve/src/main.c index 23e5645d0b4..5302f569874 100644 --- a/samples/net/dns_resolve/src/main.c +++ b/samples/net/dns_resolve/src/main.c @@ -198,7 +198,7 @@ static void print_dhcpv4_addr(struct net_if *iface, struct net_if_addr *if_addr, } static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { diff --git a/samples/net/dsa/src/main.c b/samples/net/dsa/src/main.c index 16d41af5999..a84b2cef7a9 100644 --- a/samples/net/dsa/src/main.c +++ b/samples/net/dsa/src/main.c @@ -54,7 +54,7 @@ static void dsa_iface_find_cb(struct net_if *iface, void *user_data) static struct net_mgmt_event_callback mgmt_cb; static void event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(iface); ARG_UNUSED(cb); diff --git a/samples/net/ipv4_autoconf/src/main.c b/samples/net/ipv4_autoconf/src/main.c index c4e93105cf7..9dd9fa53bb7 100644 --- a/samples/net/ipv4_autoconf/src/main.c +++ b/samples/net/ipv4_autoconf/src/main.c @@ -25,7 +25,7 @@ LOG_MODULE_REGISTER(net_ipv4_autoconf_sample, LOG_LEVEL_DBG); static struct net_mgmt_event_callback mgmt_cb; static void handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { int i = 0; diff --git a/samples/net/lwm2m_client/src/lwm2m-client.c b/samples/net/lwm2m_client/src/lwm2m-client.c index 9127769ff6b..7c15f84502c 100644 --- a/samples/net/lwm2m_client/src/lwm2m-client.c +++ b/samples/net/lwm2m_client/src/lwm2m-client.c @@ -334,7 +334,7 @@ static void on_net_event_l4_connected(void) } static void l4_event_handler(struct net_mgmt_event_callback *cb, - uint32_t event, + uint64_t event, struct net_if *iface) { switch (event) { @@ -356,7 +356,7 @@ static void l4_event_handler(struct net_mgmt_event_callback *cb, } static void connectivity_event_handler(struct net_mgmt_event_callback *cb, - uint32_t event, + uint64_t event, struct net_if *iface) { if (event == NET_EVENT_CONN_IF_FATAL_ERROR) { diff --git a/samples/net/mqtt_sn_publisher/src/main.c b/samples/net/mqtt_sn_publisher/src/main.c index 65436daea4d..fddeb4c976f 100644 --- a/samples/net/mqtt_sn_publisher/src/main.c +++ b/samples/net/mqtt_sn_publisher/src/main.c @@ -30,7 +30,7 @@ K_SEM_DEFINE(run_app, 0, 1); #define EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED) -static void net_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void net_event_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { if ((mgmt_event & EVENT_MASK) != mgmt_event) { diff --git a/samples/net/secure_mqtt_sensor_actuator/src/main.c b/samples/net/secure_mqtt_sensor_actuator/src/main.c index 64993139e90..9b6872a69cf 100644 --- a/samples/net/secure_mqtt_sensor_actuator/src/main.c +++ b/samples/net/secure_mqtt_sensor_actuator/src/main.c @@ -30,7 +30,7 @@ static struct net_mgmt_event_callback net_l4_mgmt_cb; K_SEM_DEFINE(net_conn_sem, 0, 1); static void net_l4_evt_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { switch (mgmt_event) { case NET_EVENT_L4_CONNECTED: diff --git a/samples/net/sockets/coap_download/src/main.c b/samples/net/sockets/coap_download/src/main.c index bb15551cfba..2e1ee6c59d3 100644 --- a/samples/net/sockets/coap_download/src/main.c +++ b/samples/net/sockets/coap_download/src/main.c @@ -21,7 +21,7 @@ static int64_t start_time; /* This struct contains (potentially large) TX and RX buffers, so allocate statically */ static struct coap_client client = {0}; -static void net_event_handler(uint32_t mgmt_event, struct net_if *iface, void *info, +static void net_event_handler(uint64_t mgmt_event, struct net_if *iface, void *info, size_t info_length, void *user_data) { if (NET_EVENT_L4_CONNECTED == mgmt_event) { diff --git a/samples/net/sockets/coap_server/src/events.c b/samples/net/sockets/coap_server/src/events.c index 3f843fba017..8c621214a7d 100644 --- a/samples/net/sockets/coap_server/src/events.c +++ b/samples/net/sockets/coap_server/src/events.c @@ -13,7 +13,7 @@ LOG_MODULE_DECLARE(net_coap_service_sample); #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 coap_event_handler(uint64_t mgmt_event, struct net_if *iface, void *info, size_t info_length, void *user_data) { ARG_UNUSED(iface); diff --git a/samples/net/sockets/dumb_http_server_mt/src/main.c b/samples/net/sockets/dumb_http_server_mt/src/main.c index ed19fa96833..4c8a1021923 100644 --- a/samples/net/sockets/dumb_http_server_mt/src/main.c +++ b/samples/net/sockets/dumb_http_server_mt/src/main.c @@ -98,7 +98,7 @@ K_THREAD_DEFINE(tcp6_thread_id, STACK_SIZE, NET_EVENT_L4_DISCONNECTED) static void event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if ((mgmt_event & EVENT_MASK) != mgmt_event) { return; diff --git a/samples/net/sockets/echo_client/src/echo-client.c b/samples/net/sockets/echo_client/src/echo-client.c index 3ca9ddc8aa0..9c451b9c3cc 100644 --- a/samples/net/sockets/echo_client/src/echo-client.c +++ b/samples/net/sockets/echo_client/src/echo-client.c @@ -229,7 +229,7 @@ static int check_our_ipv6_sockets(int sock, } static void ipv6_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { static char addr_str[INET6_ADDRSTRLEN]; @@ -297,7 +297,7 @@ static void ipv6_event_handler(struct net_mgmt_event_callback *cb, } static void event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if ((mgmt_event & EVENT_MASK) != mgmt_event) { return; diff --git a/samples/net/sockets/echo_server/src/echo-server.c b/samples/net/sockets/echo_server/src/echo-server.c index fd6bd4f6acf..c4dc98b4004 100644 --- a/samples/net/sockets/echo_server/src/echo-server.c +++ b/samples/net/sockets/echo_server/src/echo-server.c @@ -82,7 +82,7 @@ static void stop_udp_and_tcp(void) } static void event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(iface); ARG_UNUSED(cb); diff --git a/samples/net/sockets/packet/src/packet.c b/samples/net/sockets/packet/src/packet.c index 3b3af25c7ab..e4354254b3e 100644 --- a/samples/net/sockets/packet/src/packet.c +++ b/samples/net/sockets/packet/src/packet.c @@ -229,7 +229,7 @@ static void send_packet(void) } static void iface_up_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if (mgmt_event == NET_EVENT_IF_UP) { k_sem_give(&iface_up); diff --git a/samples/net/sockets/txtime/src/main.c b/samples/net/sockets/txtime/src/main.c index d4bc85a3f2a..870e10f8ff7 100644 --- a/samples/net/sockets/txtime/src/main.c +++ b/samples/net/sockets/txtime/src/main.c @@ -71,7 +71,7 @@ static void quit(void) } static void event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { static bool dhcpv4_done; diff --git a/samples/net/wifi/apsta_mode/src/main.c b/samples/net/wifi/apsta_mode/src/main.c index eb90b1c2104..aa0d0cb28cb 100644 --- a/samples/net/wifi/apsta_mode/src/main.c +++ b/samples/net/wifi/apsta_mode/src/main.c @@ -36,7 +36,7 @@ static struct wifi_connect_req_params sta_config; static struct net_mgmt_event_callback cb; -static void wifi_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void wifi_event_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { switch (mgmt_event) { diff --git a/samples/subsys/mgmt/updatehub/src/main.c b/samples/subsys/mgmt/updatehub/src/main.c index 73d64a1a694..9f9af6ae003 100644 --- a/samples/subsys/mgmt/updatehub/src/main.c +++ b/samples/subsys/mgmt/updatehub/src/main.c @@ -63,7 +63,7 @@ void start_updatehub(void) } static void event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if ((mgmt_event & EVENT_MASK) != mgmt_event) { return; diff --git a/subsys/logging/backends/log_backend_net.c b/subsys/logging/backends/log_backend_net.c index 11f0612724f..b0e3ca5c425 100644 --- a/subsys/logging/backends/log_backend_net.c +++ b/subsys/logging/backends/log_backend_net.c @@ -367,7 +367,7 @@ const struct log_backend *log_backend_net_get(void) } #if defined(CONFIG_LOG_BACKEND_NET_USE_CONNECTION_MANAGER) -static void l4_event_handler(uint32_t mgmt_event, struct net_if *iface, void *info, +static void l4_event_handler(uint64_t mgmt_event, struct net_if *iface, void *info, size_t info_length, void *user_data) { ARG_UNUSED(iface); diff --git a/subsys/mgmt/mcumgr/transport/src/smp_udp.c b/subsys/mgmt/mcumgr/transport/src/smp_udp.c index 8067b36d6e6..e3da22e6731 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp_udp.c +++ b/subsys/mgmt/mcumgr/transport/src/smp_udp.c @@ -280,7 +280,7 @@ static void smp_udp_open_iface(struct net_if *iface, void *user_data) } } -static void smp_udp_net_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void smp_udp_net_event_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(cb); diff --git a/subsys/net/conn_mgr/conn_mgr_connectivity.c b/subsys/net/conn_mgr/conn_mgr_connectivity.c index 5bf8e3f58be..905b5b07d1c 100644 --- a/subsys/net/conn_mgr/conn_mgr_connectivity.c +++ b/subsys/net/conn_mgr/conn_mgr_connectivity.c @@ -315,7 +315,7 @@ static void conn_mgr_conn_handle_iface_down(struct net_if *iface) } static struct net_mgmt_event_callback conn_mgr_conn_iface_cb; -static void conn_mgr_conn_iface_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void conn_mgr_conn_iface_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { if ((mgmt_event & CONN_MGR_CONN_IFACE_EVENTS_MASK) != mgmt_event) { @@ -333,7 +333,7 @@ static void conn_mgr_conn_iface_handler(struct net_mgmt_event_callback *cb, uint } static struct net_mgmt_event_callback conn_mgr_conn_self_cb; -static void conn_mgr_conn_self_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void conn_mgr_conn_self_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { if ((mgmt_event & CONN_MGR_CONN_SELF_EVENTS_MASK) != mgmt_event) { diff --git a/subsys/net/conn_mgr/events_handler.c b/subsys/net/conn_mgr/events_handler.c index 8f15a8b6c62..2a0c6fefc28 100644 --- a/subsys/net/conn_mgr/events_handler.c +++ b/subsys/net/conn_mgr/events_handler.c @@ -19,12 +19,12 @@ static struct net_mgmt_event_callback ipv6_events_cb; static struct net_mgmt_event_callback ipv4_events_cb; static void conn_mgr_iface_events_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { int idx; - NET_DBG("%s event 0x%x received on iface %d (%p)", "Iface", mgmt_event, + NET_DBG("%s event 0x%" PRIx64 " received on iface %d (%p)", "Iface", mgmt_event, net_if_get_by_iface(iface), iface); if ((mgmt_event & CONN_MGR_IFACE_EVENTS_MASK) != mgmt_event) { @@ -55,12 +55,12 @@ static void conn_mgr_iface_events_handler(struct net_mgmt_event_callback *cb, #if defined(CONFIG_NET_IPV6) static void conn_mgr_ipv6_events_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { int idx; - NET_DBG("%s event 0x%x received on iface %d (%p)", "IPv6", mgmt_event, + NET_DBG("%s event 0x%" PRIx64 " received on iface %d (%p)", "IPv6", mgmt_event, net_if_get_by_iface(iface), iface); if ((mgmt_event & CONN_MGR_IPV6_EVENTS_MASK) != mgmt_event) { @@ -101,7 +101,7 @@ static void conn_mgr_ipv6_events_handler(struct net_mgmt_event_callback *cb, #else static inline void conn_mgr_ipv6_events_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(cb); @@ -112,12 +112,12 @@ void conn_mgr_ipv6_events_handler(struct net_mgmt_event_callback *cb, #if defined(CONFIG_NET_IPV4) static void conn_mgr_ipv4_events_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { int idx; - NET_DBG("%s event 0x%x received on iface %d (%p)", "IPv4", mgmt_event, + NET_DBG("%s event 0x%" PRIx64 " received on iface %d (%p)", "IPv4", mgmt_event, net_if_get_by_iface(iface), iface); if ((mgmt_event & CONN_MGR_IPV4_EVENTS_MASK) != mgmt_event) { @@ -159,7 +159,7 @@ static void conn_mgr_ipv4_events_handler(struct net_mgmt_event_callback *cb, #else static inline void conn_mgr_ipv4_events_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(cb); diff --git a/subsys/net/ip/ipv4_autoconf.c b/subsys/net/ip/ipv4_autoconf.c index f08608f3b7e..ad399622a99 100644 --- a/subsys/net/ip/ipv4_autoconf.c +++ b/subsys/net/ip/ipv4_autoconf.c @@ -55,7 +55,7 @@ static inline void ipv4_autoconf_addr_set(struct net_if_ipv4_autoconf *ipv4auto) } static void acd_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { struct net_if_config *cfg; struct in_addr *addr; diff --git a/subsys/net/ip/ipv6_pe.c b/subsys/net/ip/ipv6_pe.c index 4379dc47e7e..bb03683db39 100644 --- a/subsys/net/ip/ipv6_pe.c +++ b/subsys/net/ip/ipv6_pe.c @@ -501,7 +501,7 @@ static void ipv6_pe_recheck_filters(bool is_denylist) #if CONFIG_NET_IPV6_PE_FILTER_PREFIX_COUNT > 0 static void send_filter_event(struct in6_addr *addr, bool is_denylist, - int event_type) + uint64_t event_type) { if (IS_ENABLED(CONFIG_NET_MGMT_EVENT_INFO)) { struct net_event_ipv6_pe_filter info; diff --git a/subsys/net/ip/net_mgmt.c b/subsys/net/ip/net_mgmt.c index 4fbc1a1b599..d48a54e5611 100644 --- a/subsys/net/ip/net_mgmt.c +++ b/subsys/net/ip/net_mgmt.c @@ -27,7 +27,7 @@ struct mgmt_event_entry { #endif /* CONFIG_NET_MGMT_EVENT_QUEUE */ size_t info_length; #endif /* CONFIG_NET_MGMT_EVENT_INFO */ - uint32_t event; + uint64_t event; struct net_if *iface; }; @@ -47,7 +47,7 @@ K_KERNEL_STACK_DEFINE(mgmt_stack, CONFIG_NET_MGMT_EVENT_STACK_SIZE); static struct k_work_q mgmt_work_q_obj; #endif -static uint32_t global_event_mask; +static uint64_t global_event_mask; static sys_slist_t event_callbacks = SYS_SLIST_STATIC_INIT(&event_callbacks); /* Forward declaration for the actual caller */ @@ -67,7 +67,7 @@ static struct k_work_q *mgmt_work_q = COND_CODE_1(CONFIG_NET_MGMT_EVENT_SYSTEM_W static void mgmt_event_work_handler(struct k_work *work); static K_WORK_DEFINE(mgmt_work, mgmt_event_work_handler); -static inline void mgmt_push_event(uint32_t mgmt_event, struct net_if *iface, +static inline void mgmt_push_event(uint64_t mgmt_event, struct net_if *iface, const void *info, size_t length) { #ifndef CONFIG_NET_MGMT_EVENT_INFO @@ -85,7 +85,7 @@ static inline void mgmt_push_event(uint32_t mgmt_event, struct net_if *iface, memcpy(new_event.info, info, length); new_event.info_length = length; } else { - NET_ERR("Event %u info length %zu > max size %zu", + NET_ERR("Event 0x%" PRIx64 " info length %zu > max size %zu", mgmt_event, length, NET_EVENT_INFO_MAX_SIZE); (void)k_mutex_unlock(&net_mgmt_event_lock); @@ -99,7 +99,7 @@ static inline void mgmt_push_event(uint32_t mgmt_event, struct net_if *iface, if (k_msgq_put(&event_msgq, &new_event, K_MSEC(CONFIG_NET_MGMT_EVENT_QUEUE_TIMEOUT)) != 0) { - NET_WARN("Failure to push event (%u), " + NET_WARN("Failure to push event (0x%" PRIx64 "), " "try increasing the 'CONFIG_NET_MGMT_EVENT_QUEUE_SIZE' " "or 'CONFIG_NET_MGMT_EVENT_QUEUE_TIMEOUT' options.", mgmt_event); @@ -128,7 +128,7 @@ static void mgmt_event_work_handler(struct k_work *work) #else -static inline void mgmt_push_event(uint32_t event, struct net_if *iface, +static inline void mgmt_push_event(uint64_t event, struct net_if *iface, const void *info, size_t length) { #ifndef CONFIG_NET_MGMT_EVENT_INFO @@ -149,7 +149,7 @@ static inline void mgmt_push_event(uint32_t event, struct net_if *iface, #endif /* CONFIG_NET_MGMT_EVENT_QUEUE */ -static inline void mgmt_add_event_mask(uint32_t event_mask) +static inline void mgmt_add_event_mask(uint64_t event_mask) { global_event_mask |= event_mask; } @@ -169,7 +169,7 @@ static inline void mgmt_rebuild_global_event_mask(void) } } -static inline bool mgmt_is_event_handled(uint32_t mgmt_event) +static inline bool mgmt_is_event_handled(uint64_t mgmt_event) { return (((NET_MGMT_GET_LAYER(mgmt_event) & NET_MGMT_GET_LAYER(global_event_mask)) == @@ -188,7 +188,7 @@ static inline void mgmt_run_slist_callbacks(const struct mgmt_event_entry * cons struct net_mgmt_event_callback *cb, *tmp; /* Readable layer code is starting from 1, thus the increment */ - NET_DBG("Event layer %u code %u cmd %u", + NET_DBG("Event layer 0x%" PRIx64 " code 0x%" PRIx64 " cmd 0x%" PRIx64, NET_MGMT_GET_LAYER(mgmt_event->event) + 1, NET_MGMT_GET_LAYER_CODE(mgmt_event->event), NET_MGMT_GET_COMMAND(mgmt_event->event)); @@ -283,8 +283,8 @@ static void mgmt_run_callbacks(const struct mgmt_event_entry * const mgmt_event) } static int mgmt_event_wait_call(struct net_if *iface, - uint32_t mgmt_event_mask, - uint32_t *raised_event, + uint64_t mgmt_event_mask, + uint64_t *raised_event, struct net_if **event_iface, const void **info, size_t *info_length, @@ -303,7 +303,7 @@ static int mgmt_event_wait_call(struct net_if *iface, sync_data.iface = iface; } - NET_DBG("Synchronous event 0x%08x wait %p", sync.event_mask, &sync); + NET_DBG("Synchronous event 0x%" PRIx64 " wait %p", sync.event_mask, &sync); net_mgmt_add_event_callback(&sync); @@ -367,12 +367,12 @@ void net_mgmt_del_event_callback(struct net_mgmt_event_callback *cb) (void)k_mutex_unlock(&net_mgmt_callback_lock); } -void net_mgmt_event_notify_with_info(uint32_t mgmt_event, struct net_if *iface, +void net_mgmt_event_notify_with_info(uint64_t mgmt_event, struct net_if *iface, const void *info, size_t length) { if (mgmt_is_event_handled(mgmt_event)) { /* Readable layer code is starting from 1, thus the increment */ - NET_DBG("Notifying Event layer %u code %u type %u", + NET_DBG("Notifying Event layer 0x%" PRIx64 " code 0x%" PRIx64 " type 0x%" PRIx64, NET_MGMT_GET_LAYER(mgmt_event) + 1, NET_MGMT_GET_LAYER_CODE(mgmt_event), NET_MGMT_GET_COMMAND(mgmt_event)); @@ -381,8 +381,8 @@ void net_mgmt_event_notify_with_info(uint32_t mgmt_event, struct net_if *iface, } } -int net_mgmt_event_wait(uint32_t mgmt_event_mask, - uint32_t *raised_event, +int net_mgmt_event_wait(uint64_t mgmt_event_mask, + uint64_t *raised_event, struct net_if **iface, const void **info, size_t *info_length, @@ -394,8 +394,8 @@ int net_mgmt_event_wait(uint32_t mgmt_event_mask, } int net_mgmt_event_wait_on_iface(struct net_if *iface, - uint32_t mgmt_event_mask, - uint32_t *raised_event, + uint64_t mgmt_event_mask, + uint64_t *raised_event, const void **info, size_t *info_length, k_timeout_t timeout) diff --git a/subsys/net/ip/net_stats.c b/subsys/net/ip/net_stats.c index 5da625faeb6..9e7d0bb6fc7 100644 --- a/subsys/net/ip/net_stats.c +++ b/subsys/net/ip/net_stats.c @@ -252,7 +252,7 @@ void net_print_statistics(void) #if defined(CONFIG_NET_STATISTICS_USER_API) -static int net_stats_get(uint32_t mgmt_request, struct net_if *iface, +static int net_stats_get(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { size_t len_chk = 0; diff --git a/subsys/net/ip/pmtu.c b/subsys/net/ip/pmtu.c index be2c3355a6b..cdd09ed0ca8 100644 --- a/subsys/net/ip/pmtu.c +++ b/subsys/net/ip/pmtu.c @@ -12,7 +12,6 @@ LOG_MODULE_REGISTER(net_pmtu, CONFIG_NET_PMTU_LOG_LEVEL); #include -#include #include #include #include "pmtu.h" diff --git a/subsys/net/l2/ethernet/arp.c b/subsys/net/l2/ethernet/arp.c index af816185fe1..d49ab054eaa 100644 --- a/subsys/net/l2/ethernet/arp.c +++ b/subsys/net/l2/ethernet/arp.c @@ -569,7 +569,7 @@ static void notify_all_ipv4_addr(struct net_if *iface) } static void iface_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(cb); @@ -586,7 +586,7 @@ static void iface_event_handler(struct net_mgmt_event_callback *cb, } static void ipv4_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { struct in_addr *ipaddr; diff --git a/subsys/net/l2/ethernet/ethernet_mgmt.c b/subsys/net/l2/ethernet/ethernet_mgmt.c index 3f1b6735318..15efbc4f37c 100644 --- a/subsys/net/l2/ethernet/ethernet_mgmt.c +++ b/subsys/net/l2/ethernet/ethernet_mgmt.c @@ -25,7 +25,7 @@ static inline bool is_hw_caps_supported(const struct device *dev, return ((api->get_capabilities(dev) & caps) != 0); } -static int ethernet_set_config(uint32_t mgmt_request, +static int ethernet_set_config(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { @@ -255,7 +255,7 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_MAC_FILTER, ethernet_set_config); -static int ethernet_get_config(uint32_t mgmt_request, +static int ethernet_get_config(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { diff --git a/subsys/net/l2/ethernet/ethernet_stats.c b/subsys/net/l2/ethernet/ethernet_stats.c index ccbbd53e2f2..57d354623f6 100644 --- a/subsys/net/l2/ethernet/ethernet_stats.c +++ b/subsys/net/l2/ethernet/ethernet_stats.c @@ -17,7 +17,7 @@ LOG_MODULE_REGISTER(net_ethernet_stats, CONFIG_NET_L2_ETHERNET_LOG_LEVEL); #if defined(CONFIG_NET_STATISTICS_USER_API) -static int eth_stats_get(uint32_t mgmt_request, struct net_if *iface, +static int eth_stats_get(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { size_t len_chk = 0; diff --git a/subsys/net/l2/ethernet/lldp/lldp.c b/subsys/net/l2/ethernet/lldp/lldp.c index 2895691d6f0..230e69eb6b8 100644 --- a/subsys/net/l2/ethernet/lldp/lldp.c +++ b/subsys/net/l2/ethernet/lldp/lldp.c @@ -234,7 +234,7 @@ static int lldp_check_iface(struct net_if *iface) return 0; } -static int lldp_start(struct net_if *iface, uint32_t mgmt_event) +static int lldp_start(struct net_if *iface, uint64_t mgmt_event) { struct ethernet_context *ctx; int ret, slot; @@ -328,7 +328,7 @@ int net_lldp_register_callback(struct net_if *iface, net_lldp_recv_cb_t recv_cb) } static void iface_event_handler(struct net_mgmt_event_callback *evt_cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { lldp_start(iface, mgmt_event); } diff --git a/subsys/net/l2/ieee802154/ieee802154_mgmt.c b/subsys/net/l2/ieee802154/ieee802154_mgmt.c index 993bcc12ae9..3c654c375b6 100644 --- a/subsys/net/l2/ieee802154/ieee802154_mgmt.c +++ b/subsys/net/l2/ieee802154/ieee802154_mgmt.c @@ -74,7 +74,7 @@ enum net_verdict ieee802154_handle_beacon(struct net_if *iface, return NET_CONTINUE; } -static int ieee802154_cancel_scan(uint32_t mgmt_request, struct net_if *iface, +static int ieee802154_cancel_scan(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { struct ieee802154_context *ctx = net_if_l2_data(iface); @@ -94,7 +94,7 @@ static int ieee802154_cancel_scan(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_IEEE802154_CANCEL_SCAN, ieee802154_cancel_scan); -static int ieee802154_scan(uint32_t mgmt_request, struct net_if *iface, +static int ieee802154_scan(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct ieee802154_phy_supported_channels *supported_channels; @@ -437,7 +437,7 @@ enum net_verdict ieee802154_handle_mac_command(struct net_if *iface, return NET_DROP; } -static int ieee802154_associate(uint32_t mgmt_request, struct net_if *iface, +static int ieee802154_associate(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { struct ieee802154_context *ctx = net_if_l2_data(iface); @@ -631,7 +631,7 @@ static int ieee802154_associate(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_IEEE802154_ASSOCIATE, ieee802154_associate); -static int ieee802154_disassociate(uint32_t mgmt_request, struct net_if *iface, +static int ieee802154_disassociate(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { struct ieee802154_context *ctx = net_if_l2_data(iface); @@ -706,7 +706,7 @@ static int ieee802154_disassociate(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_IEEE802154_DISASSOCIATE, ieee802154_disassociate); -static int ieee802154_set_ack(uint32_t mgmt_request, struct net_if *iface, +static int ieee802154_set_ack(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { struct ieee802154_context *ctx = net_if_l2_data(iface); @@ -733,7 +733,7 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_ACK, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_IEEE802154_UNSET_ACK, ieee802154_set_ack); -static int ieee802154_set_parameters(uint32_t mgmt_request, +static int ieee802154_set_parameters(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { @@ -851,7 +851,7 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_SHORT_ADDR, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_TX_POWER, ieee802154_set_parameters); -static int ieee802154_get_parameters(uint32_t mgmt_request, +static int ieee802154_get_parameters(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { @@ -914,7 +914,7 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_IEEE802154_GET_TX_POWER, #ifdef CONFIG_NET_L2_IEEE802154_SECURITY -static int ieee802154_set_security_settings(uint32_t mgmt_request, +static int ieee802154_set_security_settings(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { @@ -953,7 +953,7 @@ static int ieee802154_set_security_settings(uint32_t mgmt_request, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_SECURITY_SETTINGS, ieee802154_set_security_settings); -static int ieee802154_get_security_settings(uint32_t mgmt_request, +static int ieee802154_get_security_settings(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { diff --git a/subsys/net/l2/ieee802154/ieee802154_shell.c b/subsys/net/l2/ieee802154/ieee802154_shell.c index 8a4e6ab0b6c..777e7c6e46f 100644 --- a/subsys/net/l2/ieee802154/ieee802154_shell.c +++ b/subsys/net/l2/ieee802154/ieee802154_shell.c @@ -209,7 +209,7 @@ static inline char *print_coordinator_address(char *buf, int buf_len) } static void scan_result_cb(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { char buf[64]; @@ -224,7 +224,7 @@ static int cmd_ieee802154_scan(const struct shell *sh, size_t argc, char *argv[]) { struct net_if *iface = net_if_get_ieee802154(); - uint32_t scan_type; + uint64_t scan_type; int ret = 0; if (argc < 3) { diff --git a/subsys/net/l2/openthread/openthread.c b/subsys/net/l2/openthread/openthread.c index 6ddeadf8dfc..4ed6a34162f 100644 --- a/subsys/net/l2/openthread/openthread.c +++ b/subsys/net/l2/openthread/openthread.c @@ -34,7 +34,7 @@ static struct openthread_state_changed_callback ot_l2_state_changed_cb; #ifdef CONFIG_NET_MGMT_EVENT static struct net_mgmt_event_callback ip6_addr_cb; -static void ipv6_addr_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void ipv6_addr_event_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { if (net_if_l2(iface) != &NET_L2_GET_NAME(OPENTHREAD)) { diff --git a/subsys/net/l2/ppp/ppp_l2.c b/subsys/net/l2/ppp/ppp_l2.c index 5521d76470e..ae573a6e7ce 100644 --- a/subsys/net/l2/ppp/ppp_l2.c +++ b/subsys/net/l2/ppp/ppp_l2.c @@ -474,7 +474,7 @@ static void tx_handler(void *p1, void *p2, void *p3) } } -static void net_ppp_mgmt_evt_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void net_ppp_mgmt_evt_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { struct ppp_context *ctx; diff --git a/subsys/net/l2/virtual/virtual_mgmt.c b/subsys/net/l2/virtual/virtual_mgmt.c index 1210fc59083..c6187e0dd9f 100644 --- a/subsys/net/l2/virtual/virtual_mgmt.c +++ b/subsys/net/l2/virtual/virtual_mgmt.c @@ -13,7 +13,7 @@ LOG_MODULE_REGISTER(net_virtual_mgmt, CONFIG_NET_L2_VIRTUAL_LOG_LEVEL); #include #include -static int virtual_interface_set_config(uint32_t mgmt_request, +static int virtual_interface_set_config(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { @@ -89,7 +89,7 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_VIRTUAL_INTERFACE_SET_LINK_TYPE, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_VIRTUAL_INTERFACE_SET_PRIVATE_KEY, virtual_interface_set_config); -static int virtual_interface_get_config(uint32_t mgmt_request, +static int virtual_interface_get_config(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index dc52c42a5c2..0183faab1d5 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -371,7 +371,7 @@ static const struct wifi_mgmt_ops *const get_wifi_api(struct net_if *iface) return off_api ? off_api->wifi_mgmt_api : NULL; } -static int wifi_connect(uint32_t mgmt_request, struct net_if *iface, +static int wifi_connect(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { struct wifi_connect_req_params *params = @@ -475,7 +475,7 @@ static void scan_result_cb(struct net_if *iface, int status, #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY */ } -static int wifi_scan(uint32_t mgmt_request, struct net_if *iface, +static int wifi_scan(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -504,7 +504,7 @@ static int wifi_scan(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_SCAN, wifi_scan); -static int wifi_disconnect(uint32_t mgmt_request, struct net_if *iface, +static int wifi_disconnect(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -546,7 +546,7 @@ void wifi_mgmt_raise_disconnect_result_event(struct net_if *iface, int status) } #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING -static int wifi_start_roaming(uint32_t mgmt_request, struct net_if *iface, +static int wifi_start_roaming(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -589,7 +589,7 @@ static int wifi_start_roaming(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_START_ROAMING, wifi_start_roaming); -static int wifi_neighbor_rep_complete(uint32_t mgmt_request, struct net_if *iface, +static int wifi_neighbor_rep_complete(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -684,7 +684,7 @@ void wifi_mgmt_raise_neighbor_rep_recv_event(struct net_if *iface, char *inbuf, } #endif -static int wifi_ap_enable(uint32_t mgmt_request, struct net_if *iface, +static int wifi_ap_enable(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { struct wifi_connect_req_params *params = @@ -705,7 +705,7 @@ static int wifi_ap_enable(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_ENABLE, wifi_ap_enable); -static int wifi_ap_disable(uint32_t mgmt_request, struct net_if *iface, +static int wifi_ap_disable(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -724,7 +724,7 @@ 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, +static int wifi_ap_sta_disconnect(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -752,7 +752,7 @@ static int wifi_ap_sta_disconnect(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_STA_DISCONNECT, wifi_ap_sta_disconnect); -static int wifi_ap_config_params(uint32_t mgmt_request, struct net_if *iface, +static int wifi_ap_config_params(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -790,7 +790,7 @@ static int wifi_ap_config_params(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_CONFIG_PARAM, wifi_ap_config_params); -static int wifi_ap_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface, +static int wifi_ap_set_rts_threshold(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -814,7 +814,7 @@ static int wifi_ap_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_RTS_THRESHOLD, wifi_ap_set_rts_threshold); -static int wifi_iface_status(uint32_t mgmt_request, struct net_if *iface, +static int wifi_iface_status(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -842,7 +842,7 @@ void wifi_mgmt_raise_iface_status_event(struct net_if *iface, } #ifdef CONFIG_NET_STATISTICS_WIFI -static int wifi_iface_stats(uint32_t mgmt_request, struct net_if *iface, +static int wifi_iface_stats(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -861,7 +861,7 @@ static int wifi_iface_stats(uint32_t mgmt_request, struct net_if *iface, } NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_GET_WIFI, wifi_iface_stats); -static int wifi_iface_stats_reset(uint32_t mgmt_request, struct net_if *iface, +static int wifi_iface_stats_reset(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -876,7 +876,7 @@ static int wifi_iface_stats_reset(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_RESET_WIFI, wifi_iface_stats_reset); #endif /* CONFIG_NET_STATISTICS_WIFI */ -static int wifi_11k_cfg(uint32_t mgmt_request, struct net_if *iface, +static int wifi_11k_cfg(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -902,7 +902,7 @@ static int wifi_11k_cfg(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_11K_CONFIG, wifi_11k_cfg); -static int wifi_11k_neighbor_request(uint32_t mgmt_request, struct net_if *iface, +static int wifi_11k_neighbor_request(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -923,7 +923,7 @@ static int wifi_11k_neighbor_request(uint32_t mgmt_request, struct net_if *iface NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_11K_NEIGHBOR_REQUEST, wifi_11k_neighbor_request); -static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface, +static int wifi_set_power_save(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -977,7 +977,7 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PS, wifi_set_power_save); -static int wifi_get_power_save_config(uint32_t mgmt_request, struct net_if *iface, +static int wifi_get_power_save_config(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1001,7 +1001,7 @@ static int wifi_get_power_save_config(uint32_t mgmt_request, struct net_if *ifac NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PS_CONFIG, wifi_get_power_save_config); -static int wifi_set_twt(uint32_t mgmt_request, struct net_if *iface, +static int wifi_set_twt(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1068,7 +1068,7 @@ static int wifi_set_twt(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_TWT, wifi_set_twt); -static int wifi_set_btwt(uint32_t mgmt_request, struct net_if *iface, +static int wifi_set_btwt(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1108,7 +1108,7 @@ void wifi_mgmt_raise_twt_event(struct net_if *iface, struct wifi_twt_params *twt sizeof(struct wifi_twt_params)); } -static int wifi_reg_domain(uint32_t mgmt_request, struct net_if *iface, +static int wifi_reg_domain(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1140,7 +1140,7 @@ 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, +static int wifi_mode(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1164,7 +1164,7 @@ static int wifi_mode(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_MODE, wifi_mode); -static int wifi_packet_filter(uint32_t mgmt_request, struct net_if *iface, +static int wifi_packet_filter(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1188,7 +1188,7 @@ static int wifi_packet_filter(uint32_t mgmt_request, struct net_if *iface, 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, +static int wifi_channel(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1212,7 +1212,7 @@ 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, +static int wifi_get_version(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1228,7 +1228,7 @@ static int wifi_get_version(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_VERSION, wifi_get_version); -static int wifi_btm_query(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) +static int wifi_btm_query(uint64_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); @@ -1252,7 +1252,7 @@ static int wifi_btm_query(uint32_t mgmt_request, struct net_if *iface, void *dat NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_BTM_QUERY, wifi_btm_query); -static int wifi_get_connection_params(uint32_t mgmt_request, struct net_if *iface, +static int wifi_get_connection_params(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1272,7 +1272,7 @@ static int wifi_get_connection_params(uint32_t mgmt_request, struct net_if *ifac NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CONN_PARAMS, wifi_get_connection_params); -static int wifi_wps_config(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) +static int wifi_wps_config(uint64_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); @@ -1291,7 +1291,7 @@ static int wifi_wps_config(uint32_t mgmt_request, struct net_if *iface, void *da NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_WPS_CONFIG, wifi_wps_config); -static int wifi_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface, +static int wifi_set_rts_threshold(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1316,7 +1316,7 @@ static int wifi_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD, wifi_set_rts_threshold); #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP -static int wifi_dpp(uint32_t mgmt_request, struct net_if *iface, +static int wifi_dpp(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1338,7 +1338,7 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_DPP, wifi_dpp); #endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */ -static int wifi_pmksa_flush(uint32_t mgmt_request, struct net_if *iface, +static int wifi_pmksa_flush(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1357,7 +1357,7 @@ static int wifi_pmksa_flush(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PMKSA_FLUSH, wifi_pmksa_flush); -static int wifi_get_rts_threshold(uint32_t mgmt_request, struct net_if *iface, +static int wifi_get_rts_threshold(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1382,7 +1382,7 @@ static int wifi_get_rts_threshold(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD_CONFIG, wifi_get_rts_threshold); #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE -static int wifi_set_enterprise_creds(uint32_t mgmt_request, struct net_if *iface, +static int wifi_set_enterprise_creds(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { const struct device *dev = net_if_get_device(iface); @@ -1721,7 +1721,7 @@ static int add_static_network_config(struct net_if *iface) #endif /* defined(CONFIG_WIFI_CREDENTIALS_STATIC) */ } -static int connect_stored_command(uint32_t mgmt_request, struct net_if *iface, void *data, +static int connect_stored_command(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { int ret = 0; diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 07514b53a33..8a5468ba81b 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -518,7 +518,7 @@ static void handle_wifi_neighbor_rep_complete(struct net_mgmt_event_callback *cb #endif static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { switch (mgmt_event) { case NET_EVENT_WIFI_CONNECT_RESULT: @@ -556,7 +556,7 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, } static void wifi_mgmt_scan_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { switch (mgmt_event) { case NET_EVENT_WIFI_SCAN_RESULT: diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index b1d00a46f1d..4ba5f4d309e 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -1956,7 +1956,7 @@ void coap_observer_init(struct coap_observer *observer, static inline void coap_observer_raise_event(struct coap_resource *resource, struct coap_observer *observer, - uint32_t mgmt_event) + uint64_t mgmt_event) { #ifdef CONFIG_NET_MGMT_EVENT_INFO const struct net_event_coap_observer net_event = { diff --git a/subsys/net/lib/coap/coap_server.c b/subsys/net/lib/coap/coap_server.c index 6ab85ede3f1..27e4267167f 100644 --- a/subsys/net/lib/coap/coap_server.c +++ b/subsys/net/lib/coap/coap_server.c @@ -385,7 +385,7 @@ 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) +static inline void coap_service_raise_event(const struct coap_service *service, uint64_t mgmt_event) { #if defined(CONFIG_NET_MGMT_EVENT_INFO) const struct net_event_coap_service net_event = { diff --git a/subsys/net/lib/config/init.c b/subsys/net/lib/config/init.c index 56b6bc03b6c..22500fd8f84 100644 --- a/subsys/net/lib/config/init.c +++ b/subsys/net/lib/config/init.c @@ -102,7 +102,7 @@ static void print_dhcpv4_info(struct net_if *iface) static struct net_mgmt_event_callback mgmt4_cb; static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { if (mgmt_event == NET_EVENT_IPV4_ADDR_ADD) { @@ -244,7 +244,7 @@ static struct net_mgmt_event_callback mgmt6_cb; static struct in6_addr laddr; static void ipv6_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { struct net_if_ipv6 *ipv6 = iface->config.ip.ipv6; int i; @@ -310,7 +310,7 @@ static void ipv6_event_handler(struct net_mgmt_event_callback *cb, static void setup_ipv6(struct net_if *iface, uint32_t flags) { struct net_if_addr *ifaddr; - uint32_t mask = NET_EVENT_IPV6_DAD_SUCCEED; + uint64_t mask = NET_EVENT_IPV6_DAD_SUCCEED; if (sizeof(CONFIG_NET_CONFIG_MY_IPV6_ADDR) == 1) { /* Empty address, skip setting ANY address in this case */ @@ -330,20 +330,10 @@ static void setup_ipv6(struct net_if *iface, uint32_t flags) 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 - * so it will always return != NET_EVENT_IPV6_CMD_ADDR_ADD if any other - * event is set (for instance NET_EVENT_IPV6_ROUTER_ADD) - */ - if ((mask & NET_EVENT_IPV6_CMD_ADDR_ADD) == - NET_EVENT_IPV6_CMD_ADDR_ADD) { - ifaddr = net_if_ipv6_addr_add(iface, &laddr, - NET_ADDR_MANUAL, 0); - if (!ifaddr) { - NET_ERR("Cannot add %s to interface", - CONFIG_NET_CONFIG_MY_IPV6_ADDR); - } + ifaddr = net_if_ipv6_addr_add(iface, &laddr, NET_ADDR_MANUAL, 0); + if (!ifaddr) { + NET_ERR("Cannot add %s to interface", + CONFIG_NET_CONFIG_MY_IPV6_ADDR); } exit: @@ -363,7 +353,7 @@ static void setup_ipv6(struct net_if *iface, uint32_t flags) #if defined(CONFIG_NET_NATIVE) static void iface_up_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if (mgmt_event == NET_EVENT_IF_UP) { NET_INFO("Interface %d (%p) coming up", diff --git a/subsys/net/lib/config/init_clock_sntp.c b/subsys/net/lib/config/init_clock_sntp.c index dd63564f9c0..0e2b9aa1362 100644 --- a/subsys/net/lib/config/init_clock_sntp.c +++ b/subsys/net/lib/config/init_clock_sntp.c @@ -89,7 +89,7 @@ static void sntp_resync_handler(struct k_work *work) #endif /* CONFIG_NET_CONFIG_SNTP_INIT_RESYNC */ #ifdef CONFIG_NET_CONFIG_SNTP_INIT_USE_CONNECTION_MANAGER -static void l4_event_handler(uint32_t mgmt_event, struct net_if *iface, void *info, +static void l4_event_handler(uint64_t mgmt_event, struct net_if *iface, void *info, size_t info_length, void *user_data) { ARG_UNUSED(iface); diff --git a/subsys/net/lib/dhcpv4/dhcpv4.c b/subsys/net/lib/dhcpv4/dhcpv4.c index 2096bf330d9..f9a20bb7dfe 100644 --- a/subsys/net/lib/dhcpv4/dhcpv4.c +++ b/subsys/net/lib/dhcpv4/dhcpv4.c @@ -1637,7 +1637,7 @@ static enum net_verdict net_dhcpv4_input(struct net_conn *conn, } static void dhcpv4_iface_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { sys_snode_t *node = NULL; @@ -1699,7 +1699,7 @@ static void dhcpv4_iface_event_handler(struct net_mgmt_event_callback *cb, #if defined(CONFIG_NET_IPV4_ACD) static void dhcpv4_acd_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { sys_snode_t *node = NULL; struct in_addr *addr; diff --git a/subsys/net/lib/dhcpv6/dhcpv6.c b/subsys/net/lib/dhcpv6/dhcpv6.c index c1282c2a6f1..88770bac66d 100644 --- a/subsys/net/lib/dhcpv6/dhcpv6.c +++ b/subsys/net/lib/dhcpv6/dhcpv6.c @@ -2200,7 +2200,7 @@ static void dhcpv6_timeout(struct k_work *work) } static void dhcpv6_iface_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { sys_snode_t *node = NULL; diff --git a/subsys/net/lib/dns/llmnr_responder.c b/subsys/net/lib/dns/llmnr_responder.c index bf330e24374..f0f1f57ff28 100644 --- a/subsys/net/lib/dns/llmnr_responder.c +++ b/subsys/net/lib/dns/llmnr_responder.c @@ -117,7 +117,7 @@ static void create_ipv4_dst_addr(struct sockaddr_in *src_addr, #endif static void llmnr_iface_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if (mgmt_event == NET_EVENT_IF_UP) { #if defined(CONFIG_NET_IPV4) diff --git a/subsys/net/lib/dns/mdns_responder.c b/subsys/net/lib/dns/mdns_responder.c index 29f1c657ae1..8642364bc2b 100644 --- a/subsys/net/lib/dns/mdns_responder.c +++ b/subsys/net/lib/dns/mdns_responder.c @@ -157,7 +157,7 @@ static void mark_needs_announce(struct net_if *iface, bool needs_announce) #endif /* CONFIG_MDNS_RESPONDER_PROBE */ static void mdns_iface_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if (mgmt_event == NET_EVENT_IF_UP) { @@ -958,7 +958,7 @@ static void probing(struct k_work *work) } static void mdns_addr_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { uint32_t probe_delay = sys_rand32_get() % 250; bool probe_started = false; @@ -1110,7 +1110,7 @@ static void mdns_addr_event_handler(struct net_mgmt_event_callback *cb, } static void mdns_conn_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if (mgmt_event == NET_EVENT_L4_DISCONNECTED) { /* Clear the failed probes counter so that we can start @@ -1823,7 +1823,7 @@ static void do_init_listener(struct k_work *work) static int mdns_responder_init(void) { - uint32_t flags = NET_EVENT_IF_UP; + uint64_t flags = NET_EVENT_IF_UP; external_records = NULL; external_records_count = 0; diff --git a/subsys/net/lib/ptp/port.c b/subsys/net/lib/ptp/port.c index 24abec002c8..d3f803cb391 100644 --- a/subsys/net/lib/ptp/port.c +++ b/subsys/net/lib/ptp/port.c @@ -964,7 +964,7 @@ int port_state_update(struct ptp_port *port, enum ptp_port_event event, bool tt_ } static void port_link_monitor(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(cb); diff --git a/subsys/net/lib/shell/events.c b/subsys/net/lib/shell/events.c index 6b27dc2e4b0..51afbc85fc9 100644 --- a/subsys/net/lib/shell/events.c +++ b/subsys/net/lib/shell/events.c @@ -44,7 +44,7 @@ static const char unknown_event_str[] = ""; struct event_msg { struct net_if *iface; size_t len; - uint32_t event; + uint64_t event; uint8_t data[MAX_EVENT_INFO_SIZE]; }; @@ -52,7 +52,7 @@ K_MSGQ_DEFINE(event_mon_msgq, sizeof(struct event_msg), CONFIG_NET_MGMT_EVENT_QUEUE_SIZE, sizeof(intptr_t)); static void event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { struct event_msg msg; int ret; @@ -563,7 +563,7 @@ static void event_mon_handler(const struct shell *sh, void *p2, void *p3) } if (desc == unknown_event_str) { - PR_INFO("EVENT: %s [%d] %s%s%s%s%s (0x%08x)\n", layer_str, + PR_INFO("EVENT: %s [%d] %s%s%s%s%s (0x%" PRIx64 ")\n", layer_str, net_if_get_by_iface(msg.iface), desc, desc2 ? " " : "", desc2 ? desc2 : "", info ? " " : "", info ? info : "", msg.event); diff --git a/subsys/net/lib/sockets/sockets_net_mgmt.c b/subsys/net/lib/sockets/sockets_net_mgmt.c index 909893e0444..0b45416c1f2 100644 --- a/subsys/net/lib/sockets/sockets_net_mgmt.c +++ b/subsys/net/lib/sockets/sockets_net_mgmt.c @@ -31,7 +31,7 @@ __net_socket struct net_mgmt_socket { uintptr_t pid; /* net_mgmt mask */ - uint32_t mask; + uint64_t mask; /* Message allocation timeout */ k_timeout_t alloc_timeout; @@ -145,7 +145,7 @@ static ssize_t znet_mgmt_recvfrom(struct net_mgmt_socket *mgmt, void *buf, { struct sockaddr_nm *nm_addr = (struct sockaddr_nm *)src_addr; k_timeout_t timeout = mgmt->wait_timeout; - uint32_t raised_event = 0; + uint64_t raised_event = 0; uint8_t *copy_to = buf; struct net_mgmt_msghdr hdr; struct net_if *iface; diff --git a/subsys/shell/backends/shell_mqtt.c b/subsys/shell/backends/shell_mqtt.c index 28bd39f4b0d..d77cbac6742 100644 --- a/subsys/shell/backends/shell_mqtt.c +++ b/subsys/shell/backends/shell_mqtt.c @@ -508,7 +508,7 @@ static void net_disconnect_handler(struct k_work *work) } /* Network connection event handler */ -static void network_evt_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void network_evt_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { struct shell_mqtt *sh = sh_mqtt; diff --git a/tests/boards/espressif/ethernet/src/main.c b/tests/boards/espressif/ethernet/src/main.c index b64bc946366..e9c397d795f 100644 --- a/tests/boards/espressif/ethernet/src/main.c +++ b/tests/boards/espressif/ethernet/src/main.c @@ -30,7 +30,7 @@ static uint8_t ntp_server[4]; static struct net_mgmt_event_callback mgmt_cb; static struct net_dhcpv4_option_callback dhcp_cb; -static void ipv4_event(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void ipv4_event(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { if ((mgmt_event != NET_EVENT_IPV4_ADDR_ADD) || diff --git a/tests/boards/espressif/wifi/src/main.c b/tests/boards/espressif/wifi/src/main.c index bbccdb9b2a9..931927ef25d 100644 --- a/tests/boards/espressif/wifi/src/main.c +++ b/tests/boards/espressif/wifi/src/main.c @@ -93,7 +93,7 @@ static void wifi_disconnect_result(struct net_mgmt_event_callback *cb) } } -static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { switch (mgmt_event) { diff --git a/tests/net/conn_mgr_conn/src/main.c b/tests/net/conn_mgr_conn/src/main.c index b66e246b12d..940d142b8db 100644 --- a/tests/net/conn_mgr_conn/src/main.c +++ b/tests/net/conn_mgr_conn/src/main.c @@ -95,7 +95,7 @@ static struct event_stats { struct net_mgmt_event_callback conn_mgr_conn_callback; static void conn_mgr_conn_handler(struct net_mgmt_event_callback *cb, - uint32_t event, struct net_if *iface) + uint64_t event, struct net_if *iface) { k_mutex_lock(&event_mutex, K_FOREVER); diff --git a/tests/net/conn_mgr_monitor/src/main.c b/tests/net/conn_mgr_monitor/src/main.c index cd8242c10d1..e1e1cd67081 100644 --- a/tests/net/conn_mgr_monitor/src/main.c +++ b/tests/net/conn_mgr_monitor/src/main.c @@ -38,12 +38,12 @@ #define DAD_WAIT_TIME EVENT_WAIT_TIME #endif -#define TEST_EXPECT_L4_CONNECTED BIT(NET_EVENT_L4_CMD_CONNECTED) -#define TEST_EXPECT_L4_DISCONNECTED BIT(NET_EVENT_L4_CMD_DISCONNECTED) -#define TEST_EXPECT_L4_IPV6_CONNECTED BIT(NET_EVENT_L4_CMD_IPV6_CONNECTED) -#define TEST_EXPECT_L4_IPV6_DISCONNECTED BIT(NET_EVENT_L4_CMD_IPV6_DISCONNECTED) -#define TEST_EXPECT_L4_IPV4_CONNECTED BIT(NET_EVENT_L4_CMD_IPV4_CONNECTED) -#define TEST_EXPECT_L4_IPV4_DISCONNECTED BIT(NET_EVENT_L4_CMD_IPV4_DISCONNECTED) +#define TEST_EXPECT_L4_CONNECTED NET_EVENT_L4_CMD_CONNECTED +#define TEST_EXPECT_L4_DISCONNECTED NET_EVENT_L4_CMD_DISCONNECTED +#define TEST_EXPECT_L4_IPV6_CONNECTED NET_EVENT_L4_CMD_IPV6_CONNECTED +#define TEST_EXPECT_L4_IPV6_DISCONNECTED NET_EVENT_L4_CMD_IPV6_DISCONNECTED +#define TEST_EXPECT_L4_IPV4_CONNECTED NET_EVENT_L4_CMD_IPV4_CONNECTED +#define TEST_EXPECT_L4_IPV4_DISCONNECTED NET_EVENT_L4_CMD_IPV4_DISCONNECTED #define TEST_EXPECT_CLEAR(event) (global_stats.expected_events &= ~event) @@ -162,7 +162,7 @@ static struct test_stats get_reset_stats(void) /* Callback hooks */ struct net_mgmt_event_callback l4_callback; -void l4_handler(struct net_mgmt_event_callback *cb, uint32_t event, struct net_if *iface) +void l4_handler(struct net_mgmt_event_callback *cb, uint64_t event, struct net_if *iface) { if (event == NET_EVENT_L4_CONNECTED) { k_mutex_lock(&stats_mutex, K_FOREVER); @@ -187,7 +187,7 @@ void l4_handler(struct net_mgmt_event_callback *cb, uint32_t event, struct net_i struct net_mgmt_event_callback conn_callback; -void conn_handler(struct net_mgmt_event_callback *cb, uint32_t event, struct net_if *iface) +void conn_handler(struct net_mgmt_event_callback *cb, uint64_t event, struct net_if *iface) { if (event == NET_EVENT_L4_IPV6_CONNECTED) { k_mutex_lock(&stats_mutex, K_FOREVER); @@ -224,7 +224,7 @@ void conn_handler(struct net_mgmt_event_callback *cb, uint32_t event, struct net } } -static void wait_for_events(uint32_t event_mask, k_timeout_t timeout) +static void wait_for_events(uint64_t event_mask, k_timeout_t timeout) { k_mutex_lock(&stats_mutex, K_FOREVER); k_sem_reset(&event_sem); diff --git a/tests/net/conn_mgr_nsos/src/main.c b/tests/net/conn_mgr_nsos/src/main.c index 41c4273f262..d4e014accff 100644 --- a/tests/net/conn_mgr_nsos/src/main.c +++ b/tests/net/conn_mgr_nsos/src/main.c @@ -15,7 +15,7 @@ K_SEM_DEFINE(l4_connected, 0, 1); K_SEM_DEFINE(l4_disconnected, 0, 1); -static void l4_event_handler(struct net_mgmt_event_callback *cb, uint32_t event, +static void l4_event_handler(struct net_mgmt_event_callback *cb, uint64_t event, struct net_if *iface) { switch (event) { diff --git a/tests/net/dhcpv4/client/prj.conf b/tests/net/dhcpv4/client/prj.conf index 5b126f90a14..5ac77585482 100644 --- a/tests/net/dhcpv4/client/prj.conf +++ b/tests/net/dhcpv4/client/prj.conf @@ -20,6 +20,7 @@ CONFIG_NET_MGMT_EVENT=y CONFIG_NET_MGMT_EVENT_INFO=y CONFIG_DNS_RESOLVER=y +CONFIG_DNS_RESOLVER_MAX_SERVERS=3 # Turn off UDP checksum checking as the test fails otherwise. CONFIG_NET_UDP_CHECKSUM=n @@ -31,3 +32,5 @@ CONFIG_NET_DHCPV4_INITIAL_DELAY_MAX=2 CONFIG_NET_DHCPV4_LOG_LEVEL_DBG=y CONFIG_LOG_BUFFER_SIZE=8192 + +CONFIG_ZVFS_POLL_MAX=5 diff --git a/tests/net/dhcpv4/client/src/main.c b/tests/net/dhcpv4/client/src/main.c index 654a98d2cbe..7c87ab4d478 100644 --- a/tests/net/dhcpv4/client/src/main.c +++ b/tests/net/dhcpv4/client/src/main.c @@ -493,7 +493,7 @@ static struct net_dhcpv4_option_callback opt_vs_invalid_cb; static int event_count; static void receiver_cb(struct net_mgmt_event_callback *cb, - uint32_t nm_event, struct net_if *iface) + uint64_t nm_event, struct net_if *iface) { if (nm_event != NET_EVENT_IPV4_ADDR_ADD && nm_event != NET_EVENT_DNS_SERVER_ADD && @@ -694,7 +694,7 @@ ZTEST(dhcpv4_tests, test_dhcp) #elif defined(CONFIG_NET_DHCPV4_OPTION_CALLBACKS) while (event_count < 10) { #elif defined(CONFIG_NET_DHCPV4_OPTION_PRINT_IGNORED) - while (event_count < 2) { + while (event_count < 1) { #else while (event_count < 5) { #endif diff --git a/tests/net/dhcpv6/src/main.c b/tests/net/dhcpv6/src/main.c index c5046a2746a..b1375383c67 100644 --- a/tests/net/dhcpv6/src/main.c +++ b/tests/net/dhcpv6/src/main.c @@ -178,7 +178,7 @@ static struct net_pkt *test_dhcpv6_create_message( return NULL; } -static void evt_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void evt_handler(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(cb); diff --git a/tests/net/hostname/src/main.c b/tests/net/hostname/src/main.c index bfc2fd926f8..b5c0664d2ef 100644 --- a/tests/net/hostname/src/main.c +++ b/tests/net/hostname/src/main.c @@ -101,7 +101,7 @@ static void net_iface_init(struct net_if *iface) #ifdef CONFIG_NET_MGMT_EVENT static void hostname_changed(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if (mgmt_event == NET_EVENT_HOSTNAME_CHANGED) { #ifdef CONFIG_NET_MGMT_EVENT_INFO diff --git a/tests/net/ieee802154/l2/src/ieee802154_shell_test.c b/tests/net/ieee802154/l2/src/ieee802154_shell_test.c index 0281b699edb..5964025e023 100644 --- a/tests/net/ieee802154/l2/src/ieee802154_shell_test.c +++ b/tests/net/ieee802154/l2/src/ieee802154_shell_test.c @@ -50,7 +50,7 @@ static bool expected_association_permitted_bit; #define EXPECTED_PAYLOAD_DATA EXPECTED_ENDDEVICE_EXT_ADDR_LE #define EXPECTED_PAYLOAD_LEN 8 -static void scan_result_cb(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, +static void scan_result_cb(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface) { struct ieee802154_context *ctx = net_if_l2_data(iface); diff --git a/tests/net/igmp/src/main.c b/tests/net/igmp/src/main.c index 7878c5953eb..e2f201dd4ee 100644 --- a/tests/net/igmp/src/main.c +++ b/tests/net/igmp/src/main.c @@ -227,7 +227,7 @@ NET_DEVICE_INIT(net_test_igmp, "net_test_igmp", 127); static void group_joined(struct net_mgmt_event_callback *cb, - uint32_t nm_event, struct net_if *iface) + uint64_t nm_event, struct net_if *iface) { if (nm_event != NET_EVENT_IPV4_MCAST_JOIN) { /* Spurious callback. */ @@ -240,7 +240,7 @@ static void group_joined(struct net_mgmt_event_callback *cb, } static void group_left(struct net_mgmt_event_callback *cb, - uint32_t nm_event, struct net_if *iface) + uint64_t nm_event, struct net_if *iface) { if (nm_event != NET_EVENT_IPV4_MCAST_LEAVE) { /* Spurious callback. */ @@ -253,7 +253,7 @@ static void group_left(struct net_mgmt_event_callback *cb, } static struct mgmt_events { - uint32_t event; + uint64_t event; net_mgmt_event_handler_t handler; struct net_mgmt_event_callback cb; } mgmt_events[] = { diff --git a/tests/net/lib/dns_addremove/src/main.c b/tests/net/lib/dns_addremove/src/main.c index 1b6f55efd73..f8f9fdc1c80 100644 --- a/tests/net/lib/dns_addremove/src/main.c +++ b/tests/net/lib/dns_addremove/src/main.c @@ -139,7 +139,7 @@ NET_DEVICE_INIT_INSTANCE(net_iface1_test, 127); static void dns_evt_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { if (mgmt_event == NET_EVENT_DNS_SERVER_ADD) { k_sem_give(&dns_added); diff --git a/tests/net/mgmt/src/mgmt.c b/tests/net/mgmt/src/mgmt.c index 004b60adb97..288dcc353b2 100644 --- a/tests/net/mgmt/src/mgmt.c +++ b/tests/net/mgmt/src/mgmt.c @@ -28,7 +28,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_MGMT_EVENT_LOG_LEVEL); MAX(sizeof(TEST_INFO_STRING), sizeof(struct in6_addr)) /* Notifier infra */ -static uint32_t event2throw; +static uint64_t event2throw; static uint32_t throw_times; static uint32_t throw_sleep; static bool with_info; @@ -38,7 +38,7 @@ static struct k_thread thrower_thread_data; static struct k_sem thrower_lock; /* Receiver infra */ -static uint32_t rx_event; +static uint64_t rx_event; static uint32_t rx_calls; static size_t info_length_in_test; static struct net_mgmt_event_callback rx_cb; @@ -49,7 +49,7 @@ static struct in6_addr addr6 = { { { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, static char info_data[TEST_MGMT_EVENT_INFO_SIZE]; -static int test_mgmt_request(uint32_t mgmt_request, +static int test_mgmt_request(uint64_t mgmt_request, struct net_if *iface, void *data, uint32_t len) { uint32_t *test_data = data; @@ -67,14 +67,14 @@ static int test_mgmt_request(uint32_t mgmt_request, NET_MGMT_REGISTER_REQUEST_HANDLER(TEST_MGMT_REQUEST, test_mgmt_request); -static void test_mgmt_event_handler(uint32_t mgmt_event, struct net_if *iface, void *info, +static void test_mgmt_event_handler(uint64_t mgmt_event, struct net_if *iface, void *info, size_t info_length, void *user_data) { if (!with_static) { return; } - TC_PRINT("\t\tReceived static event 0x%08X\n", mgmt_event); + TC_PRINT("\t\tReceived static event 0x%" PRIx64 "\n", mgmt_event); ARG_UNUSED(user_data); @@ -144,7 +144,7 @@ static void thrower_thread(void *p1, void *p2, void *p3) while (1) { k_sem_take(&thrower_lock, K_FOREVER); - TC_PRINT("\tThrowing event 0x%08X %u times\n", + TC_PRINT("\tThrowing event 0x%" PRIx64 " %u times\n", event2throw, throw_times); for (; throw_times; throw_times--) { @@ -168,9 +168,9 @@ static void thrower_thread(void *p1, void *p2, void *p3) } static void receiver_cb(struct net_mgmt_event_callback *cb, - uint32_t nm_event, struct net_if *iface) + uint64_t nm_event, struct net_if *iface) { - TC_PRINT("\t\tReceived event 0x%08X\n", nm_event); + TC_PRINT("\t\tReceived event 0x%" PRIx64 "\n", nm_event); if (with_info && cb->info) { if (cb->info_length != info_length_in_test) { @@ -208,14 +208,15 @@ static int sending_event(uint32_t times, bool receiver, bool info) k_msleep(THREAD_SLEEP); if (receiver) { - TC_PRINT("\tReceived 0x%08X %u times\n", + TC_PRINT("\tReceived 0x%" PRIx64 " %u times\n", rx_event, rx_calls); zassert_equal(rx_event, event2throw, "rx_event check failed"); zassert_equal(rx_calls, times, "rx_calls check failed"); net_mgmt_del_event_callback(&rx_cb); - rx_event = rx_calls = 0U; + rx_event = 0ULL; + rx_calls = 0U; } return TC_PASS; @@ -233,7 +234,7 @@ static int test_sending_event_info(uint32_t times, bool receiver) static int test_synchronous_event_listener(uint32_t times, bool on_iface) { - uint32_t event_mask; + uint64_t event_mask; int ret; TC_PRINT("- Synchronous event listener %s\n", @@ -283,13 +284,14 @@ static int test_static_event_listener(uint32_t times, bool info) /* Let the network stack to proceed */ k_msleep(THREAD_SLEEP); - TC_PRINT("\tReceived 0x%08X %u times\n", + TC_PRINT("\tReceived 0x%" PRIx64 " %u times\n", rx_event, rx_calls); zassert_equal(rx_event, event2throw, "rx_event check failed"); zassert_equal(rx_calls, times, "rx_calls check failed"); - rx_event = rx_calls = 0U; + rx_event = 0ULL; + rx_calls = 0U; with_static = false; return TC_PASS; @@ -297,12 +299,12 @@ static int test_static_event_listener(uint32_t times, bool info) static void initialize_event_tests(void) { - event2throw = 0U; + event2throw = 0ULL; throw_times = 0U; throw_sleep = 0; with_info = false; - rx_event = 0U; + rx_event = 0ULL; rx_calls = 0U; k_sem_init(&thrower_lock, 0, UINT_MAX); @@ -318,9 +320,9 @@ static void initialize_event_tests(void) NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); } -static int test_core_event(uint32_t event, bool (*func)(void)) +static int test_core_event(uint64_t event, bool (*func)(void)) { - TC_PRINT("- Triggering core event: 0x%08X\n", event); + TC_PRINT("- Triggering core event: 0x%" PRIx64 "\n", event); info_length_in_test = sizeof(struct in6_addr); memcpy(info_data, &addr6, sizeof(addr6)); @@ -336,10 +338,11 @@ static int test_core_event(uint32_t event, bool (*func)(void)) zassert_true(rx_calls > 0 && rx_calls != -1, "rx_calls empty"); zassert_equal(rx_event, event, "rx_event check failed, " - "0x%08x vs 0x%08x", rx_event, event); + "0x%" PRIx64 " vs 0x%" PRIx64, rx_event, event); net_mgmt_del_event_callback(&rx_cb); - rx_event = rx_calls = 0U; + rx_event = 0ULL; + rx_calls = 0U; return TC_PASS; } @@ -426,7 +429,7 @@ ZTEST(mgmt_fn_test_suite, test_mgmt) static K_SEM_DEFINE(wait_for_event_processing, 0, 1); static void net_mgmt_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) + uint64_t mgmt_event, struct net_if *iface) { static int cb_call_count; diff --git a/tests/net/mld/src/main.c b/tests/net/mld/src/main.c index 1c95fe5409d..0036b5853af 100644 --- a/tests/net/mld/src/main.c +++ b/tests/net/mld/src/main.c @@ -238,7 +238,7 @@ static void test_iface_carrier_off_on(void) } static void group_joined(struct net_mgmt_event_callback *cb, - uint32_t nm_event, struct net_if *iface) + uint64_t nm_event, struct net_if *iface) { if (nm_event != NET_EVENT_IPV6_MCAST_JOIN) { /* Spurious callback. */ @@ -254,7 +254,7 @@ static void group_joined(struct net_mgmt_event_callback *cb, } static void group_left(struct net_mgmt_event_callback *cb, - uint32_t nm_event, struct net_if *iface) + uint64_t nm_event, struct net_if *iface) { if (nm_event != NET_EVENT_IPV6_MCAST_LEAVE) { /* Spurious callback. */ @@ -270,7 +270,7 @@ static void group_left(struct net_mgmt_event_callback *cb, } static struct mgmt_events { - uint32_t event; + uint64_t event; net_mgmt_event_handler_t handler; struct net_mgmt_event_callback cb; } mgmt_events[] = { diff --git a/tests/net/pmtu/src/main.c b/tests/net/pmtu/src/main.c index 54d225a259e..d744a4415f4 100644 --- a/tests/net/pmtu/src/main.c +++ b/tests/net/pmtu/src/main.c @@ -103,7 +103,7 @@ static K_SEM_DEFINE(wait_pmtu_changed, 0, UINT_MAX); static bool is_pmtu_changed; static void ipv6_pmtu_changed(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(cb); @@ -123,7 +123,7 @@ static void ipv6_pmtu_changed(struct net_mgmt_event_callback *cb, } static void ipv4_pmtu_changed(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, + uint64_t mgmt_event, struct net_if *iface) { ARG_UNUSED(cb); @@ -143,7 +143,7 @@ static void ipv4_pmtu_changed(struct net_mgmt_event_callback *cb, } static struct mgmt_events { - uint32_t event; + uint64_t event; net_mgmt_event_handler_t handler; struct net_mgmt_event_callback cb; } mgmt_events[] = { From 664e66c32f9ff1dc86a0fed3fea82b55cce36bfa Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 4 Jun 2025 16:35:31 +0300 Subject: [PATCH 26/42] [nrf fromtree] net: socket: mgmt: Create proper socket options for net_mgmt sockets We cannot use the network management event number directly as a socket option value because the management value is uint64_t and that cannot be mapped directly to 32 bit integer. So have an intermediate socket option that is mapped to actual network management request number in getsockopt() and setsockopt(). Signed-off-by: Jukka Rissanen (cherry picked from commit 2ed2232f17f732bcf8b21db70e6dfb4e49782be1) Signed-off-by: Robert Lubos --- include/zephyr/net/socket_net_mgmt.h | 13 +++++++++++++ subsys/net/lib/sockets/sockets_net_mgmt.c | 4 ++-- tests/net/socket/net_mgmt/src/main.c | 21 +++++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/zephyr/net/socket_net_mgmt.h b/include/zephyr/net/socket_net_mgmt.h index 337648d5d18..595a92bbad9 100644 --- a/include/zephyr/net/socket_net_mgmt.h +++ b/include/zephyr/net/socket_net_mgmt.h @@ -42,6 +42,19 @@ extern "C" { /** @endcond */ +/** + * @name Socket options for NET_MGMT sockets + * @{ + */ + +/** Set Ethernet Qav parameters */ +#define SO_NET_MGMT_ETHERNET_SET_QAV_PARAM 1 + +/** Get Ethernet Qav parameters */ +#define SO_NET_MGMT_ETHERNET_GET_QAV_PARAM 2 + +/** @} */ /* for @name */ + /** * struct sockaddr_nm - The sockaddr structure for NET_MGMT sockets * diff --git a/subsys/net/lib/sockets/sockets_net_mgmt.c b/subsys/net/lib/sockets/sockets_net_mgmt.c index 0b45416c1f2..dcb4194ec85 100644 --- a/subsys/net/lib/sockets/sockets_net_mgmt.c +++ b/subsys/net/lib/sockets/sockets_net_mgmt.c @@ -237,7 +237,7 @@ static int znet_mgmt_getsockopt(struct net_mgmt_socket *mgmt, int level, } if (IS_ENABLED(CONFIG_NET_L2_ETHERNET_MGMT)) { - if (optname == NET_REQUEST_ETHERNET_GET_QAV_PARAM) { + if (optname == SO_NET_MGMT_ETHERNET_GET_QAV_PARAM) { int ret; ret = net_mgmt(NET_REQUEST_ETHERNET_GET_QAV_PARAM, @@ -274,7 +274,7 @@ static int znet_mgmt_setsockopt(struct net_mgmt_socket *mgmt, int level, } if (IS_ENABLED(CONFIG_NET_L2_ETHERNET_MGMT)) { - if (optname == NET_REQUEST_ETHERNET_SET_QAV_PARAM) { + if (optname == SO_NET_MGMT_ETHERNET_SET_QAV_PARAM) { int ret; ret = net_mgmt(NET_REQUEST_ETHERNET_SET_QAV_PARAM, diff --git a/tests/net/socket/net_mgmt/src/main.c b/tests/net/socket/net_mgmt/src/main.c index a5d6ead4679..89901beda7b 100644 --- a/tests/net/socket/net_mgmt/src/main.c +++ b/tests/net/socket/net_mgmt/src/main.c @@ -20,6 +20,19 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL); #define STACK_SIZE 1024 #define THREAD_PRIORITY K_PRIO_COOP(8) +/* Use a base value for socket options that are not implemented. + * This is used to check if the socket option is implemented or not. + */ +#define NOT_IMPLEMENTED_SOCKET_OPTION_BASE (INT32_MAX - 1000) + +#if !defined(SO_NET_MGMT_ETHERNET_GET_PRIORITY_QUEUES_NUM) +#define SO_NET_MGMT_ETHERNET_GET_PRIORITY_QUEUES_NUM (NOT_IMPLEMENTED_SOCKET_OPTION_BASE + 1) +#endif /* !defined(SO_NET_MGMT_ETHERNET_GET_PRIORITY_QUEUES_NUM) */ + +#if !defined(SO_NET_MGMT_ETHERNET_SET_MAC_ADDRESS) +#define SO_NET_MGMT_ETHERNET_SET_MAC_ADDRESS (NOT_IMPLEMENTED_SOCKET_OPTION_BASE + 2) +#endif /* !defined(SO_NET_MGMT_ETHERNET_SET_MAC_ADDRESS) */ + static struct net_if *default_iface; static ZTEST_BMEM int fd; @@ -502,7 +515,7 @@ static void test_ethernet_set_qav(void) params.qav_param.enabled = true; ret = zsock_setsockopt(fd, SOL_NET_MGMT_RAW, - NET_REQUEST_ETHERNET_SET_QAV_PARAM, + SO_NET_MGMT_ETHERNET_SET_QAV_PARAM, ¶ms, sizeof(params)); zassert_equal(ret, 0, "Cannot set Qav parameters"); } @@ -529,7 +542,7 @@ static void test_ethernet_get_qav(void) params.qav_param.type = ETHERNET_QAV_PARAM_TYPE_STATUS; ret = zsock_getsockopt(fd, SOL_NET_MGMT_RAW, - NET_REQUEST_ETHERNET_GET_QAV_PARAM, + SO_NET_MGMT_ETHERNET_GET_QAV_PARAM, ¶ms, &optlen); zassert_equal(ret, 0, "Cannot get Qav parameters (%d)", ret); zassert_equal(optlen, sizeof(params), "Invalid optlen (%d)", optlen); @@ -556,7 +569,7 @@ static void test_ethernet_get_unknown_option(void) memset(¶ms, 0, sizeof(params)); ret = zsock_getsockopt(fd, SOL_NET_MGMT_RAW, - NET_REQUEST_ETHERNET_GET_PRIORITY_QUEUES_NUM, + SO_NET_MGMT_ETHERNET_GET_PRIORITY_QUEUES_NUM, ¶ms, &optlen); zassert_equal(ret, -1, "Could get prio queue parameters (%d)", errno); zassert_equal(errno, EINVAL, "prio queue get parameters"); @@ -581,7 +594,7 @@ static void test_ethernet_set_unknown_option(void) memset(¶ms, 0, sizeof(params)); ret = zsock_setsockopt(fd, SOL_NET_MGMT_RAW, - NET_REQUEST_ETHERNET_SET_MAC_ADDRESS, + SO_NET_MGMT_ETHERNET_SET_MAC_ADDRESS, ¶ms, optlen); zassert_equal(ret, -1, "Could set promisc_mode parameters (%d)", errno); zassert_equal(errno, EINVAL, "promisc_mode set parameters"); From 2b89705e9b89a5779bcdccfe853d2c0d08074a16 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Fri, 30 May 2025 15:23:23 +0300 Subject: [PATCH 27/42] [nrf fromtree] doc: migration: 4.2: Add information about net_mgmt API changes Add information how the net_mgmt request handler is changed. The event number type is changed from uint32_t to uint64_t to allow the event command to be a bit mask instead of enum value. Signed-off-by: Jukka Rissanen (cherry picked from commit 6b0597f631338b2193a57c91a1093b0aeb8dd1d2) Signed-off-by: Robert Lubos --- doc/releases/migration-guide-4.2.rst | 15 +++++++++++++++ doc/releases/release-notes-4.2.rst | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/doc/releases/migration-guide-4.2.rst b/doc/releases/migration-guide-4.2.rst index 08a2a3d0e33..9b31f4a1634 100644 --- a/doc/releases/migration-guide-4.2.rst +++ b/doc/releases/migration-guide-4.2.rst @@ -509,6 +509,21 @@ Networking need to update their response callback implementations. To retain current behavior, simply return 0 from the callback. +* The API signature of ``net_mgmt`` event handler :c:type:`net_mgmt_event_handler_t` and + request handler :c:type:`net_mgmt_request_handler_t` has changed. The management event + type is changed from ``uint32_t`` to ``uint64_t``. The change allows event number values + to be bit masks instead of enum values. The layer code still stays as a enum value. + The :c:macro:`NET_MGMT_LAYER_CODE` and :c:macro:`NET_MGMT_GET_COMMAND` can be used to get + the layer code and management event command from the actual event value in the request or + event handlers if needed. + +* The socket options for ``net_mgmt`` type sockets cannot directly be network management + event types as those are now ``uint64_t`` and the socket option expects a normal 32 bit + integer value. Because of this, a new ``SO_NET_MGMT_ETHERNET_SET_QAV_PARAM`` + and ``SO_NET_MGMT_ETHERNET_GET_QAV_PARAM`` socket options are created that will replace + the previously used ``NET_REQUEST_ETHERNET_GET_QAV_PARAM`` and + ``NET_REQUEST_ETHERNET_GET_QAV_PARAM`` options. + OpenThread ========== diff --git a/doc/releases/release-notes-4.2.rst b/doc/releases/release-notes-4.2.rst index 00c65556880..80e0f5868de 100644 --- a/doc/releases/release-notes-4.2.rst +++ b/doc/releases/release-notes-4.2.rst @@ -111,6 +111,13 @@ Deprecated APIs and options was deprecated since Zephyr 4.0, and users were advised to migrate to alternative crypto backends. +Stable API changes in this release +================================== + +* The API signature of ``net_mgmt`` event handler :c:type:`net_mgmt_event_handler_t` + and request handler :c:type:`net_mgmt_request_handler_t` has changed. The event value + type is changed from ``uint32_t`` to ``uint64_t``. + New APIs and options ==================== From f5093d3789c7b9fd38ab1c17d62a74854c5d70c6 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Mon, 9 Jun 2025 17:28:47 +0300 Subject: [PATCH 28/42] [nrf fromtree] net: mgmt: Increment API major version number As per API overview documentation, a braking API change must increment major version number. https://docs.zephyrproject.org/latest/develop/api/overview.html#api-overview Signed-off-by: Jukka Rissanen (cherry picked from commit b1a8655bf0d8fb64ce1034e7b7efd2e983360874) Signed-off-by: Robert Lubos --- include/zephyr/net/net_mgmt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/net/net_mgmt.h b/include/zephyr/net/net_mgmt.h index 9c559b7fd8b..1c5f0aebeaa 100644 --- a/include/zephyr/net/net_mgmt.h +++ b/include/zephyr/net/net_mgmt.h @@ -24,7 +24,7 @@ extern "C" { * @brief Network Management * @defgroup net_mgmt Network Management * @since 1.7 - * @version 1.0.0 + * @version 2.0.0 * @ingroup networking * @{ */ From 22479b9c1f1d4915b4adc2bec36021f2e86f7c9b Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Thu, 26 Jun 2025 15:01:20 +0200 Subject: [PATCH 29/42] [nrf fromtree] net: ppp: stats: Fix net_mgmt request handler format This has been missed in net_mgmt rework in commit 5a9a39caf3bf5195a38194bb844a428eaa7f2bb8. Signed-off-by: Robert Lubos (cherry picked from commit 3e704256e308fed36dfea82b1e897439eecc49fe) --- subsys/net/l2/ppp/ppp_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/ppp/ppp_stats.c b/subsys/net/l2/ppp/ppp_stats.c index 9dafef154b3..ee831b3953d 100644 --- a/subsys/net/l2/ppp/ppp_stats.c +++ b/subsys/net/l2/ppp/ppp_stats.c @@ -17,7 +17,7 @@ LOG_MODULE_REGISTER(net_ppp_stats, CONFIG_NET_L2_PPP_LOG_LEVEL); #if defined(CONFIG_NET_STATISTICS_USER_API) -static int ppp_stats_get(uint32_t mgmt_request, struct net_if *iface, +static int ppp_stats_get(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len) { size_t len_chk = 0; From 2cf4a21ae0008f40c499943e9ba7ec794ab0385b Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Thu, 26 Jun 2025 14:17:43 +0200 Subject: [PATCH 30/42] [nrf fromtree] net: events: Add missing net_mgmt.h include net_event.h header makes use of macros defined in net_mgmt.h, therefore it should include that header. Signed-off-by: Robert Lubos (cherry picked from commit ae7d7a800e281b42068a56cda3a7c5be56639600) --- include/zephyr/net/net_event.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/zephyr/net/net_event.h b/include/zephyr/net/net_event.h index 3a948ca5ef9..556a78ae99e 100644 --- a/include/zephyr/net/net_event.h +++ b/include/zephyr/net/net_event.h @@ -13,6 +13,7 @@ #define ZEPHYR_INCLUDE_NET_NET_EVENT_H_ #include +#include #include #ifdef __cplusplus From 9c45c9847cf12b71026a1241dfc06bf52da3f1a9 Mon Sep 17 00:00:00 2001 From: Ajay Parida Date: Mon, 3 Jun 2024 17:31:59 +0530 Subject: [PATCH 31/42] [nrf fromtree] net: l2: wifi: Configure BSS max idle period Support to configure BSS max idle period at runtime. Signed-off-by: Ajay Parida (cherry picked from commit c70b3504bb9aa421baa150ec9248808f82b04219) Signed-off-by: Robert Lubos --- drivers/wifi/nrf_wifi/inc/fmac_main.h | 1 + drivers/wifi/nrf_wifi/inc/wifi_mgmt.h | 3 ++ drivers/wifi/nrf_wifi/src/fmac_main.c | 4 ++ drivers/wifi/nrf_wifi/src/wifi_mgmt.c | 53 +++++++++++++++++++++++++ drivers/wifi/nrf_wifi/src/wpa_supp_if.c | 6 ++- include/zephyr/net/wifi_mgmt.h | 16 ++++++++ modules/hostap/src/supp_api.c | 13 ++++++ modules/hostap/src/supp_api.h | 8 ++++ modules/hostap/src/supp_main.c | 1 + subsys/net/l2/wifi/Kconfig | 16 ++++++++ subsys/net/l2/wifi/wifi_mgmt.c | 25 ++++++++++++ subsys/net/l2/wifi/wifi_shell.c | 32 +++++++++++++++ 12 files changed, 176 insertions(+), 2 deletions(-) diff --git a/drivers/wifi/nrf_wifi/inc/fmac_main.h b/drivers/wifi/nrf_wifi/inc/fmac_main.h index c193515ae2d..7a863d8b614 100644 --- a/drivers/wifi/nrf_wifi/inc/fmac_main.h +++ b/drivers/wifi/nrf_wifi/inc/fmac_main.h @@ -91,6 +91,7 @@ struct nrf_wifi_vif_ctx_zep { struct k_work_delayable nrf_wifi_rpu_recovery_bringup_work; #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */ int rts_threshold_value; + unsigned short bss_max_idle_period; }; struct nrf_wifi_vif_ctx_map { diff --git a/drivers/wifi/nrf_wifi/inc/wifi_mgmt.h b/drivers/wifi/nrf_wifi/inc/wifi_mgmt.h index a4ae2030210..9b84427cdca 100644 --- a/drivers/wifi/nrf_wifi/inc/wifi_mgmt.h +++ b/drivers/wifi/nrf_wifi/inc/wifi_mgmt.h @@ -77,4 +77,7 @@ int nrf_wifi_set_rts_threshold(const struct device *dev, int nrf_wifi_get_rts_threshold(const struct device *dev, unsigned int *rts_threshold); + +int nrf_wifi_set_bss_max_idle_period(const struct device *dev, + unsigned short bss_max_idle_period); #endif /* __ZEPHYR_WIFI_MGMT_H__ */ diff --git a/drivers/wifi/nrf_wifi/src/fmac_main.c b/drivers/wifi/nrf_wifi/src/fmac_main.c index 379c3242b18..f2d9aa55af9 100644 --- a/drivers/wifi/nrf_wifi/src/fmac_main.c +++ b/drivers/wifi/nrf_wifi/src/fmac_main.c @@ -858,6 +858,9 @@ static int nrf_wifi_drv_main_zep(const struct device *dev) #endif /* CONFIG_NRF70_RADIO_TEST */ k_mutex_init(&rpu_drv_priv_zep.rpu_ctx_zep.rpu_lock); +#ifndef CONFIG_NRF70_RADIO_TEST + vif_ctx_zep->bss_max_idle_period = USHRT_MAX; +#endif /* !CONFIG_NRF70_RADIO_TEST */ return 0; #ifdef CONFIG_NRF70_RADIO_TEST fmac_deinit: @@ -885,6 +888,7 @@ static const struct wifi_mgmt_ops nrf_wifi_mgmt_ops = { .get_power_save_config = nrf_wifi_get_power_save_config, .set_rts_threshold = nrf_wifi_set_rts_threshold, .get_rts_threshold = nrf_wifi_get_rts_threshold, + .set_bss_max_idle_period = nrf_wifi_set_bss_max_idle_period, #endif #ifdef CONFIG_NRF70_SYSTEM_WITH_RAW_MODES .mode = nrf_wifi_mode, diff --git a/drivers/wifi/nrf_wifi/src/wifi_mgmt.c b/drivers/wifi/nrf_wifi/src/wifi_mgmt.c index a323faf21dd..e9755e80013 100644 --- a/drivers/wifi/nrf_wifi/src/wifi_mgmt.c +++ b/drivers/wifi/nrf_wifi/src/wifi_mgmt.c @@ -1077,3 +1077,56 @@ int nrf_wifi_get_rts_threshold(const struct device *dev, return ret; } + +int nrf_wifi_set_bss_max_idle_period(const struct device *dev, + unsigned short bss_max_idle_period) +{ + struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; + struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL; + int ret = -1; + + if (!dev) { + LOG_ERR("%s: dev is NULL", __func__); + return ret; + } + + vif_ctx_zep = dev->data; + + if (!vif_ctx_zep) { + LOG_ERR("%s: vif_ctx_zep is NULL", __func__); + return ret; + } + + rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; + + if (!rpu_ctx_zep) { + LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); + return ret; + } + + + if (!rpu_ctx_zep->rpu_ctx) { + LOG_ERR("%s: RPU context not initialized", __func__); + return ret; + } + + if (((int)bss_max_idle_period < 0) || + (bss_max_idle_period > 64000)) { + /* 0 or value less than 64000 is passed to f/w. + * All other values considered as invalid. + */ + LOG_ERR("%s: Invalid max_idle_period value : %d", + __func__, (int)bss_max_idle_period); + return ret; + } + + k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER); + + vif_ctx_zep->bss_max_idle_period = bss_max_idle_period; + + ret = 0; + + k_mutex_unlock(&vif_ctx_zep->vif_lock); + + return ret; +} diff --git a/drivers/wifi/nrf_wifi/src/wpa_supp_if.c b/drivers/wifi/nrf_wifi/src/wpa_supp_if.c index 34af00e6d38..21f7600ca80 100644 --- a/drivers/wifi/nrf_wifi/src/wpa_supp_if.c +++ b/drivers/wifi/nrf_wifi/src/wpa_supp_if.c @@ -931,8 +931,10 @@ int nrf_wifi_wpa_supp_associate(void *if_priv, struct wpa_driver_associate_param assoc_info.use_mfp = NRF_WIFI_MFP_REQUIRED; } - if (params->bss_max_idle_period) { - assoc_info.bss_max_idle_time = params->bss_max_idle_period; + if (vif_ctx_zep->bss_max_idle_period == USHRT_MAX) { + assoc_info.bss_max_idle_time = CONFIG_WIFI_MGMT_BSS_MAX_IDLE_TIME; + } else { + assoc_info.bss_max_idle_time = vif_ctx_zep->bss_max_idle_period; } assoc_info.conn_type = NRF_WIFI_CONN_TYPE_OPEN; diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 2c895afb36d..4232a88d955 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -133,6 +133,8 @@ enum net_request_wifi_cmd { NET_REQUEST_WIFI_CMD_CANDIDATE_SCAN, /** AP WPS config */ NET_REQUEST_WIFI_CMD_AP_WPS_CONFIG, + /** Configure BSS maximum idle period */ + NET_REQUEST_WIFI_CMD_BSS_MAX_IDLE_PERIOD, /** @cond INTERNAL_HIDDEN */ NET_REQUEST_WIFI_CMD_MAX /** @endcond */ @@ -317,6 +319,11 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_START_ROAMING); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_NEIGHBOR_REP_COMPLETE); +#define NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD \ + (NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_BSS_MAX_IDLE_PERIOD) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD); + /** @cond INTERNAL_HIDDEN */ enum { @@ -1588,6 +1595,15 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*start_11r_roaming)(const struct device *dev); + /** Set BSS max idle period + * + * @param dev Pointer to the device structure for the driver instance. + * @param BSS max idle period value + * + * @return 0 if ok, < 0 if error + */ + int (*set_bss_max_idle_period)(const struct device *dev, + unsigned short bss_max_idle_period); }; /** Wi-Fi management offload API */ diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index cde1ef95f47..3679808b3d4 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -1811,6 +1811,19 @@ int supplicant_legacy_roam(const struct device *dev) return ret; } +int supplicant_set_bss_max_idle_period(const struct device *dev, + unsigned short bss_max_idle_period) +{ + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev); + + if (!wifi_mgmt_api || !wifi_mgmt_api->set_bss_max_idle_period) { + wpa_printf(MSG_ERROR, "set_bss_max_idle_period is not supported"); + return -ENOTSUP; + } + + return wifi_mgmt_api->set_bss_max_idle_period(dev, bss_max_idle_period); +} + #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM int supplicant_btm_query(const struct device *dev, uint8_t reason) { diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index ddd3c3d6698..9d2b90b50fe 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -305,6 +305,14 @@ int supplicant_get_wifi_conn_params(const struct device *dev, */ int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params); +/** @ Set Wi-Fi max idle period + * + * @param dev Wi-Fi interface handle to use + * @param bss_max_idle_period Maximum idle period to set + * @return 0 for OK; -1 for ERROR + */ +int supplicant_set_bss_max_idle_period(const struct device *dev, + unsigned short bss_max_idle_period); #ifdef CONFIG_AP int set_ap_bandwidth(const struct device *dev, enum wifi_frequency_bandwidths bandwidth); diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index 4549ab3160d..9336cb2bf74 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -83,6 +83,7 @@ static const struct wifi_mgmt_ops mgmt_ops = { #endif .get_conn_params = supplicant_get_wifi_conn_params, .wps_config = supplicant_wps_config, + .set_bss_max_idle_period = supplicant_set_bss_max_idle_period, #ifdef CONFIG_AP .ap_enable = supplicant_ap_enable, .ap_disable = supplicant_ap_disable, diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 4b1d309066c..7728678cc97 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -154,3 +154,19 @@ config HEAP_MEM_POOL_ADD_SIZE_WIFI_CERT endif # WIFI_SHELL_RUNTIME_CERTIFICATES endif # WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE + +config WIFI_MGMT_BSS_MAX_IDLE_TIME + int "BSS max idle timeout in seconds" + range 0 64000 + default 30 + help + As per 802.11-2020: 11.21.13 BSS max idle period management + If dot11WirelessManagementImplemented is true, dot11BSSMaxIdlePeriod is + nonzero and dot11BSSMaxIdlePeriodIndicationByNonAPSTA is true, then a + non-S1G non-AP STA shall include a BSS Max Idle Period element + in the (Re)Association Request frame. If the BSS Max Idle Period + element is present in the (Re)Association Request frame received + by a non-S1G AP that has dot11BSSMaxIdlePeriodIndicationByNonAPSTA + equal to true, then the non-S1G AP may choose the non-AP STA’s + preferred maximum idle period. The non-S1G AP indicates its chosen + value to the non-S1G STA in the (Re)Association Response frame. diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 0183faab1d5..f16f2581374 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -1403,6 +1403,31 @@ static int wifi_set_enterprise_creds(uint64_t mgmt_request, struct net_if *iface NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_ENTERPRISE_CREDS, wifi_set_enterprise_creds); #endif +static int wifi_set_bss_max_idle_period(uint64_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); + unsigned short *bss_max_idle_period = data; + + if (wifi_mgmt_api == NULL || wifi_mgmt_api->set_bss_max_idle_period == NULL) { + return -ENOTSUP; + } + + if (!net_if_is_admin_up(iface)) { + return -ENETDOWN; + } + + if (!data || len != sizeof(*bss_max_idle_period)) { + return -EINVAL; + } + + return wifi_mgmt_api->set_bss_max_idle_period(dev, *bss_max_idle_period); +} + +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD, + wifi_set_bss_max_idle_period); + #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 8a5468ba81b..b23d407da64 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -3455,6 +3455,32 @@ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[ return 0; } + +static int cmd_wifi_set_bss_max_idle_period(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface = get_iface(IFACE_TYPE_STA, argc, argv); + unsigned short bss_max_idle_period = 0; + int idx = 1; + unsigned long val = 0; + + if (!parse_number(sh, &val, argv[idx++], "bss_max_idle_period", 0, USHRT_MAX)) { + return -EINVAL; + } + + bss_max_idle_period = (unsigned short)val; + + if (net_mgmt(NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD, iface, + &bss_max_idle_period, sizeof(bss_max_idle_period))) { + shell_fprintf(sh, SHELL_WARNING, + "Setting BSS maximum idle period failed.\n"); + return -ENOEXEC; + } + + shell_fprintf(sh, SHELL_NORMAL, "BSS max idle period: %hu\n", bss_max_idle_period); + + return 0; +} + SHELL_STATIC_SUBCMD_SET_CREATE( wifi_cmd_ap, SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n" @@ -3930,6 +3956,12 @@ SHELL_SUBCMD_ADD((wifi), ps_exit_strategy, NULL, cmd_wifi_ps_exit_strategy, 2, 2); +SHELL_SUBCMD_ADD((wifi), bss_max_idle_period, NULL, + ".\n" + "[-i, --iface=] : Interface index.\n", + cmd_wifi_set_bss_max_idle_period, + 2, 2); + SHELL_CMD_REGISTER(wifi, &wifi_commands, "Wi-Fi commands", NULL); static int wifi_shell_init(void) From 8277731e86e2d7bab82d1ac72c8419c583a7bf3b Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 31 Jul 2025 17:40:48 +0530 Subject: [PATCH 32/42] [nrf fromtree] net: l2: wifi: Fix the default keepalive value 30s is too aggressive for most APs, and hostapd also uses 5mins as the default value. Signed-off-by: Chaitanya Tata (cherry picked from commit 59ff12656ff93fd2568bc3013073edbe1eb65e98) Signed-off-by: Robert Lubos --- subsys/net/l2/wifi/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 7728678cc97..49d061c7439 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -158,7 +158,7 @@ endif # WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE config WIFI_MGMT_BSS_MAX_IDLE_TIME int "BSS max idle timeout in seconds" range 0 64000 - default 30 + default 300 help As per 802.11-2020: 11.21.13 BSS max idle period management If dot11WirelessManagementImplemented is true, dot11BSSMaxIdlePeriod is From 39a962774d40381bdd99f94f7efa14c102035434 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Tue, 5 Aug 2025 06:19:02 +0000 Subject: [PATCH 33/42] [nrf fromlist] drivers: nrf_wifi: Add check for minimum RX buffer size Add check for the RX data buffer size. It should be atleast 400 bytes, anthing less than that scan fails. Upstream PR #: 94106 Signed-off-by: Kapil Bhatt --- drivers/wifi/nrf_wifi/src/fmac_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/wifi/nrf_wifi/src/fmac_main.c b/drivers/wifi/nrf_wifi/src/fmac_main.c index f2d9aa55af9..125ffd7a9a1 100644 --- a/drivers/wifi/nrf_wifi/src/fmac_main.c +++ b/drivers/wifi/nrf_wifi/src/fmac_main.c @@ -79,6 +79,8 @@ BUILD_ASSERT(CONFIG_NRF70_TX_MAX_DATA_SIZE % 4 == 0, "TX buffer size must be a multiple of 4"); BUILD_ASSERT(CONFIG_NRF70_RX_MAX_DATA_SIZE % 4 == 0, "RX buffer size must be a multiple of 4"); +BUILD_ASSERT(CONFIG_NRF70_RX_MAX_DATA_SIZE >= 400, + "RX buffer size must be at least 400 bytes"); static const unsigned char aggregation = 1; static const unsigned char max_num_tx_agg_sessions = 4; From 2c900ff71beb178c58b4d0f295e003bfbce94da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Thu, 5 Jun 2025 15:48:25 +0200 Subject: [PATCH 34/42] [nrf fromtree] Bluetooth: Host: Update LE legacy pairing check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates the LE legacy pairing procedure as a result of errata ES-24491. New part: If the initiating device receives an LP_CONFIRM_R value that is equal to the LP_CONFIRM_I value, the pairing process shall be aborted and fail with "Confirm Value Failed" as reason. Signed-off-by: Håvard Reierstad (cherry picked from commit 2a8118c9454542119e9d06c49093e77da609a3ab) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/host/smp.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 916bb661bb9..805b18f33c4 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -2555,22 +2555,35 @@ static uint8_t legacy_pairing_req(struct bt_smp *smp) static uint8_t legacy_pairing_random(struct bt_smp *smp) { struct bt_conn *conn = smp->chan.chan.conn; - uint8_t tmp[16]; + uint8_t tmp[16], cfm_i[16]; int err; LOG_DBG(""); - /* calculate confirmation */ + /* calculate LP_CONFIRM_R */ err = smp_c1(smp->tk, smp->rrnd, smp->preq, smp->prsp, &conn->le.init_addr, &conn->le.resp_addr, tmp); if (err) { return BT_SMP_ERR_UNSPECIFIED; } + /* calculate LP_CONFIRM_I */ + err = smp_c1(smp->tk, smp->prnd, smp->preq, smp->prsp, + &conn->le.init_addr, &conn->le.resp_addr, cfm_i); + if (err) { + return BT_SMP_ERR_UNSPECIFIED; + } + LOG_DBG("pcnf %s", bt_hex(smp->pcnf, 16)); - LOG_DBG("cfm %s", bt_hex(tmp, 16)); + LOG_DBG("cfm (remote) %s", bt_hex(tmp, 16)); + LOG_DBG("cfm (local) %s", bt_hex(cfm_i, 16)); - if (memcmp(smp->pcnf, tmp, sizeof(smp->pcnf))) { + /* Core Specification, Vol 3, Part H, section 2.3.5.5 (Errata ES-24491): If the computed + * LP_CONFIRM_R value is not equal to the received LP_CONFIRM_R value, or the received + * LP_CONFIRM_R value is equal to the LP_CONFIRM_I value, fail pairing. + */ + if (memcmp(smp->pcnf, tmp, sizeof(smp->pcnf)) || + !memcmp(smp->pcnf, cfm_i, sizeof(smp->pcnf))) { return BT_SMP_ERR_CONFIRM_FAILED; } From 8720fcc41232657f771b09ec1627b1bbc279d471 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 11 Jun 2025 16:59:55 +0200 Subject: [PATCH 35/42] [nrf fromtree] Bluetooth: Host: Fix SMP Pairing failed code on invalid Public Key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Core Specification 6.1 clarified exptected erro code in case peer sending invalid Public Key. In case pairing is aborted during or immediately after Public Key Exchange phase has completed (which is the case here) expected reason code is set to "DHKey Check Failed". This was affecting SM/CEN/KDU/BI-04-C and SM/PER/KDU/BI-04-C qualification test cases. Signed-off-by: Szymon Janc (cherry picked from commit 9b27a472f42e92fc290915e7529e1e9e91631a7b) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/host/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 805b18f33c4..ff920fb0f3a 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -4499,7 +4499,7 @@ static uint8_t smp_public_key(struct bt_smp *smp, struct net_buf *buf) } } else if (!bt_pub_key_is_valid(smp->pkey)) { LOG_WRN("Received invalid public key"); - return BT_SMP_ERR_INVALID_PARAMS; + return BT_SMP_ERR_DHKEY_CHECK_FAILED; } if (IS_ENABLED(CONFIG_BT_CENTRAL) && From 57d8acee344a9fcc77116a02cee99624a548bf9a Mon Sep 17 00:00:00 2001 From: Nirav Agrawal Date: Fri, 13 Jun 2025 10:44:29 +0530 Subject: [PATCH 36/42] [nrf fromtree] bluetooth: host: gatt: fix null-ptr access if no include-svc userdata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Issue: There is a bus-fault while accessing empty userdata structure pointer if application does not include any include service userdata instance (which consist of UUID list of included service) but service array has defined dummy entry for it assumed to be overridden by app during initial flow. - For example, the issue has happened in case of tmap-central sample without "CONFIG_BT_OTS" support. there are some MCS attributes dependent on OTS service because of that "BT_GATT_INCLUDE_SERVICE(NULL)" entry is added as part of service definition. The given entry does not have userdata handler defined and is expecting to be overriden by the app if it will be included. During "bt_mcs_init()" call, "mcs.attrs[i].user_data" is not populated with any attr-instance pointer. This makes CPU to access null-address during reading local-database include-service attribute which was not provided by the app but the include-service entry was added to the db. - Fix: Adding condition to check if user-data has null address, and returning back to avoid any hard-faults. Signed-off-by: Nirav Agrawal (cherry picked from commit 5a8189bf2afec221b925065854a714b1088ccddc) Signed-off-by: Håvard Reierstad --- include/zephyr/bluetooth/gatt.h | 1 + subsys/bluetooth/host/gatt.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/zephyr/bluetooth/gatt.h b/include/zephyr/bluetooth/gatt.h index 3597c7c5fdb..2c7d36a6758 100644 --- a/include/zephyr/bluetooth/gatt.h +++ b/include/zephyr/bluetooth/gatt.h @@ -918,6 +918,7 @@ ssize_t bt_gatt_attr_read_service(struct bt_conn *conn, * Read include service attribute value from local database storing the result * into buffer after encoding it. * @note Only use this with attributes which user_data is a ``bt_gatt_include``. + * The function returns EINVAL if @p attr or @p attr->user_data is NULL. * * @param conn Connection object. * @param attr Attribute to read. diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 3092801554a..be642fec9fe 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -1917,6 +1917,10 @@ ssize_t bt_gatt_attr_read_included(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { + if ((attr == NULL) || (attr->user_data == NULL)) { + return -EINVAL; + } + struct bt_gatt_attr *incl = attr->user_data; uint16_t handle = bt_gatt_attr_get_handle(incl); struct bt_uuid *uuid = incl->user_data; From 01ec0ff5bd167631bc8078b88ac1767f9ac6d866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Tue, 15 Jul 2025 07:43:33 +0200 Subject: [PATCH 37/42] [nrf fromtree] Bluetooth: Host: l2cap: Fix MPS/MTU confusion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The implementation used BT_L2CAP_ECRED_MIN_MTU to check the lower limits of both MTU and MPS, instead of BT_L2CAP_ECRED_MIN_MPS for MPS. While these are the same here, confusion may arise. This commit fixes the confusion. Signed-off-by: Håvard Reierstad (cherry picked from commit d989188f29e6d19c9b7ec0458becc868632d939b) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/host/l2cap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 9fa5638d961..ac3bd8eeb2b 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -46,6 +46,7 @@ LOG_MODULE_REGISTER(bt_l2cap, CONFIG_BT_L2CAP_LOG_LEVEL); #define CHAN_RX(_w) CONTAINER_OF(_w, struct bt_l2cap_le_chan, rx_work) #define L2CAP_LE_MIN_MTU 23 +#define L2CAP_LE_MIN_MPS 23 #define L2CAP_LE_MAX_CREDITS (BT_BUF_ACL_RX_COUNT - 1) @@ -1478,7 +1479,7 @@ static void le_conn_req(struct bt_l2cap *l2cap, uint8_t ident, LOG_DBG("psm 0x%02x scid 0x%04x mtu %u mps %u credits %u", psm, scid, mtu, mps, credits); - if (mtu < L2CAP_LE_MIN_MTU || mps < L2CAP_LE_MIN_MTU) { + if (mtu < L2CAP_LE_MIN_MTU || mps < L2CAP_LE_MIN_MPS) { LOG_ERR("Invalid LE-Conn Req params: mtu %u mps %u", mtu, mps); return; } @@ -1577,7 +1578,7 @@ static void le_ecred_conn_req(struct bt_l2cap *l2cap, uint8_t ident, LOG_DBG("psm 0x%02x mtu %u mps %u credits %u", psm, mtu, mps, credits); - if (mtu < BT_L2CAP_ECRED_MIN_MTU || mps < BT_L2CAP_ECRED_MIN_MTU) { + if (mtu < BT_L2CAP_ECRED_MIN_MTU || mps < BT_L2CAP_ECRED_MIN_MPS) { LOG_ERR("Invalid ecred conn req params. mtu %u mps %u", mtu, mps); result = BT_L2CAP_LE_ERR_INVALID_PARAMS; goto response; @@ -1685,7 +1686,7 @@ static void le_ecred_reconf_req(struct bt_l2cap *l2cap, uint8_t ident, mtu = sys_le16_to_cpu(req->mtu); mps = sys_le16_to_cpu(req->mps); - if (mps < BT_L2CAP_ECRED_MIN_MTU) { + if (mps < BT_L2CAP_ECRED_MIN_MPS) { result = BT_L2CAP_RECONF_OTHER_UNACCEPT; goto response; } From b07b1bba4aec25dc602f00301a2a8ed72bc4b0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Tue, 22 Jul 2025 13:25:11 +0200 Subject: [PATCH 38/42] [nrf fromtree] Bluetooth: Host: Add l2cap credit param checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a missing requirement from Core Spec V6.0 Vol 3.A chapters 10.1 and 10.2 to ignore L2CAP_FLOW_CONTROL_CREDIT_IND packets with the credit value set to 0. Matches existing credit-related functions by checking that the CID is in the dynamic range (you can't add credits to fixed channels). Signed-off-by: Håvard Reierstad (cherry picked from commit 2b42a1d81d981d55e0a5c6e3cd96caee13b195ea) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/host/l2cap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index ac3bd8eeb2b..9ecdc72c0aa 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -2158,6 +2158,17 @@ static void le_credits(struct bt_l2cap *l2cap, uint8_t ident, cid = sys_le16_to_cpu(ev->cid); credits = sys_le16_to_cpu(ev->credits); + if (!L2CAP_LE_CID_IS_DYN(cid)) { + LOG_WRN("Can't add credits to non-dynamic channel %p (cid 0x%04x)", &l2cap->chan, + cid); + return; + } + + if (credits == 0U) { + LOG_WRN("Ignoring zero credit packet"); + return; + } + LOG_DBG("cid 0x%04x credits %u", cid, credits); chan = bt_l2cap_le_lookup_tx_cid(conn, cid); From 4c976e3ff28fceec1203f5a86cd5399675795f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Wed, 16 Jul 2025 08:55:06 +0200 Subject: [PATCH 39/42] [nrf fromtree] Bluetooth: Host: Add conn rsp param check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check whether the connection response parameters both with and without ECRED are within the valid ranges from the Bluetooth Core Specification (part 3.A.4 v6.0). Changes validation checks in requests to match the same pattern. Signed-off-by: Håvard Reierstad (cherry picked from commit 7debc8a8f53d4832dfc9cd4dd9debff3d8648079) Signed-off-by: Håvard Reierstad --- include/zephyr/bluetooth/l2cap.h | 14 +++++++ subsys/bluetooth/host/l2cap.c | 52 +++++++++++++++++++++----- subsys/bluetooth/host/l2cap_internal.h | 3 ++ 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/include/zephyr/bluetooth/l2cap.h b/include/zephyr/bluetooth/l2cap.h index f8781d791f0..380b52ad508 100644 --- a/include/zephyr/bluetooth/l2cap.h +++ b/include/zephyr/bluetooth/l2cap.h @@ -111,6 +111,20 @@ extern "C" { */ #define BT_L2CAP_ECRED_MIN_MPS 64 +/** @brief L2CAP maximum MTU + * + * The maximum MTU for an L2CAP Based Connection. This is the same with or without ECRED. This + * requirement is taken from text in Core 3.A.4.22 and 3.A.4.26 v6.0. + */ +#define BT_L2CAP_MAX_MTU UINT16_MAX + +/** @brief L2CAP maximum MPS + * + * The maximum MPS for an L2CAP Based Connection. This is the same with or without ECRED. This + * requirement is taken from text in Core 3.A.4.22 and 3.A.4.26 v6.0. + */ +#define BT_L2CAP_MAX_MPS 65533 + /** @brief The maximum number of channels in ECRED L2CAP signaling PDUs * * Currently, this is the maximum number of channels referred to in the diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 9ecdc72c0aa..caf5424717b 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -1479,11 +1479,6 @@ static void le_conn_req(struct bt_l2cap *l2cap, uint8_t ident, LOG_DBG("psm 0x%02x scid 0x%04x mtu %u mps %u credits %u", psm, scid, mtu, mps, credits); - if (mtu < L2CAP_LE_MIN_MTU || mps < L2CAP_LE_MIN_MPS) { - LOG_ERR("Invalid LE-Conn Req params: mtu %u mps %u", mtu, mps); - return; - } - buf = l2cap_create_le_sig_pdu(BT_L2CAP_LE_CONN_RSP, ident, sizeof(*rsp)); if (!buf) { @@ -1493,6 +1488,16 @@ static void le_conn_req(struct bt_l2cap *l2cap, uint8_t ident, rsp = net_buf_add(buf, sizeof(*rsp)); (void)memset(rsp, 0, sizeof(*rsp)); + /* Validate parameters. Requirements are from Core Spec v6.0, Vol 3.A.4.22. Valid credit + * range is from 0 to UINT16_MAX, thus no credit validation is needed. + */ + if (!IN_RANGE(mtu, L2CAP_LE_MIN_MTU, BT_L2CAP_MAX_MTU) || + !IN_RANGE(mps, L2CAP_LE_MIN_MPS, BT_L2CAP_MAX_MPS)) { + LOG_ERR("Invalid le conn req params: mtu %u mps %u", mtu, mps); + result = BT_L2CAP_LE_ERR_UNACCEPT_PARAMS; + goto rsp; + } + /* Check if there is a server registered */ server = bt_l2cap_server_lookup_psm(psm); if (!server) { @@ -1578,8 +1583,12 @@ static void le_ecred_conn_req(struct bt_l2cap *l2cap, uint8_t ident, LOG_DBG("psm 0x%02x mtu %u mps %u credits %u", psm, mtu, mps, credits); - if (mtu < BT_L2CAP_ECRED_MIN_MTU || mps < BT_L2CAP_ECRED_MIN_MPS) { - LOG_ERR("Invalid ecred conn req params. mtu %u mps %u", mtu, mps); + /* Validate parameters. Requirements are from Core Spec v6.0, Vol 3.A.4.25. */ + if (!IN_RANGE(mtu, BT_L2CAP_ECRED_MIN_MTU, BT_L2CAP_MAX_MTU) || + !IN_RANGE(mps, BT_L2CAP_ECRED_MIN_MPS, BT_L2CAP_MAX_MPS) || + !IN_RANGE(credits, BT_L2CAP_ECRED_CREDITS_MIN, BT_L2CAP_ECRED_CREDITS_MAX)) { + LOG_ERR("Invalid le ecred conn req params: mtu %u mps %u credits %u", mtu, mps, + credits); result = BT_L2CAP_LE_ERR_INVALID_PARAMS; goto response; } @@ -1982,13 +1991,24 @@ static void le_ecred_conn_rsp(struct bt_l2cap *l2cap, uint8_t ident, LOG_DBG("dcid 0x%04x", dcid); - /* If a Destination CID is 0x0000, the channel was not + /* Validate parameters before assignment. Requirements are from Core Spec + * v6.0, Vol 3.A.4.26. If a Destination CID is 0x0000, the channel was not * established. */ - if (!dcid) { + if (dcid == 0U) { bt_l2cap_chan_remove(conn, &chan->chan); bt_l2cap_chan_del(&chan->chan); continue; + } else if (!L2CAP_LE_CID_IS_DYN(dcid) || + !IN_RANGE(mtu, BT_L2CAP_ECRED_MIN_MTU, BT_L2CAP_MAX_MTU) || + !IN_RANGE(mps, BT_L2CAP_ECRED_MIN_MPS, BT_L2CAP_MAX_MPS) || + !IN_RANGE(credits, BT_L2CAP_ECRED_CREDITS_MIN, + BT_L2CAP_ECRED_CREDITS_MAX)) { + LOG_WRN("Invalid ecred conn rsp params: dcid 0x%04x mtu %u mps %u " + "credits %u. Disconnecting.", + dcid, mtu, mps, credits); + bt_conn_disconnect(conn, BT_HCI_ERR_UNACCEPT_CONN_PARAM); + return; } c = bt_l2cap_le_lookup_tx_cid(conn, dcid); @@ -2086,6 +2106,20 @@ static void le_conn_rsp(struct bt_l2cap *l2cap, uint8_t ident, switch (result) { case BT_L2CAP_LE_SUCCESS: + /* Validate parameters on successful connection. Requirements are from Core Spec + * v6.0, Vol 3.A.4.23. Valid credit range is from 0 to UINT16_MAX, thus no credit + * validation is needed. + */ + if ((!L2CAP_LE_CID_IS_DYN(dcid) || + !IN_RANGE(mtu, L2CAP_LE_MIN_MTU, BT_L2CAP_MAX_MTU) || + !IN_RANGE(mps, L2CAP_LE_MIN_MPS, BT_L2CAP_MAX_MPS))) { + LOG_WRN("Invalid conn rsp params: dcid 0x%04x mtu %u mps %u. " + "Disconnecting.", + dcid, mtu, mps); + bt_conn_disconnect(conn, BT_HCI_ERR_UNACCEPT_CONN_PARAM); + return; + } + chan->tx.cid = dcid; chan->tx.mtu = mtu; chan->tx.mps = mps; diff --git a/subsys/bluetooth/host/l2cap_internal.h b/subsys/bluetooth/host/l2cap_internal.h index 07bd428334a..61fa7416dd5 100644 --- a/subsys/bluetooth/host/l2cap_internal.h +++ b/subsys/bluetooth/host/l2cap_internal.h @@ -125,6 +125,9 @@ struct bt_l2cap_le_credits { uint16_t credits; } __packed; +#define BT_L2CAP_ECRED_CREDITS_MIN 1 +#define BT_L2CAP_ECRED_CREDITS_MAX UINT16_MAX + #define BT_L2CAP_ECRED_CONN_REQ 0x17 struct bt_l2cap_ecred_conn_req { uint16_t psm; From 7de47337d2a38ff9e5221986072ce1e8c9f6aaaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Tue, 22 Jul 2025 09:56:14 +0200 Subject: [PATCH 40/42] [nrf fromtree] Bluetooth: Host: Use MTU min for l2cap test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The many_conn l2cap test used a MTU lower than the minimum permitted value. This commit bumps it to the minimum (23). Signed-off-by: Håvard Reierstad (cherry picked from commit b799d1897b9695d4bea7d985509a6621ab9dcd85) Signed-off-by: Håvard Reierstad --- tests/bsim/bluetooth/host/l2cap/many_conns/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bsim/bluetooth/host/l2cap/many_conns/src/main.c b/tests/bsim/bluetooth/host/l2cap/many_conns/src/main.c index ff9f3030d1e..a4f45bc1890 100644 --- a/tests/bsim/bluetooth/host/l2cap/many_conns/src/main.c +++ b/tests/bsim/bluetooth/host/l2cap/many_conns/src/main.c @@ -29,7 +29,7 @@ DEFINE_FLAG_STATIC(flag_l2cap_connected); #define NUM_PERIPHERALS CONFIG_BT_MAX_CONN #define L2CAP_CHANS NUM_PERIPHERALS #define SDU_NUM 1 -#define SDU_LEN 10 +#define SDU_LEN 23 /* Only one SDU per link will be transmitted */ NET_BUF_POOL_DEFINE(sdu_tx_pool, From 7d913ca2a706b2f2a49e8c9e8c80178cf2ef0539 Mon Sep 17 00:00:00 2001 From: Jonathan Nilsen Date: Mon, 4 Aug 2025 12:08:04 +0200 Subject: [PATCH 41/42] [nrf fromlist] soc: nordic: uicr: Populate UICR.VERSION field in gen_uicr.py Upstream PR #: 94064 Set the VERSION field to 2.0 in gen_uicr.py to indicate the version of the format the script produces blobs for. This is required for forwards compatibility with newer versions of IronSide SE. Signed-off-by: Jonathan Nilsen --- soc/nordic/common/uicr/gen_uicr.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/soc/nordic/common/uicr/gen_uicr.py b/soc/nordic/common/uicr/gen_uicr.py index 50f96eab566..5888786e928 100644 --- a/soc/nordic/common/uicr/gen_uicr.py +++ b/soc/nordic/common/uicr/gen_uicr.py @@ -17,6 +17,10 @@ from elftools.elf.elffile import ELFFile from intelhex import IntelHex +# The UICR format version produced by this script +UICR_FORMAT_VERSION_MAJOR = 2 +UICR_FORMAT_VERSION_MINOR = 0 + # Name of the ELF section containing PERIPHCONF entries. # Must match the name used in the linker script. PERIPHCONF_SECTION = "uicr_periphconf_entry" @@ -45,6 +49,14 @@ class PeriphconfEntry(c.LittleEndianStructure): PERIPHCONF_ENTRY_SIZE = c.sizeof(PeriphconfEntry) +class Version(c.LittleEndianStructure): + _pack_ = 1 + _fields_ = [ + ("MINOR", c.c_uint16), + ("MAJOR", c.c_uint16), + ] + + class Approtect(c.LittleEndianStructure): _pack_ = 1 _fields_ = [ @@ -104,7 +116,7 @@ class Mpcconf(c.LittleEndianStructure): class Uicr(c.LittleEndianStructure): _pack_ = 1 _fields_ = [ - ("VERSION", c.c_uint32), + ("VERSION", Version), ("RESERVED", c.c_uint32), ("LOCK", c.c_uint32), ("RESERVED1", c.c_uint32), @@ -171,6 +183,9 @@ def main() -> None: init_values = DISABLED_VALUE.to_bytes(4, "little") * (c.sizeof(Uicr) // 4) uicr = Uicr.from_buffer_copy(init_values) + uicr.VERSION.MAJOR = UICR_FORMAT_VERSION_MAJOR + uicr.VERSION.MINOR = UICR_FORMAT_VERSION_MINOR + kconfig_str = args.in_config.read() kconfig = parse_kconfig(kconfig_str) From b1ea2f92af0a0c173772440ae2be9859db693d5f Mon Sep 17 00:00:00 2001 From: Sebastian Wezel Date: Wed, 6 Aug 2025 13:26:50 +0200 Subject: [PATCH 42/42] [nrf noup] ci: enable custom brase for manifest-PR new arg base-branch defaults to main, but can map zephyr release branch to nrf release base Signed-off-by: Sebastian Wezel --- .github/workflows/manifest-PR.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/manifest-PR.yml b/.github/workflows/manifest-PR.yml index a871aa381de..8f834b99f72 100644 --- a/.github/workflows/manifest-PR.yml +++ b/.github/workflows/manifest-PR.yml @@ -3,7 +3,7 @@ on: pull_request_target: types: [opened, synchronize, closed] branches: - - main + - ncs-v3.1-branch jobs: @@ -15,3 +15,4 @@ jobs: with: token: ${{ secrets.NCS_GITHUB_TOKEN }} manifest-pr-title-details: ${{ github.event.pull_request.title }} + base-branch: v3.1-branch