2019-07-22 13:32:39 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 HAW Hamburg
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @author Jose I. Alamos <jose.alamos@haw-hamburg.de>
|
|
|
|
*/
|
|
|
|
|
2020-10-21 15:58:33 +02:00
|
|
|
#include <assert.h>
|
2019-07-22 13:32:39 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "errno.h"
|
2021-02-02 16:45:21 +01:00
|
|
|
#include "irq.h"
|
2019-07-22 13:32:39 +02:00
|
|
|
#include "net/netif.h"
|
|
|
|
#include "utlist.h"
|
|
|
|
|
|
|
|
static list_node_t netif_list;
|
|
|
|
|
|
|
|
int netif_register(netif_t *netif)
|
|
|
|
{
|
2021-02-02 16:45:21 +01:00
|
|
|
if (netif == NULL) {
|
2019-07-22 13:32:39 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-02-02 16:45:21 +01:00
|
|
|
unsigned state = irq_disable();
|
2019-07-22 13:32:39 +02:00
|
|
|
list_add(&netif_list, &netif->node);
|
2021-02-02 16:45:21 +01:00
|
|
|
irq_restore(state);
|
|
|
|
|
2019-07-22 13:32:39 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
netif_t *netif_iter(netif_t *last)
|
|
|
|
{
|
|
|
|
if (last == NULL) {
|
|
|
|
return (netif_t *)netif_list.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (netif_t *)last->node.next;
|
|
|
|
}
|
|
|
|
|
2019-11-18 13:51:11 +01:00
|
|
|
__attribute__((weak)) int16_t netif_get_id(const netif_t *netif)
|
|
|
|
{
|
|
|
|
list_node_t *node = netif_list.next;
|
|
|
|
for (int16_t i = 0; node; i++, node = node->next) {
|
|
|
|
if (netif == (netif_t *)node) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-07-22 13:32:39 +02:00
|
|
|
netif_t *netif_get_by_name(const char *name)
|
|
|
|
{
|
|
|
|
assert(name);
|
|
|
|
list_node_t *node = netif_list.next;
|
|
|
|
|
2020-07-28 19:32:12 +02:00
|
|
|
char tmp[CONFIG_NETIF_NAMELENMAX];
|
2019-07-22 13:32:39 +02:00
|
|
|
|
2021-02-02 16:45:21 +01:00
|
|
|
while (node) {
|
2019-07-22 13:32:39 +02:00
|
|
|
netif_get_name((netif_t *)node, tmp);
|
2021-02-02 16:45:21 +01:00
|
|
|
if (strncmp(name, tmp, CONFIG_NETIF_NAMELENMAX) == 0) {
|
2019-07-22 13:32:39 +02:00
|
|
|
return (netif_t *)node;
|
|
|
|
}
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-11-18 13:51:11 +01:00
|
|
|
|
|
|
|
__attribute__((weak)) netif_t *netif_get_by_id(int16_t id)
|
|
|
|
{
|
|
|
|
list_node_t *node = netif_list.next;
|
|
|
|
for (int16_t i = 0; node; i++, node = node->next) {
|
|
|
|
if (i == id) {
|
|
|
|
return (netif_t *)node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-22 13:32:39 +02:00
|
|
|
/** @} */
|