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)
|
|
|
|
|
|
|
|
static int eth_stats_get(u32_t mgmt_request, struct net_if *iface,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
eth = net_if_get_device(iface)->driver_api;
|
2018-07-19 13:06:56 +08:00
|
|
|
if (eth->get_stats == NULL) {
|
|
|
|
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 */
|