2020-07-09 01:44:11 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 ML!PA Consulting GmbH
|
|
|
|
*
|
|
|
|
* 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 Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
|
|
|
*/
|
|
|
|
|
2021-06-08 12:02:08 +02:00
|
|
|
#include "assert.h"
|
2020-07-09 01:44:11 +02:00
|
|
|
#include "eui48_provider_params.h"
|
|
|
|
#include "eui64_provider_params.h"
|
|
|
|
#include "luid.h"
|
|
|
|
#include "net/eui_provider.h"
|
|
|
|
|
2022-06-23 14:25:35 +02:00
|
|
|
static inline unsigned _get_idx(netdev_t *netdev)
|
|
|
|
{
|
|
|
|
#ifdef MODULE_NETDEV_REGISTER
|
|
|
|
return netdev->index;
|
|
|
|
#else
|
|
|
|
(void)netdev;
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-07-09 01:44:11 +02:00
|
|
|
void netdev_eui48_get(netdev_t *netdev, eui48_t *addr)
|
|
|
|
{
|
|
|
|
unsigned i = EUI48_PROVIDER_NUMOF;
|
|
|
|
while (i--) {
|
|
|
|
#ifdef MODULE_NETDEV_REGISTER
|
2021-06-08 12:02:08 +02:00
|
|
|
/* using NETDEV_ANY causes conflicts if there is another interface
|
|
|
|
* of a different type. Require EUI providers to be locked to an
|
|
|
|
* interface type for uniqueness.
|
|
|
|
*/
|
|
|
|
assert(eui48_conf[i].type != NETDEV_ANY);
|
|
|
|
|
|
|
|
if (eui48_conf[i].type != netdev->type) {
|
2020-07-09 01:44:11 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eui48_conf[i].index != netdev->index &&
|
|
|
|
eui48_conf[i].index != NETDEV_INDEX_ANY) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2022-06-23 14:25:35 +02:00
|
|
|
if (eui48_conf[i].provider(_get_idx(netdev), addr) == 0) {
|
2020-07-09 01:44:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
luid_netdev_get_eui48(netdev, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void netdev_eui64_get(netdev_t *netdev, eui64_t *addr)
|
|
|
|
{
|
|
|
|
unsigned i = EUI64_PROVIDER_NUMOF;
|
|
|
|
while (i--) {
|
|
|
|
#ifdef MODULE_NETDEV_REGISTER
|
2021-06-08 12:02:08 +02:00
|
|
|
/* using NETDEV_ANY causes conflicts if there is another interface
|
|
|
|
* of a different type. Require EUI providers to be locked to an
|
|
|
|
* interface type for uniqueness.
|
|
|
|
*/
|
|
|
|
assert(eui64_conf[i].type != NETDEV_ANY);
|
|
|
|
|
|
|
|
if (eui64_conf[i].type != netdev->type) {
|
2020-07-09 01:44:11 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eui64_conf[i].index != netdev->index &&
|
|
|
|
eui64_conf[i].index != NETDEV_INDEX_ANY) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2022-06-23 14:25:35 +02:00
|
|
|
if (eui64_conf[i].provider(_get_idx(netdev), addr) == 0) {
|
2020-07-09 01:44:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
luid_netdev_get_eui64(netdev, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|