2018-03-28 21:59:45 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2018-11-30 18:54:56 +08:00
|
|
|
#include <logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(net_ethernet_stats, CONFIG_NET_L2_ETHERNET_LOG_LEVEL);
|
2018-07-06 16:35:07 +08:00
|
|
|
|
2018-03-28 21:59:45 +08:00
|
|
|
#include <kernel.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <net/net_core.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
|
|
|
|
#include "net_stats.h"
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_STATISTICS_USER_API)
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
static int eth_stats_get(uint32_t mgmt_request, struct net_if *iface,
|
2018-03-28 21:59:45 +08:00
|
|
|
void *data, size_t len)
|
|
|
|
{
|
|
|
|
size_t len_chk = 0;
|
|
|
|
void *src = NULL;
|
2018-07-26 16:07:44 +08:00
|
|
|
const struct ethernet_api *eth;
|
2018-03-28 21:59:45 +08:00
|
|
|
|
|
|
|
switch (NET_MGMT_GET_COMMAND(mgmt_request)) {
|
|
|
|
case NET_REQUEST_STATS_CMD_GET_ETHERNET:
|
|
|
|
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2020-05-29 03:23:02 +08:00
|
|
|
eth = net_if_get_device(iface)->api;
|
2019-04-16 04:58:00 +08:00
|
|
|
if (eth == NULL || eth->get_stats == NULL) {
|
2018-07-19 13:06:56 +08:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2018-03-28 21:59:45 +08:00
|
|
|
len_chk = sizeof(struct net_stats_eth);
|
2018-07-26 16:04:47 +08:00
|
|
|
src = eth->get_stats(net_if_get_device(iface));
|
2018-03-28 21:59:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len != len_chk || !src) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(data, src, len);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_GET_ETHERNET,
|
|
|
|
eth_stats_get);
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_STATISTICS_USER_API */
|