Skip to content

openthread: Fix OpenThread independence from Zephyr network. #90861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ArekBalysNordic
Copy link
Contributor

@ArekBalysNordic ArekBalysNordic commented May 30, 2025

If CONFIG_OPENTHREAD_SYS_INIT is enabled, OpenThread initialisation should also consider running OpenThread automatically if CONFIG_OPENTHREAD_MANUAL_START is disabled.

Removed also dependency on the net_bytes_from_str functions from the openthread.h file. Now, in the OpenThread module, there is an additional openthread_utils.c/.h file that can implement useful utilities for the OpenThread platform. Currently, it implements the bytes_from_str function to use it instead of net_bytes_from_str.

@ArekBalysNordic
Copy link
Contributor Author

Hi @nashif, could this change: #90856 cause errors in this PR?

I can see errors like:
Build failure - error: 'PTHREAD_STACK_MIN' undeclared

Copy link
Collaborator

@rlubos rlubos left a comment

Choose a reason for hiding this comment

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

In the commit message you wrote:

If CONFIG_OPENTHREAD_SYS_INIT is enabled, OpenThread initialisation
should also consider running OpenThread automatically if
CONFIG_OPENTHREAD_MANUAL_START is enabled

Did you mean "if CONFIG_OPENTHREAD_MANUAL_START is disabled"? That's what's implemented and what actually makes sense.

Otherwise LGTM

@ArekBalysNordic
Copy link
Contributor Author

In the commit message you wrote:

If CONFIG_OPENTHREAD_SYS_INIT is enabled, OpenThread initialisation
should also consider running OpenThread automatically if
CONFIG_OPENTHREAD_MANUAL_START is enabled

Did you mean "if CONFIG_OPENTHREAD_MANUAL_START is disabled"? That's what's implemented and what actually makes sense.

Otherwise LGTM

Right! I'm fixing the description. :)

@ArekBalysNordic ArekBalysNordic force-pushed the openthread_without_net branch from df92ae5 to a7a0221 Compare May 30, 2025 12:19
@ArekBalysNordic ArekBalysNordic force-pushed the openthread_without_net branch from a7a0221 to 19ee59b Compare May 30, 2025 12:54
rlubos
rlubos previously approved these changes May 30, 2025
@ArekBalysNordic ArekBalysNordic force-pushed the openthread_without_net branch 2 times, most recently from f965d0a to fb7f533 Compare May 30, 2025 13:10
@ArekBalysNordic ArekBalysNordic requested a review from rlubos May 30, 2025 14:00
rlubos
rlubos previously approved these changes May 30, 2025
Comment on lines 491 to 493
int error;

error = openthread_init();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
int error;
error = openthread_init();
int error = openthread_init();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

error = otThreadSetExtendedPanId(openthread_instance, &xpanid);
if (error != OT_ERROR_NONE) {
LOG_ERR("Failed to set %s [%d]", "ext PAN ID", error);
return false;
}

if (strlen(OT_NETWORKKEY)) {
net_bytes_from_str(networkKey.m8, OT_NETWORK_KEY_SIZE, (char *)OT_NETWORKKEY);
bytes_from_str(networkKey.m8, OT_NETWORK_KEY_SIZE, (char *)OT_NETWORKKEY);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably we don't need it, because otThread methods will handle it properly anyway due to internal checks, but please note that below we are passing buffer that may contain trash, as output result was not verified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've added a check here.

}
}

(void)memset(buf, 0, buf_len);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing nullptr check for buf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

If CONFIG_OPENTHREAD_SYS_INIT is enabled, OpenThread initialisation
should also consider running OpenThread automatically if
CONFIG_OPENTHREAD_MANUAL_START is disabled.

Removed also dependency on the `net_bytes_from_str` functions from
the openthread.h file. Now, in the OpenThread module, there is an
additional `openthread_utils.c/.h` file that can implement useful
utilities for the OpenThread platform. Currently, it implements
the `bytes_from_str` function to use it instead of
`net_bytes_from_str`.

Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
@ArekBalysNordic ArekBalysNordic force-pushed the openthread_without_net branch from 2fb121a to f1338c3 Compare June 3, 2025 11:39
Copy link

sonarqubecloud bot commented Jun 3, 2025

@@ -182,15 +183,22 @@ static bool ot_setup_default_configuration(void)
return false;
}

net_bytes_from_str(xpanid.m8, 8, (char *)OT_XPANID);
if (bytes_from_str(xpanid.m8, 8, (char *)OT_XPANID) != 0) {

Choose a reason for hiding this comment

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

if (bytes_from_str(xpanid.m8, 8, (char *)OT_XPANID) != 0)
if (bytes_from_str(xpanid.m8, sizeof(xpanid.m8), (char *)OT_XPANID) != 0)

@fabiobaltieri fabiobaltieri merged commit 1dbe7fa into zephyrproject-rtos:main Jun 3, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants