1 /*
2 * Copyright (c) 2019 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/logging/log.h>
8 LOG_MODULE_REGISTER(net_ppp_stats, CONFIG_NET_L2_PPP_LOG_LEVEL);
9
10 #include <zephyr/kernel.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <zephyr/net/net_core.h>
14 #include <zephyr/net/ppp.h>
15
16 #include "net_stats.h"
17
18 #if defined(CONFIG_NET_STATISTICS_USER_API)
19
ppp_stats_get(uint32_t mgmt_request,struct net_if * iface,void * data,size_t len)20 static int ppp_stats_get(uint32_t mgmt_request, struct net_if *iface,
21 void *data, size_t len)
22 {
23 size_t len_chk = 0;
24 void *src = NULL;
25 const struct ppp_api *ppp;
26
27 if (NET_MGMT_GET_COMMAND(mgmt_request) ==
28 NET_REQUEST_STATS_CMD_GET_PPP) {
29 if (net_if_l2(iface) != &NET_L2_GET_NAME(PPP)) {
30 return -ENOENT;
31 }
32
33 ppp = net_if_get_device(iface)->api;
34 if (ppp->get_stats == NULL) {
35 return -ENOENT;
36 }
37
38 len_chk = sizeof(struct net_stats_ppp);
39 src = ppp->get_stats(net_if_get_device(iface));
40 }
41
42 if (len != len_chk || !src) {
43 return -EINVAL;
44 }
45
46 memcpy(data, src, len);
47
48 return 0;
49 }
50
51 NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_GET_PPP,
52 ppp_stats_get);
53
54 #endif /* CONFIG_NET_STATISTICS_USER_API */
55