diff --git a/cpu/esp_common/esp-now/esp_now_gnrc.c b/cpu/esp_common/esp-now/esp_now_gnrc.c index 8c40bbfb5a..ce8ff50933 100644 --- a/cpu/esp_common/esp-now/esp_now_gnrc.c +++ b/cpu/esp_common/esp-now/esp_now_gnrc.c @@ -192,6 +192,7 @@ err: } static const gnrc_netif_ops_t _esp_now_ops = { + .init = gnrc_netif_default_init, .send = _send, .recv = _recv, .get = gnrc_netif_get_from_netdev, diff --git a/cpu/nrf5x_common/radio/nrfmin/nrfmin_gnrc.c b/cpu/nrf5x_common/radio/nrfmin/nrfmin_gnrc.c index dc0cdc4e75..dedff9abf8 100644 --- a/cpu/nrf5x_common/radio/nrfmin/nrfmin_gnrc.c +++ b/cpu/nrf5x_common/radio/nrfmin/nrfmin_gnrc.c @@ -173,6 +173,7 @@ static gnrc_pktsnip_t *gnrc_nrfmin_recv(gnrc_netif_t *dev) } static const gnrc_netif_ops_t gnrc_nrfmin_ops = { + .init = gnrc_netif_default_init, .send = gnrc_nrfmin_send, .recv = gnrc_nrfmin_recv, .get = gnrc_netif_get_from_netdev, diff --git a/drivers/cc1xxx_common/gnrc_netif_cc1xxx.c b/drivers/cc1xxx_common/gnrc_netif_cc1xxx.c index 0c4498427e..25bcba2d24 100644 --- a/drivers/cc1xxx_common/gnrc_netif_cc1xxx.c +++ b/drivers/cc1xxx_common/gnrc_netif_cc1xxx.c @@ -159,6 +159,7 @@ static int cc1xxx_adpt_send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt) } static const gnrc_netif_ops_t cc1xxx_netif_ops = { + .init = gnrc_netif_default_init, .send = cc1xxx_adpt_send, .recv = cc1xxx_adpt_recv, .get = gnrc_netif_get_from_netdev, diff --git a/drivers/xbee/gnrc_xbee.c b/drivers/xbee/gnrc_xbee.c index c3df55d24d..04365ee072 100644 --- a/drivers/xbee/gnrc_xbee.c +++ b/drivers/xbee/gnrc_xbee.c @@ -160,6 +160,7 @@ static int xbee_adpt_send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt) } static const gnrc_netif_ops_t _xbee_ops = { + .init = gnrc_netif_default_init, .send = xbee_adpt_send, .recv = xbee_adpt_recv, .get = gnrc_netif_get_from_netdev, diff --git a/pkg/nimble/netif/nimble_netif.c b/pkg/nimble/netif/nimble_netif.c index 07baf2d4cc..f70e074d0e 100644 --- a/pkg/nimble/netif/nimble_netif.c +++ b/pkg/nimble/netif/nimble_netif.c @@ -90,6 +90,7 @@ static void _netif_init(gnrc_netif_t *netif) { (void)netif; + gnrc_netif_default_init(netif); /* save the threads context pointer, so we can set its flags */ _netif_thread = (thread_t *)thread_get(thread_getpid()); diff --git a/pkg/nordic_softdevice_ble/src/gnrc_nordic_ble_6lowpan.c b/pkg/nordic_softdevice_ble/src/gnrc_nordic_ble_6lowpan.c index 5fdd1d0718..4c56d1c186 100644 --- a/pkg/nordic_softdevice_ble/src/gnrc_nordic_ble_6lowpan.c +++ b/pkg/nordic_softdevice_ble/src/gnrc_nordic_ble_6lowpan.c @@ -258,7 +258,7 @@ static void _netif_msg_handler(gnrc_netif_t *netif, msg_t *msg) } static const gnrc_netif_ops_t _ble_ops = { - .init = NULL, + .init = gnrc_netif_default_init, .send = _netif_send, .recv = _netif_recv, .get = gnrc_netif_get_from_netdev, diff --git a/sys/include/net/gnrc/netif.h b/sys/include/net/gnrc/netif.h index 456b43c915..cf73747852 100644 --- a/sys/include/net/gnrc/netif.h +++ b/sys/include/net/gnrc/netif.h @@ -131,10 +131,13 @@ struct gnrc_netif_ops { * * @param[in] netif The network interface. * - * This is called after the default settings were set, right before the - * interface's thread starts receiving messages. It is not necessary to lock - * the interface's mutex gnrc_netif_t::mutex, since the thread will already - * lock it. Leave NULL if you do not need any special initialization. + * This is called after the network device's initial configuration, right + * before the interface's thread starts receiving messages. It is not + * necessary to lock the interface's mutex gnrc_netif_t::mutex, since it is + * already locked. Set to @ref gnrc_netif_default_init() if you do not need + * any special initialization. If you do need special initialization, it is + * recommended to call @ref gnrc_netif_default_init() at the start of the + * custom initialization function set here. */ void (*init)(gnrc_netif_t *netif); @@ -434,6 +437,15 @@ static inline int gnrc_netif_ipv6_group_leave(const gnrc_netif_t *netif, sizeof(ipv6_addr_t)); } +/** + * @brief Default operation for gnrc_netif_ops_t::init() + * + * @note Can also be used to be called *before* a custom operation. + * + * @param[in] netif The network interface. + */ +void gnrc_netif_default_init(gnrc_netif_t *netif); + /** * @brief Default operation for gnrc_netif_ops_t::get() * diff --git a/sys/net/gnrc/link_layer/gomach/gomach.c b/sys/net/gnrc/link_layer/gomach/gomach.c index c87282477f..b0cdebfedf 100644 --- a/sys/net/gnrc/link_layer/gomach/gomach.c +++ b/sys/net/gnrc/link_layer/gomach/gomach.c @@ -2108,6 +2108,7 @@ static void _gomach_init(gnrc_netif_t *netif) { netdev_t *dev; + gnrc_netif_default_init(netif); dev = netif->dev; dev->event_callback = _gomach_event_cb; diff --git a/sys/net/gnrc/link_layer/lwmac/lwmac.c b/sys/net/gnrc/link_layer/lwmac/lwmac.c index f9cf821edc..1e7216f260 100644 --- a/sys/net/gnrc/link_layer/lwmac/lwmac.c +++ b/sys/net/gnrc/link_layer/lwmac/lwmac.c @@ -901,6 +901,7 @@ static void _lwmac_init(gnrc_netif_t *netif) { netdev_t *dev; + gnrc_netif_default_init(netif); dev = netif->dev; dev->event_callback = _lwmac_event_cb; diff --git a/sys/net/gnrc/netif/ethernet/gnrc_netif_ethernet.c b/sys/net/gnrc/netif/ethernet/gnrc_netif_ethernet.c index 8517cc1d6b..908e8d1614 100644 --- a/sys/net/gnrc/netif/ethernet/gnrc_netif_ethernet.c +++ b/sys/net/gnrc/netif/ethernet/gnrc_netif_ethernet.c @@ -37,6 +37,7 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif); static char addr_str[ETHERNET_ADDR_LEN * 3]; static const gnrc_netif_ops_t ethernet_ops = { + .init = gnrc_netif_default_init, .send = _send, .recv = _recv, .get = gnrc_netif_get_from_netdev, diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index dc75dcfe69..a6053073e5 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -1213,6 +1213,8 @@ static void _configure_netdev(netdev_t *dev) } #ifdef DEVELHELP +static bool options_tested = false; + /* checks if a device supports all required options and functions */ static void _test_options(gnrc_netif_t *netif) { @@ -1314,9 +1316,22 @@ static void _test_options(gnrc_netif_t *netif) #endif /* GNRC_IPV6_NIB_CONF_6LN */ } #endif /* (GNRC_NETIF_L2ADDR_MAXLEN > 0) */ + options_tested = true; } #endif /* DEVELHELP */ +void gnrc_netif_default_init(gnrc_netif_t *netif) +{ + _init_from_device(netif); +#ifdef DEVELHELP + _test_options(netif); +#endif + netif->cur_hl = GNRC_NETIF_DEFAULT_HL; +#ifdef MODULE_GNRC_IPV6_NIB + gnrc_ipv6_nib_init_iface(netif); +#endif +} + static void *_gnrc_netif_thread(void *args) { gnrc_netapi_opt_t *opt; @@ -1349,17 +1364,10 @@ static void *_gnrc_netif_thread(void *args) return NULL; } _configure_netdev(dev); - _init_from_device(netif); -#ifdef DEVELHELP - _test_options(netif); + netif->ops->init(netif); +#if DEVELHELP + assert(options_tested); #endif - netif->cur_hl = GNRC_NETIF_DEFAULT_HL; -#ifdef MODULE_GNRC_IPV6_NIB - gnrc_ipv6_nib_init_iface(netif); -#endif - if (netif->ops->init) { - netif->ops->init(netif); - } #ifdef MODULE_NETSTATS_L2 memset(&netif->stats, 0, sizeof(netstats_t)); #endif diff --git a/sys/net/gnrc/netif/gnrc_netif_raw.c b/sys/net/gnrc/netif/gnrc_netif_raw.c index 886c00731e..84ae3eb678 100644 --- a/sys/net/gnrc/netif/gnrc_netif_raw.c +++ b/sys/net/gnrc/netif/gnrc_netif_raw.c @@ -28,6 +28,7 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt); static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif); static const gnrc_netif_ops_t raw_ops = { + .init = gnrc_netif_default_init, .send = _send, .recv = _recv, .get = gnrc_netif_get_from_netdev, diff --git a/sys/net/gnrc/netif/ieee802154/gnrc_netif_ieee802154.c b/sys/net/gnrc/netif/ieee802154/gnrc_netif_ieee802154.c index 374ab6b979..ad15ec080a 100644 --- a/sys/net/gnrc/netif/ieee802154/gnrc_netif_ieee802154.c +++ b/sys/net/gnrc/netif/ieee802154/gnrc_netif_ieee802154.c @@ -32,6 +32,7 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt); static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif); static const gnrc_netif_ops_t ieee802154_ops = { + .init = gnrc_netif_default_init, .send = _send, .recv = _recv, .get = gnrc_netif_get_from_netdev, diff --git a/tests/gnrc_ipv6_ext_frag/Makefile.ci b/tests/gnrc_ipv6_ext_frag/Makefile.ci index 41ea57e6f2..10375a3fbc 100644 --- a/tests/gnrc_ipv6_ext_frag/Makefile.ci +++ b/tests/gnrc_ipv6_ext_frag/Makefile.ci @@ -5,6 +5,8 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-nano \ arduino-uno \ atmega328p \ + blackpill \ + bluepill \ hifive1 \ hifive1b \ i-nucleo-lrwan1 \ diff --git a/tests/gnrc_ndp/main.c b/tests/gnrc_ndp/main.c index fa2df65569..363f54290e 100644 --- a/tests/gnrc_ndp/main.c +++ b/tests/gnrc_ndp/main.c @@ -1221,6 +1221,7 @@ static int _test_netif_set(gnrc_netif_t *netif, const gnrc_netapi_opt_t *opt) } static const gnrc_netif_ops_t _test_netif_ops = { + .init = gnrc_netif_default_init, .send = _test_netif_send, .recv = _test_netif_recv, .get = gnrc_netif_get_from_netdev, diff --git a/tests/gnrc_netif/main.c b/tests/gnrc_netif/main.c index 7020c0b9ab..2b55d1bac8 100644 --- a/tests/gnrc_netif/main.c +++ b/tests/gnrc_netif/main.c @@ -106,6 +106,7 @@ static void _set_up(void) static inline void _test_init(gnrc_netif_t *netif) { (void)netif; + gnrc_netif_default_init(netif); init_called = true; }