Skip to content

coexistence: fix protocol switch back to Zigbee#122

Merged
edmont merged 2 commits into
nrfconnect:mainfrom
edmont:pr/fix-switch-back
Jul 14, 2026
Merged

coexistence: fix protocol switch back to Zigbee#122
edmont merged 2 commits into
nrfconnect:mainfrom
edmont:pr/fix-switch-back

Conversation

@edmont

@edmont edmont commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

A bus fault in the openthread thread was triggered when InitThreadStack() auto-started the radio stack while Zigbee still owned the 802.15.4 radio. Disable CHIP_DEVICE_CONFIG_ENABLE_THREAD_AUTOSTART via a CMake compile definition so OpenThread never starts autonomously; the coexistence runtime starts Thread explicitly once the radio dispatcher is handed over.

On the Matter→Zigbee switch, kill ZBOSS only after sending a clean NWK Leave so the coordinator removes the device's unique TCLK entry. This prevents the fresh-join TCLK mismatch that caused the coordinator to fail the Transport-Key delivery after the next reboot.

@edmont
edmont requested a review from a team as a code owner July 8, 2026 06:56
@edmont
edmont force-pushed the pr/fix-switch-back branch from 94036db to 8f8db7c Compare July 8, 2026 10:21
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Documentation Preview

The documentation has been built successfully. You can view the preview here: preview

Generated at: 2026-07-13 09:21:20 UTC with commit 56a715e.

Expand to view changed pages

No documentation files were changed in this PR.


Note: The preview will be available after GitHub Pages deployment completes (usually 1-2 minutes). Ensure that generated at timestamp is up to date. If the Pull Request is stale for more than 30 days, the preview may be deleted. In this case, please update the Pull Request, or re-run the Build Documentation workflow to generate a new preview.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the Zigbee↔Matter coexistence runtime to prevent OpenThread from starting while Zigbee owns the 802.15.4 radio, and improves the Matter→Zigbee→Matter switch path by ensuring a clean Zigbee NWK Leave before tearing down ZBOSS (to avoid TCLK mismatch on re-join).

Changes:

  • Disables OpenThread autostart at build time and adds explicit “start Thread if commissioned” logic after radio handover.
  • Adds pre-/post-Matter-server-init hooks to safely switch the 802.15.4 callbacks dispatcher during InitThreadStack() / StartServer().
  • Defers Matter switch until ZBOSS sends a NWK Leave, wiring the leave completion signal through the sample.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
subsys/lib/zigbee_matter_coexistence/Kconfig Updates help text to reflect new signaling path.
subsys/lib/zigbee_matter_coexistence/coexistence.cpp Adds dispatcher handover hooks, explicit Thread start, and Zigbee leave gating before switch.
subsys/lib/zigbee_matter_coexistence/CMakeLists.txt Forces CHIP_DEVICE_CONFIG_ENABLE_THREAD_AUTOSTART=0 for coexistence builds.
samples/light_switch/src/app_task_zigbee.c Forwards ZBOSS leave completion to coexistence runtime.
samples/light_switch/src/app_task_matter.cpp Integrates new pre-/post-server-init coexistence hooks.
samples/light_bulb/src/app_task_matter.cpp Integrates new pre-/post-server-init coexistence hooks.
include/zigbee/matter_coexistence.h Updates/extends public coexistence API for new integration flow and leave signaling.
docs/includes/matter_extension_protocol_switch.txt Documents new integration call sites and behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread samples/light_switch/src/app_task_matter.cpp Outdated
Comment thread samples/light_bulb/src/app_task_matter.cpp Outdated
Comment thread docs/includes/matter_extension_protocol_switch.txt Outdated
Comment thread subsys/lib/zigbee_matter_coexistence/coexistence.cpp
Comment thread subsys/lib/zigbee_matter_coexistence/coexistence.cpp
Comment thread subsys/lib/zigbee_matter_coexistence/coexistence.cpp
@edmont
edmont force-pushed the pr/fix-switch-back branch from b5a426d to 8fc6a59 Compare July 8, 2026 14:03
@edmont

edmont commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed Copilot comments.

@ArekBalysNordic ArekBalysNordic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments to improve semaphors in coexistence.

I think we should do a similar thing for app_task_zigbee in the light bulb.
For example in the line 594 as:

#ifdef CONFIG_ZIGBEE_MATTER_COEXISTENCE
  if (bufid) {
    zb_zdo_app_signal_hdr_t *sig_handler = nullptr;
    zb_zdo_app_signal_type_t sig = zb_get_app_signal(bufid, &sig_handler);
    if (sig == ZB_ZDO_SIGNAL_LEAVE &&
        ZB_ZDO_APP_SIGNAL_STATUS(sig_handler) == RET_OK) {
      zb_zdo_signal_leave_params_t *leave_params =
          ZB_ZDO_SIGNAL_GET_PARAMS(sig_handler, zb_zdo_signal_leave_params_t);
      if (leave_params->leave_type == ZB_NWK_LEAVE_TYPE_RESET) {
        /* Unblock a pending Matter switch deferred until Leave completes. */
        zigbee_matter_coexistence_on_zboss_leave_signal();
      }
    }
  }
#endif
  ZB_ERROR_CHECK(zigbee_default_signal_handler(bufid));
``

To reflect the same case as for light switch.

Comment thread include/zigbee/matter_coexistence.h Outdated
Comment thread subsys/lib/zigbee_matter_coexistence/coexistence.cpp
Comment thread subsys/lib/zigbee_matter_coexistence/coexistence.cpp
@edmont
edmont force-pushed the pr/fix-switch-back branch from 8fc6a59 to f6e76da Compare July 10, 2026 12:03

@annwoj annwoj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one minor suggestion

Comment thread docs/includes/matter_extension_protocol_switch.txt Outdated
edmont added 2 commits July 13, 2026 11:19
A bus fault in the openthread thread was triggered when InitThreadStack()
auto-started the radio stack while Zigbee still owned the 802.15.4 radio.
Disable CHIP_DEVICE_CONFIG_ENABLE_THREAD_AUTOSTART via a CMake compile
definition so OpenThread never starts autonomously; the coexistence runtime
starts Thread explicitly once the radio dispatcher is handed over.

On the Matter→Zigbee switch, kill ZBOSS only after sending a clean NWK
Leave so the coordinator removes the device's unique TCLK entry.  This
prevents the fresh-join TCLK mismatch that caused the coordinator to
fail the Transport-Key delivery after the next reboot.

Introduce zigbee_matter_coexistence_on_server_started() as the single
entry point that samples call unconditionally after StartServer().  It
encapsulates the BT_ADV_WHILE_ZIGBEE/FabricCount branching that was
previously duplicated in every sample's AppTask::Init().

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Add zigbee_matter_coexistence_handle_zboss_signal() so samples forward
bufid before the default handler instead of duplicating leave parsing.
Wire the helper into the light bulb and light switch samples.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
@edmont
edmont force-pushed the pr/fix-switch-back branch from f6e76da to 56a715e Compare July 13, 2026 09:19
@edmont
edmont requested a review from ArekBalysNordic July 13, 2026 09:21
@edmont

edmont commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

I think we should do a similar thing for app_task_zigbee in the light bulb.

I've moved the checks to the coex module. See coexistence: centralize ZBOSS leave signal handling commit.

@edmont
edmont merged commit 0059150 into nrfconnect:main Jul 14, 2026
7 checks passed
@edmont
edmont deleted the pr/fix-switch-back branch July 14, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants