From d99972791a3573cdcfe58ea0058023b2bca6cb05 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 28 Jul 2021 00:25:03 +0200 Subject: [PATCH] gnrc/rpl: add gnrc_rpl_configure_root() convenience function --- sys/include/net/gnrc/rpl.h | 12 ++++++++++++ sys/net/gnrc/routing/rpl/gnrc_rpl.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/sys/include/net/gnrc/rpl.h b/sys/include/net/gnrc/rpl.h index f792b5ace1..e5fb179075 100644 --- a/sys/include/net/gnrc/rpl.h +++ b/sys/include/net/gnrc/rpl.h @@ -736,6 +736,18 @@ static inline void gnrc_rpl_config_pio(gnrc_rpl_dodag_t *dodag, bool status) } } +#if IS_USED(MODULE_GNRC_RPL) || DOXYGEN +/** + * @brief Convenience function to start a RPL root using the default configuration. + * + * @param[in] netif Network interface to use as RPL root + * @param[in] dodag_id Id of the DODAG + */ +void gnrc_rpl_configure_root(gnrc_netif_t *netif, const ipv6_addr_t *dodag_id); +#else +#define gnrc_rpl_configure_root(netif, dodag_id) ((void)netif) +#endif + #ifdef __cplusplus } #endif diff --git a/sys/net/gnrc/routing/rpl/gnrc_rpl.c b/sys/net/gnrc/routing/rpl/gnrc_rpl.c index 35879e2bca..1b4c7c80e2 100644 --- a/sys/net/gnrc/routing/rpl/gnrc_rpl.c +++ b/sys/net/gnrc/routing/rpl/gnrc_rpl.c @@ -419,6 +419,18 @@ uint8_t gnrc_rpl_gen_instance_id(bool local) return instance_id; } +void gnrc_rpl_configure_root(gnrc_netif_t *netif, const ipv6_addr_t *dodag_id) +{ + gnrc_rpl_init(netif->pid); + gnrc_rpl_instance_t *inst = gnrc_rpl_instance_get( + CONFIG_GNRC_RPL_DEFAULT_INSTANCE + ); + if (inst) { + gnrc_rpl_instance_remove(inst); + } + gnrc_rpl_root_init(CONFIG_GNRC_RPL_DEFAULT_INSTANCE, dodag_id, false, false); +} + /** * @} */