Skip to content

Conversation

@jukkar
Copy link
Member

@jukkar jukkar commented Apr 24, 2025

The current net_mgmt API uses 32 bit enum values for network event codes. This means that user needs to check what event is being triggered because the individual bits do not tell that. This has led to great confusion over the years and is being discussed more in #88534

This PR proposes that each network event is mapped to one specific bit in the layer. To make sure that there are enough bits available, the net_mgmt API is changed to use 64 bit event number values.

@JordanYates
Copy link
Contributor

What changed from your #88495 (comment) that 64 bits will eventually be insufficient?


/** @endcond */

/** Central place the definition of the layer codes (7 bit value) */
Copy link
Contributor

Choose a reason for hiding this comment

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

Defining these layer codes as integers rather than individual bits essentially makes the global_event_mask optimisation in net_mgmt.c pointless. This is no different from the current behaviour, but worth looking at if we are redoing the definitions of events in order to get it right the first time?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mentioned earlier the problems with net_mgmt_event_wait() but it seems that I missed your point there as after looking the API it looks ok after all. Or were you just wanting to avoid checking enum values in the first place and just use bit values?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the problems with net_mgmt_event_wait are solved by this PR.
This comment was about

static inline void mgmt_add_event_mask(uint32_t event_mask)
{
global_event_mask |= event_mask;
}

static inline bool mgmt_is_event_handled(uint32_t mgmt_event)
{
return (((NET_MGMT_GET_LAYER(mgmt_event) &
NET_MGMT_GET_LAYER(global_event_mask)) ==
NET_MGMT_GET_LAYER(mgmt_event)) &&
((NET_MGMT_GET_LAYER_CODE(mgmt_event) &
NET_MGMT_GET_LAYER_CODE(global_event_mask)) ==
NET_MGMT_GET_LAYER_CODE(mgmt_event)) &&
((NET_MGMT_GET_COMMAND(mgmt_event) &
NET_MGMT_GET_COMMAND(global_event_mask)) ==
NET_MGMT_GET_COMMAND(mgmt_event)));
}

This code is supposed to be doing some early filtering of events that no-one is subscribed to, but because the layer codes mostly all share bits with each other, basically no events are actually going to be filtered, its just extra computation for no benefit.

@jukkar
Copy link
Member Author

jukkar commented Apr 25, 2025

What changed from your #88495 (comment) that 64 bits will eventually be insufficient?

Nothing really, just wanted to experiment with this idea of having one bit / event thingy. I looked also using bitarray but that would be much bigger change. So just experimenting and path finding a solution for having one bit / event with minimal API changes.

@jukkar
Copy link
Member Author

jukkar commented Apr 25, 2025

From the current set of changes here, the first three are more or less generic and we could probably apply them regardless of what is being done with the actual event values.

Copy link
Contributor

@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.

I just wonder if we should differentiate the actual event codes (integers defined in for example enum net_event_if_cmd) from the even representation in the 64-bit event, it seems it could cause some confustion.

@jukkar
Copy link
Member Author

jukkar commented Apr 25, 2025

I just wonder if we should differentiate the actual event codes (integers defined in for example enum net_event_if_cmd) from the even representation in the 64-bit event, it seems it could cause some confustion.

Yeah, I thought about the same. It is just a bigger API change so did not go that route yet.

@jukkar
Copy link
Member Author

jukkar commented Apr 25, 2025

I submitted the first three commits to #89083 as they are pretty generic and could be used in main already.

@jukkar jukkar force-pushed the fix/88534/net-mgmt-event-handling branch from aaa7421 to d52258e Compare May 30, 2025 12:27
@jukkar jukkar marked this pull request as ready for review May 30, 2025 12:27
@jukkar
Copy link
Member Author

jukkar commented May 30, 2025

I marked this as a normal PR so that we can have a verdict whether this is a desired change. Please take a look and comment.

@jukkar jukkar force-pushed the fix/88534/net-mgmt-event-handling branch from d52258e to 837f31b Compare June 2, 2025 12:07
@github-actions github-actions bot added area: Samples Samples platform: NXP S32 NXP Semiconductors, S32 platform: ESP32 Espressif ESP32 labels Jun 2, 2025
@github-actions github-actions bot requested a review from congnguyenhuu June 2, 2025 12:08
@decsny
Copy link
Member

decsny commented Jun 17, 2025

update manifest and remove DNM once #91494 merges due to NXP HAL synchronizing order

@decsny decsny added DNM This PR should not be merged (Do Not Merge) labels Jun 17, 2025
jukkar added 4 commits June 18, 2025 10:08
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 <jukka.rissanen@nordicsemi.no>
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 <jukka.rissanen@nordicsemi.no>
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 <jukka.rissanen@nordicsemi.no>
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 <jukka.rissanen@nordicsemi.no>
@jukkar jukkar dismissed stale reviews from rlubos and maass-hamburg via b961cd9 June 18, 2025 07:11
@jukkar jukkar force-pushed the fix/88534/net-mgmt-event-handling branch from a562ab5 to b961cd9 Compare June 18, 2025 07:11
@jukkar jukkar removed the DNM This PR should not be merged (Do Not Merge) label Jun 18, 2025
@github-actions github-actions bot removed manifest manifest-hal_nxp DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Jun 18, 2025
@jukkar jukkar removed the Architecture Review Discussion in the Architecture WG required label Jun 18, 2025
@sonarqubecloud
Copy link

@kartben kartben merged commit b1a8655 into zephyrproject-rtos:main Jun 18, 2025
31 of 33 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Architecture Review Jun 18, 2025
@jukkar jukkar deleted the fix/88534/net-mgmt-event-handling branch June 18, 2025 09:23
craigpeacock added a commit to craigpeacock/Zephyr_WiFi that referenced this pull request Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: API Changes to public APIs area: IEEE 802.15.4 area: Networking area: Samples Samples area: Sockets Networking sockets area: UpdateHub UpdateHub area: Wi-Fi Wi-Fi Breaking API Change Breaking changes to stable, public APIs platform: ESP32 Espressif ESP32 platform: NXP S32 NXP Semiconductors, S32 Release Notes To be mentioned in the release notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

8 participants