1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

net/gnrc_netif: add return values to init

This commit is contained in:
Jose Alamos 2021-09-29 16:52:58 +02:00
parent f33b3ad10d
commit e7fac9f661
No known key found for this signature in database
GPG Key ID: F483EB800EF89DD9
7 changed files with 36 additions and 20 deletions

View File

@ -79,7 +79,7 @@ static void _notify(int handle, nimble_netif_event_t event, uint8_t *addr)
}
}
static void _netif_init(gnrc_netif_t *netif)
static int _netif_init(gnrc_netif_t *netif)
{
(void)netif;
@ -92,6 +92,8 @@ static void _netif_init(gnrc_netif_t *netif)
* of this */
_netif.sixlo.max_frag_size = 0;
#endif /* IS_USED(MODULE_GNRC_NETIF_6LO) */
return 0;
}
static int _send_pkt(nimble_netif_conn_t *conn, gnrc_pktsnip_t *pkt)

View File

@ -194,21 +194,26 @@ typedef struct {
*/
struct gnrc_netif_ops {
/**
* @brief Initializes network interface beyond the default settings
* @brief Initializes network interface.
*
* @pre `netif != NULL`
*
* @param[in] netif The network interface.
*
* 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.
* This function should init the device driver or MAC underlying MAC layer.
* This is called 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.
*
* @return 0 if the initialization of the device or MAC layer was
* successful
* @return negative errno on error.
*/
void (*init)(gnrc_netif_t *netif);
int (*init)(gnrc_netif_t *netif);
/**
* @brief Send a @ref net_gnrc_pkt "packet" over the network interface
@ -537,7 +542,7 @@ static inline int gnrc_netif_ipv6_group_leave(const gnrc_netif_t *netif,
*
* @param[in] netif The network interface.
*/
void gnrc_netif_default_init(gnrc_netif_t *netif);
int gnrc_netif_default_init(gnrc_netif_t *netif);
/**
* @brief Default operation for gnrc_netif_ops_t::get()

View File

@ -55,7 +55,7 @@
*/
static kernel_pid_t gomach_pid;
static void _gomach_init(gnrc_netif_t *netif);
static int _gomach_init(gnrc_netif_t *netif);
static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt);
static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif);
static void _gomach_msg_handler(gnrc_netif_t *netif, msg_t *msg);
@ -2115,7 +2115,7 @@ static void _gomach_event_cb(netdev_t *dev, netdev_event_t event)
}
}
static void _gomach_init(gnrc_netif_t *netif)
static int _gomach_init(gnrc_netif_t *netif)
{
netdev_t *dev;
@ -2216,4 +2216,6 @@ static void _gomach_init(gnrc_netif_t *netif)
gnrc_gomach_set_update(netif, false);
gomach_update(netif);
}
return 0;
}

View File

@ -63,7 +63,7 @@ static void rtt_cb(void *arg);
static void lwmac_set_state(gnrc_netif_t *netif, gnrc_lwmac_state_t newstate);
static void lwmac_schedule_update(gnrc_netif_t *netif);
static void rtt_handler(uint32_t event, gnrc_netif_t *netif);
static void _lwmac_init(gnrc_netif_t *netif);
static int _lwmac_init(gnrc_netif_t *netif);
static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt);
static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif);
static void _lwmac_msg_handler(gnrc_netif_t *netif, msg_t *msg);
@ -939,7 +939,7 @@ static void _lwmac_msg_handler(gnrc_netif_t *netif, msg_t *msg)
}
}
static void _lwmac_init(gnrc_netif_t *netif)
static int _lwmac_init(gnrc_netif_t *netif)
{
netdev_t *dev;
@ -984,4 +984,6 @@ static void _lwmac_init(gnrc_netif_t *netif)
netif->mac.prot.lwmac.awake_duration_sum_ticks = 0;
netif->mac.prot.lwmac.lwmac_info |= GNRC_LWMAC_RADIO_IS_ON;
#endif
return 0;
}

View File

@ -1577,7 +1577,7 @@ static void _test_options(gnrc_netif_t *netif)
}
#endif /* DEVELHELP */
void gnrc_netif_default_init(gnrc_netif_t *netif)
int gnrc_netif_default_init(gnrc_netif_t *netif)
{
_init_from_device(netif);
#ifdef DEVELHELP
@ -1590,6 +1590,7 @@ void gnrc_netif_default_init(gnrc_netif_t *netif)
#ifdef MODULE_GNRC_IPV6_NIB
gnrc_ipv6_nib_init_iface(netif);
#endif
return 0;
}
static void _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt, bool push_back);

View File

@ -48,7 +48,7 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif);
static void _msg_handler(gnrc_netif_t *netif, msg_t *msg);
static int _get(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt);
static int _set(gnrc_netif_t *netif, const gnrc_netapi_opt_t *opt);
static void _init(gnrc_netif_t *netif);
static int _init(gnrc_netif_t *netif);
static const gnrc_netif_ops_t lorawan_ops = {
.init = _init,
@ -252,7 +252,7 @@ netdev_t *gnrc_lorawan_get_netdev(gnrc_lorawan_t *mac)
return netif->dev;
}
static void _init(gnrc_netif_t *netif)
static int _init(gnrc_netif_t *netif)
{
gnrc_netif_default_init(netif);
netif->dev->event_callback = _driver_cb;
@ -279,6 +279,8 @@ static void _init(gnrc_netif_t *netif)
ztimer_set_msg(ZTIMER_MSEC, &netif->lorawan.backoff_timer,
GNRC_LORAWAN_BACKOFF_WINDOW_TICK / 1000,
&backoff_msg, thread_getpid());
return 0;
}
int gnrc_netif_lorawan_create(gnrc_netif_t *netif, char *stack, int stacksize,

View File

@ -55,7 +55,7 @@ static bool init_called = false;
static uint8_t ethernet_groups[ETHERNET_GROUPS_MAX][ETHERNET_ADDR_LEN];
static BITFIELD(ethernet_groups_set, ETHERNET_GROUPS_MAX);
static inline void _test_init(gnrc_netif_t *netif);
static inline int _test_init(gnrc_netif_t *netif);
static inline int _mock_netif_send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt);
static inline gnrc_pktsnip_t *_mock_netif_recv(gnrc_netif_t * netif);
static int _get_netdev_address(netdev_t *dev, void *value, size_t max_len);
@ -113,11 +113,13 @@ static void _set_up(void)
while (msg_try_receive(&msg) > 0) {}
}
static inline void _test_init(gnrc_netif_t *netif)
static inline int _test_init(gnrc_netif_t *netif)
{
(void)netif;
gnrc_netif_default_init(netif);
init_called = true;
return 0;
}
static void test_creation(void)