diff --git a/Makefile.dep b/Makefile.dep index a49f2ca0e0..ee10ee9edf 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -196,6 +196,10 @@ ifneq (,$(filter gnrc_netif,$(USEMODULE))) endif endif +ifneq (,$(filter gnrc_netif_bus,$(USEMODULE))) + USEMODULE += core_msg_bus +endif + ifneq (,$(filter gnrc_netif_events,$(USEMODULE))) USEMODULE += core_thread_flags USEMODULE += event diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 34fc2385df..e423cfde7a 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -31,6 +31,7 @@ PSEUDOMODULES += gnrc_netdev_default PSEUDOMODULES += gnrc_neterr PSEUDOMODULES += gnrc_netapi_callbacks PSEUDOMODULES += gnrc_netapi_mbox +PSEUDOMODULES += gnrc_netif_bus PSEUDOMODULES += gnrc_netif_events PSEUDOMODULES += gnrc_pktbuf_cmd PSEUDOMODULES += gnrc_netif_6lo diff --git a/sys/include/net/gnrc/netif.h b/sys/include/net/gnrc/netif.h index 7538caf537..3c8826c516 100644 --- a/sys/include/net/gnrc/netif.h +++ b/sys/include/net/gnrc/netif.h @@ -30,6 +30,9 @@ #include "kernel_types.h" #include "msg.h" +#ifdef MODULE_GNRC_NETIF_BUS +#include "msg_bus.h" +#endif #include "event.h" #include "net/ipv6/addr.h" #include "net/gnrc/netapi.h" @@ -64,6 +67,13 @@ extern "C" { #endif +/** + * @brief Per-Interface Event Message Busses + */ +typedef enum { + GNRC_NETIF_BUS_NUMOF +} gnrc_netif_bus_t; + /** * @brief Operations to an interface */ @@ -87,8 +97,11 @@ typedef struct { gnrc_netif_ipv6_t ipv6; /**< IPv6 component */ #endif #if IS_USED(MODULE_GNRC_NETIF_MAC) || defined(DOXYGEN) - gnrc_netif_mac_t mac; /**< @ref net_gnrc_mac component */ + gnrc_netif_mac_t mac; /**< @ref net_gnrc_mac component */ #endif /* IS_USED(MODULE_GNRC_NETIF_MAC) || defined(DOXYGEN) */ +#if IS_USED(MODULE_GNRC_NETIF_BUS) || DOXYGEN + msg_bus_t bus[GNRC_NETIF_BUS_NUMOF]; /**< Event Message Bus */ +#endif /** * @brief Flags for the interface * @@ -566,6 +579,23 @@ static inline int gnrc_netif_send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt) return gnrc_netapi_send(netif->pid, pkt); } +#if defined(MODULE_GNRC_NETIF_BUS) || DOXYGEN +/** + * @brief Get a message bus of a given @ref gnrc_netif_t interface. + * + * @param netif pointer to the interface + * @param type GNRC message bus [type](@ref gnrc_netif_bus_t) + * + * @return the message bus for the interface + */ +static inline msg_bus_t* gnrc_netif_get_bus(gnrc_netif_t *netif, + gnrc_netif_bus_t type) +{ + assert(type < GNRC_NETIF_BUS_NUMOF); + return &netif->bus[type]; +} +#endif /* MODULE_GNRC_NETIF_BUS */ + #ifdef __cplusplus } #endif diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 224a6c7a76..bff28fb1c1 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -67,6 +67,11 @@ int gnrc_netif_create(gnrc_netif_t *netif, char *stack, int stacksize, "more than one interface is being registered.\n"); assert(netif_iter(NULL) == NULL); } +#ifdef MODULE_GNRC_NETIF_BUS + for (int i = 0; i < GNRC_NETIF_BUS_NUMOF; ++i) { + msg_bus_init(&netif->bus[i]); + } +#endif rmutex_init(&netif->mutex); netif->ops = ops; netif_register((netif_t*) netif);