Skip to content
Open
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7564665
gnrc/netapi: add notification message type
elenaf9 Jul 15, 2025
0408e39
nimble/netif: notify on BLE connection events
elenaf9 Jul 15, 2025
bf82b94
gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Jul 15, 2025
fbd2219
gnrc/ipv6: notify L3_ROUTING of discovered/ unreachable nodes
elenaf9 Jul 16, 2025
9715791
gnrc/rpl: iterate through parents that match addr
elenaf9 Jul 8, 2025
9030409
gnrc/rpl: handle L3 routing events from netapi
elenaf9 Jul 16, 2025
6cef5d6
nimble/rpble: don't send DIS on connection event
elenaf9 Jul 16, 2025
b6e19c2
fixup! gnrc/rpl: handle L3 routing events from netapi
elenaf9 Jul 17, 2025
f1b82ec
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Jul 17, 2025
4404817
fixup! gnrc/netapi: add notification message type
elenaf9 Jul 17, 2025
e9d25cb
fixup! gnrc/netapi: add notification message type
elenaf9 Jul 17, 2025
6570d30
fixup! nimble/netif: notify on BLE connection events
elenaf9 Jul 17, 2025
82b5059
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Jul 17, 2025
7e911b8
fixup! gnrc/ipv6: notify L3_ROUTING of discovered/ unreachable nodes
elenaf9 Jul 17, 2025
d8d7c81
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Jul 17, 2025
602e894
fixup! gnrc/netapi: add notification message type
elenaf9 Jul 30, 2025
418825f
fixup! gnrc/netapi: add notification message type
elenaf9 Jul 30, 2025
7755585
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Jul 30, 2025
2447cb8
fixup! gnrc/netapi: add notification message type
elenaf9 Aug 4, 2025
8c53e7a
fixup! fixup! gnrc/netapi: add notification message type
elenaf9 Aug 7, 2025
2c5bf74
gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 7, 2025
ad4c316
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 7, 2025
b8ae0f6
Merge branch 'master' of https://github.com/RIOT-OS/RIOT into gnrc/ne…
elenaf9 Aug 18, 2025
abb69a1
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 29, 2025
afb04c8
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 29, 2025
8c88416
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 29, 2025
bee053b
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 29, 2025
a7d5ac9
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Aug 29, 2025
2079a8f
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 3, 2025
30b2b7f
Apply suggestions from code review
elenaf9 Sep 4, 2025
2bfd90d
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 4, 2025
7713680
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Sep 4, 2025
f57c38b
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 4, 2025
2d5e9c5
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 4, 2025
7de5975
fixup! Apply suggestions from code review
elenaf9 Sep 4, 2025
754fe9c
Like 7de59757a6da5b3b7367f1a0a2e87081c3e1887f
elenaf9 Sep 4, 2025
0c8d01d
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 8, 2025
97a0422
fixup! gnrc/netapi: add notification message type
elenaf9 Sep 8, 2025
d57474d
fixup! nimble/netif: notify on BLE connection events
elenaf9 Sep 8, 2025
06c3e64
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Sep 8, 2025
5328407
fixup! gnrc/ipv6: notify L3_ROUTING of discovered/ unreachable nodes
elenaf9 Sep 8, 2025
00a8d28
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Sep 8, 2025
ed5ac34
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Oct 1, 2025
c45fd59
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Oct 1, 2025
6e33db2
fixup! gnrc/netapi: add notification message type
elenaf9 Oct 1, 2025
2ab900c
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Nov 25, 2025
d0df717
fixup! gnrc/rpl: handle L3 routing events from netapi
elenaf9 Nov 26, 2025
e263d97
fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Nov 26, 2025
d20a7b5
fixup! fixup! gnrc/netapi/netnotify: ACK notify event directly
elenaf9 Nov 26, 2025
11567f7
fixup! gnrc/ipv6: modify nib nc on l2 connection event
elenaf9 Nov 26, 2025
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
34 changes: 34 additions & 0 deletions pkg/nimble/netif/nimble_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "host/ble_gap.h"
#include "host/util/util.h"
#include "mem/mem.h"
#include <string.h>

#define ENABLE_DEBUG 0
#include "debug.h"
Expand Down Expand Up @@ -331,6 +332,27 @@
ble_l2cap_recv_ready(event->receive.chan, rxb);
}

#ifdef MODULE_GNRC_IPV6
/**
* @brief Sends a netapi notification for a connection event.
*
* @param[in] notify The type of notification event.
* @param[in] addr BLE address of the node that (dis-)connected.
*/
static inline void _dispatch_connection_event(netapi_notify_t notify, uint8_t *addr)
{
netapi_notify_l2_connection_t event = {
.l2addr_len = BLE_ADDR_LEN,
.if_pid = _netif.pid,
};

memcpy(event.l2addr, addr, BLE_ADDR_LEN);

gnrc_netapi_notify(GNRC_NETTYPE_L2_DISCOVERY, GNRC_NETREG_DEMUX_CTX_ALL,
notify, &event, sizeof(netapi_notify_l2_connection_t));
}
#endif /* MODULE_GNRC_IPV6 */

static int _on_l2cap_client_evt(struct ble_l2cap_event *event, void *arg)
{
int handle = (int)arg;
Expand All @@ -349,6 +371,9 @@
conn->state |= NIMBLE_NETIF_L2CAP_CLIENT;
conn->state &= ~NIMBLE_NETIF_CONNECTING;
_notify(handle, NIMBLE_NETIF_CONNECTED_MASTER, conn->addr);
#ifdef MODULE_GNRC_IPV6
_dispatch_connection_event(NETAPI_NOTIFY_L2_NEIGH_CONNECTED, conn->addr);
#endif /* MODULE_GNRC_IPV6 */
break;
case BLE_L2CAP_EVENT_COC_DISCONNECTED:
assert(conn->state & NIMBLE_NETIF_L2CAP_CLIENT);
Expand Down Expand Up @@ -404,6 +429,9 @@
}

_notify(handle, NIMBLE_NETIF_CONNECTED_SLAVE, conn->addr);
#ifdef MODULE_GNRC_IPV6
_dispatch_connection_event(NETAPI_NOTIFY_L2_NEIGH_CONNECTED, conn->addr);
#endif /* MODULE_GNRC_IPV6 */
break;
case BLE_L2CAP_EVENT_COC_DISCONNECTED:
conn = nimble_netif_conn_from_gaphandle(event->disconnect.conn_handle);
Expand Down Expand Up @@ -450,7 +478,7 @@
{
struct ble_gap_conn_desc desc;
int res = ble_gap_conn_find(conn->gaphandle, &desc);
assert(res == 0) ;

Check warning on line 481 in pkg/nimble/netif/nimble_netif.c

View workflow job for this annotation

GitHub Actions / static-tests

semicolon is isolated from other tokens
(void)res;

conn->itvl = desc.conn_itvl;
Expand Down Expand Up @@ -498,6 +526,9 @@
nimble_netif_conn_free(handle, addr);
thread_flags_set(_netif_thread, FLAG_TX_NOTCONN);
_notify(handle, type, addr);
#ifdef MODULE_GNRC_IPV6
_dispatch_connection_event(NETAPI_NOTIFY_L2_NEIGH_DISCONNECTED, addr);
#endif /* MODULE_GNRC_IPV6 */
break;
}
case BLE_GAP_EVENT_CONN_UPDATE:
Expand Down Expand Up @@ -542,6 +573,9 @@
nimble_netif_conn_free(handle, addr);
thread_flags_set(_netif_thread, FLAG_TX_NOTCONN);
_notify(handle, type, addr);
#ifdef MODULE_GNRC_IPV6
_dispatch_connection_event(NETAPI_NOTIFY_L2_NEIGH_DISCONNECTED, addr);
#endif /* MODULE_GNRC_IPV6 */
break;
}
case BLE_GAP_EVENT_CONN_UPDATE:
Expand Down
3 changes: 0 additions & 3 deletions pkg/nimble/rpble/nimble_rpble.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ static void _on_netif_evt(int handle, nimble_netif_event_t event,
case NIMBLE_NETIF_CONNECTED_MASTER:
/* parent selected */
assert(_current_parent == handle);
/* send a DIS once connected to a (new) parent) */
gnrc_rpl_send_DIS(NULL, (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes,
NULL, 0);
break;
case NIMBLE_NETIF_CONNECTED_SLAVE:
/* child added */
Expand Down
1 change: 1 addition & 0 deletions sys/include/net/gnrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@

#include "net/netopt.h"
#include "net/gnrc/netapi.h"
#include "net/gnrc/netapi/notify.h"
#include "net/gnrc/netreg.h"
#include "net/gnrc/nettype.h"
#include "net/gnrc/netif.h"
Expand Down
45 changes: 45 additions & 0 deletions sys/include/net/gnrc/ipv6/nib/nc.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,36 @@ static inline unsigned gnrc_ipv6_nib_nc_get_ar_state(const gnrc_ipv6_nib_nc_t *e
int gnrc_ipv6_nib_nc_set(const ipv6_addr_t *ipv6, unsigned iface,
const uint8_t *l2addr, size_t l2addr_len);

#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LN) || defined(DOXYGEN)
/**
* @brief Adds an unmanaged neighbor entry to the NIB if the interface represents a 6LN node
* and the IPv6 address can be constructed from the L2 address @p l2addr.
*
* @param[in] iface The interface to the neighbor.
* @param[in] l2addr The neighbor's layer 2 address.
* @param[in] l2addr_len Length of @p l2addr.
*
* @retval 0 on success.
* @retval -ENOTSUP if the interface does not represent a 6LN or when
* gnrc_netif_t::device_type of the iface does not support IID conversion.
* @retval -EINVAL when @p addr_len is invalid for the
* gnrc_netif_t::device_type of @p netif.
* @retval -ENOMEM if no space is left in neighbor cache.
*/
int gnrc_ipv6_nib_nc_set_6ln(unsigned iface, const uint8_t *l2addr,
size_t l2addr_len);
#else /* CONFIG_GNRC_IPV6_NIB_6LN */
static inline int gnrc_ipv6_nib_nc_set_6ln(unsigned iface, const uint8_t *l2addr,
size_t l2addr_len)
{
(void)iface;
(void)l2addr;
(void)l2addr_len;

return -ENOTSUP;
}
#endif /* CONFIG_GNRC_IPV6_NIB_6LN */

/**
* @brief Deletes neighbor with address @p ipv6 from NIB
*
Expand All @@ -245,6 +275,21 @@ int gnrc_ipv6_nib_nc_set(const ipv6_addr_t *ipv6, unsigned iface,
*/
void gnrc_ipv6_nib_nc_del(const ipv6_addr_t *ipv6, unsigned iface);

/**
* @brief Deletes neighbor with link-layer address @p l2addr from NIB.
*
* @param[in] iface The interface to the neighbor.
* @param[in] l2addr The neighbor's l2addr address.
* @param[in] l2addr_len Length of @p l2addr.
*
*
* If the @p l2addr can't be found for a neighbor in the NIB nothing happens.
*
* @retval True if a neighbor with @p l2addr existed.
* @retval False otherwise.
*/
bool gnrc_ipv6_nib_nc_del_l2(unsigned iface, const uint8_t *l2addr, size_t l2addr_len);

/**
* @brief Mark neighbor with address @p ipv6 as reachable
*
Expand Down
28 changes: 27 additions & 1 deletion sys/include/net/gnrc/netapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

#include "thread.h"
#include "net/netopt.h"
#include "net/gnrc/netapi/notify.h"
#include "net/gnrc/nettype.h"
#include "net/gnrc/pkt.h"

Expand Down Expand Up @@ -88,10 +89,17 @@ extern "C" {
#define GNRC_NETAPI_MSG_TYPE_GET (0x0204)

/**
* @brief @ref core_msg type for replying to get and set option messages
* @brief @ref core_msg type for replying to get/set option, and notify messages
*/
#define GNRC_NETAPI_MSG_TYPE_ACK (0x0205)

/**
* @brief @ref core_msg type for sending a general event notifications to one or more subscribers
*
* This sends back a @ref GNRC_NETAPI_MSG_TYPE_ACK, so it should be used with `msg_send_receive()`.
*/
#define GNRC_NETAPI_MSG_TYPE_NOTIFY (0x0207)

/**
* @brief Data structure to be send for setting (@ref GNRC_NETAPI_MSG_TYPE_SET)
* and getting (@ref GNRC_NETAPI_MSG_TYPE_GET) options
Expand Down Expand Up @@ -183,6 +191,24 @@ static inline int gnrc_netapi_dispatch_send(gnrc_nettype_t type, uint32_t demux_
return gnrc_netapi_dispatch(type, demux_ctx, GNRC_NETAPI_MSG_TYPE_SND, pkt);
}

/**
* @brief Sends a @ref GNRC_NETAPI_MSG_TYPE_NOTIFY command to all subscribers to
* (@p type, @p demux_ctx).
*
* @note This blocks the sender until all registered subscribers have ack'ed the notification
* or sending has failed. The @p data can be freed after the function returned.
*
* @param[in] type Type of the targeted network module.
* @param[in] demux_ctx Demultiplexing context for @p type.
* @param[in] event Notification event type.
* @param[in] data Data associated with the event.
* @param[in] data_len Size of @p data.
*
* @return Number of subscribers to (@p type, @p demux_ctx).
*/
int gnrc_netapi_notify(gnrc_nettype_t type, uint32_t demux_ctx, netapi_notify_t event,
void *data, size_t data_len);

/**
* @brief Shortcut function for sending @ref GNRC_NETAPI_MSG_TYPE_RCV messages
*
Expand Down
104 changes: 104 additions & 0 deletions sys/include/net/gnrc/netapi/notify.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* SPDX-FileCopyrightText: 2025 TU Dresden
* SPDX-License-Identifier: LGPL-2.1-only
*/

#pragma once

/**
* @defgroup net_gnrc_netapi_notify Notification events for network APIs.
* @ingroup net_gnrc_netapi
* @brief Network event notification types.
* @{
*
* @file
* @brief Network event notification type definitions.
*
* @details The purpose of this API is to allow lower layers in the network
* stack to inform higher layers of general, protocol-independent
* network events.
* It can be used through the @ref net_gnrc_netapi to notify any
* other network interfaces that have registered themselves through
* @ref net_gnrc_netreg for the corresponding @ref net_gnrc_nettype.
*
* @note Notification events are associated with type-dependent event data.
* Receivers should not access the data directly, but instead use the
* the dedicated API functions to copy the data from the sender's.
* If the data is read manually, the receiver is responsible for
* calling @ref gnrc_netapi_notify_ack to unblock the sender.
*
* @author Elena Frank <[email protected]>
*/

#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif

#include "net/gnrc/netif/conf.h"
#include "sema_inv.h"

/**
* @brief Definition of notification event types in the network stack.
*
* @note Expand at will.
* If event data is associated with the type, a helper function must also
* be added for parsing the data and calling @ref gnrc_netapi_notify_ack.
*/
typedef enum {
NETAPI_NOTIFY_L2_NEIGH_CONNECTED, /**< Connection established on layer 2. */
NETAPI_NOTIFY_L2_NEIGH_DISCONNECTED, /**< Connection closed on layer 2. */
NETAPI_NOTIFY_L3_DISCOVERED, /**< Discovered node on the network layer. */
NETAPI_NOTIFY_L3_UNREACHABLE, /**< Node became unreachable on the network layer. */
} netapi_notify_t;

/**
* @brief Data structure to be sent for netapi notification events.
*/
typedef struct {
netapi_notify_t event; /**< the type of event */
void *_data; /**< associated event data. */
uint16_t _data_len; /**< size of the event data */
sema_inv_t ack; /**< inverse semaphore for collecting ack's */
} gnrc_netapi_notify_t;

/**
* @brief L2 connection event data associated with @ref NETAPI_NOTIFY_L2_NEIGH_CONNECTED or
* @ref NETAPI_NOTIFY_L2_NEIGH_DISCONNECTED events.
*/
typedef struct {
uint8_t l2addr[GNRC_NETIF_L2ADDR_MAXLEN]; /**< L2 address of the node */
uint8_t l2addr_len; /**< length of L2 address in byte */
kernel_pid_t if_pid; /**< PID of network interface */
} netapi_notify_l2_connection_t;

/**
* @brief Acknowledge that a notify event was received and its data read.
*
* @param[in] ack Pointer to semaphore that is used to collect ack's.
*/
static inline void gnrc_netapi_notify_ack(sema_inv_t *ack)
{
sema_inv_post(ack);
}

/**
* @brief Copy the connection event data associated with a @ref gnrc_netapi_notify_t event.
*
* @note This will call @ref gnrc_netapi_notify_ack.
*
* @param[in] notify Pointer to the received notify event.
* @param[in] data_len Size of the expected data type.
* @param[out] data Connection data received in the @p notify event.
*
* @retval Size of the data type on success.
* @retval -EINVAL if the data in @p notify is invalid or doesn't match the expected
* data length.
*/
int gnrc_netapi_notify_copy_event_data(gnrc_netapi_notify_t *notify, uint8_t data_len, void *data);

#ifdef __cplusplus
}
#endif

/** @} */
3 changes: 2 additions & 1 deletion sys/include/net/gnrc/netreg.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ static inline void gnrc_netreg_entry_init_cb(gnrc_netreg_entry_t *entry,
* @brief Registers a thread to the registry.
*
* @details The semantics are: Thread gnrc_netreg_entry_t::pid is interested in
* packets of protocol @p type with context gnrc_netreg_entry_t::demux_ctx.
* packets or network events of protocol @p type with context
* gnrc_netreg_entry_t::demux_ctx.
*
* @param[in] type Type of the protocol. Must not be < GNRC_NETTYPE_UNDEF or
* >= GNRC_NETTYPE_NUMOF.
Expand Down
9 changes: 9 additions & 0 deletions sys/include/net/gnrc/nettype.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ typedef enum {
#endif
/** @} */

/**
* @{
* @name Protocol-independent network events.
* }
*/
GNRC_NETTYPE_L2_DISCOVERY, /**< Layer 2 node discovery */
GNRC_NETTYPE_L3_ROUTING, /**< Layer 3 routing info */
/** @} */

/**
* @{
* @name Testing
Expand Down
12 changes: 12 additions & 0 deletions sys/include/net/gnrc/rpl/dodag.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ void gnrc_rpl_dodag_remove_all_parents(gnrc_rpl_dodag_t *dodag);
bool gnrc_rpl_parent_add_by_addr(gnrc_rpl_dodag_t *dodag, ipv6_addr_t *addr,
gnrc_rpl_parent_t **parent);

/**
* @brief Iterate over all parents in all DODAGs with @p IPv6 address.
*
* @param[in] idx Index to start searching from.
* @param[in] addr IPV6 address of the parent.
* @param[out] parent Pointer to the parent if one was found. Otherwise NULL.
*
* @retval Index > 0 to continue next search from, if parent was found.
* @retval -ENONENT if not found
*/
int gnrc_rpl_parent_iter_by_addr(ipv6_addr_t *addr, gnrc_rpl_parent_t **parent, int idx);

/**
* @brief Remove the @p parent from its DODAG.
*
Expand Down
3 changes: 3 additions & 0 deletions sys/net/gnrc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ endif
ifneq (,$(filter gnrc_netapi,$(USEMODULE)))
DIRS += netapi
endif
ifneq (,$(filter gnrc_netapi_notify,$(USEMODULE)))
DIRS += netapi/notify
endif
ifneq (,$(filter gnrc_netif gnrc_netif_%,$(USEMODULE)))
DIRS += netif
endif
Expand Down
Loading
Loading