1 /*
2 * Copyright (c) 2013 Corey Tabaka
3 *
4 * Use of this source code is governed by a MIT-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/MIT
7 */
8
9 #include <lk/err.h>
10 #include <dev/class/netif.h>
11
class_netif_set_state(struct device * dev,struct netstack_state * state)12 status_t class_netif_set_state(struct device *dev, struct netstack_state *state) {
13 struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
14 if (!ops)
15 return ERR_NOT_CONFIGURED;
16
17 if (ops->set_state)
18 return ops->set_state(dev, state);
19 else
20 return ERR_NOT_SUPPORTED;
21 }
22
class_netif_get_hwaddr(struct device * dev,void * buf,size_t max_len)23 ssize_t class_netif_get_hwaddr(struct device *dev, void *buf, size_t max_len) {
24 struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
25 if (!ops)
26 return ERR_NOT_CONFIGURED;
27
28 if (ops->get_hwaddr)
29 return ops->get_hwaddr(dev, buf, max_len);
30 else
31 return ERR_NOT_SUPPORTED;
32 }
33
class_netif_get_mtu(struct device * dev)34 ssize_t class_netif_get_mtu(struct device *dev) {
35 struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
36 if (!ops)
37 return ERR_NOT_CONFIGURED;
38
39 if (ops->get_mtu)
40 return ops->get_mtu(dev);
41 else
42 return ERR_NOT_SUPPORTED;
43 }
44
class_netif_set_status(struct device * dev,bool up)45 status_t class_netif_set_status(struct device *dev, bool up) {
46 struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
47 if (!ops)
48 return ERR_NOT_CONFIGURED;
49
50 if (ops->set_status)
51 return ops->set_status(dev, up);
52 else
53 return ERR_NOT_SUPPORTED;
54 }
55
class_netif_output(struct device * dev,struct pbuf * p)56 status_t class_netif_output(struct device *dev, struct pbuf *p) {
57 struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
58 if (!ops)
59 return ERR_NOT_CONFIGURED;
60
61 if (ops->output)
62 return ops->output(dev, p);
63 else
64 return ERR_NOT_SUPPORTED;
65 }
66
class_netif_mcast_filter(struct device * dev,const uint8_t * mac,int action)67 status_t class_netif_mcast_filter(struct device *dev, const uint8_t *mac, int action) {
68 struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
69 if (!ops)
70 return ERR_NOT_CONFIGURED;
71
72 if (ops->mcast_filter)
73 return ops->mcast_filter(dev, mac, action);
74 else
75 return ERR_NOT_SUPPORTED;
76 }
77
78