11
#include <kernel/irq.h>
12
#include <net/l2/ethernet.h>
13
#include <net/netdevice.h>
14
#include <net/inetdevice.h>
16
#include <net/skbuff.h>
17
#include <embox/unit.h>
18
#include <net/l0/net_entry.h>
20
#include <kernel/printk.h>
21
#include <kernel/host.h>
23
EMBOX_UNIT_INIT(umether_init);
25
static int umether_xmit(struct net_device *dev, struct sk_buff *skb) {
26
struct host_net_adp *hnet = netdev_priv(dev);
28
host_net_tx(hnet, skb->mac.raw, skb->len);
34
static int umether_start(struct net_device *dev) {
35
struct host_net_adp *hnet = netdev_priv(dev);
37
return host_net_cfg(hnet, HOST_NET_START);
40
static int umether_stop(struct net_device *dev) {
41
struct host_net_adp *hnet = netdev_priv(dev);
43
return host_net_cfg(hnet, HOST_NET_STOP);
46
static int umether_setmac(struct net_device *dev, const void *addr) {
50
static irq_return_t umether_irq(unsigned int irq_num, void *dev_id) {
51
struct net_device *dev = (struct net_device *) dev_id;
52
struct host_net_adp *hnet = netdev_priv(dev);
56
while ((len = host_net_rx_count(hnet))) {
57
if (!(skb = skb_alloc(len))) {
61
host_net_rx(hnet, skb->mac.raw, len);
70
static const struct net_driver umether_drv_ops = {
72
.start = umether_start,
74
.set_macaddr = umether_setmac,
77
static int umether_init(void) {
79
struct net_device *nic;
80
struct host_net_adp *hnet;
82
nic = etherdev_alloc(sizeof(struct host_net_adp));
87
nic->drv_ops = &umether_drv_ops;
88
nic->irq = HOST_NET_IRQ;
90
hnet = netdev_priv(nic);
92
res = host_net_cfg(hnet, HOST_NET_INIT);
95
printk("usermode: can't init network: %s\n", strerror(-res));
99
res = irq_attach(HOST_NET_IRQ, umether_irq, IF_SHARESUP, nic,
105
return inetdev_register_dev(nic);