Skip to content

net: Cherry pick net_mgmt API changes #2990

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/connectivity/networking/api/coap_server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions doc/connectivity/networking/api/net_mgmt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions doc/releases/migration-guide-4.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,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
==========

Expand Down
7 changes: 7 additions & 0 deletions doc/releases/release-notes-4.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
====================

Expand Down
2 changes: 1 addition & 1 deletion drivers/modem/modem_cellular.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion drivers/wifi/esp32/src/esp_wifi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 16 additions & 4 deletions include/zephyr/net/coap_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
14 changes: 12 additions & 2 deletions include/zephyr/net/conn_mgr_connectivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
20 changes: 16 additions & 4 deletions include/zephyr/net/ethernet_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
11 changes: 10 additions & 1 deletion include/zephyr/net/ieee802154_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

/**
Expand Down
Loading
Loading