minor fixes for safecopy & safemap tests
[minix.git] / servers / lwip / eth.c
blob9e15bbfb8cb20def96ecbe86d9d29506a78edfab
1 /**
2 * @file
3 * Ethernet Interface Skeleton
5 */
7 /*
8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
14 * 1. Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 * OF SUCH DAMAGE.
33 * This file is part of the lwIP TCP/IP stack.
35 * Author: Adam Dunkels <adam@sics.se>
40 * This file is a skeleton for developing Ethernet network interface
41 * drivers for lwIP. Add code to the low_level functions and do a
42 * search-and-replace for the word "ethernetif" to replace it with
43 * something that better describes your network interface.
46 #include <minix/sysutil.h>
48 #include "lwip/opt.h"
50 #include "lwip/def.h"
51 #include "lwip/mem.h"
52 #include "lwip/pbuf.h"
53 #include "lwip/sys.h"
54 #include <lwip/stats.h>
55 #include <lwip/snmp.h>
56 #include <netif/etharp.h>
58 #include <net/gen/ether.h>
59 #include <net/gen/eth_io.h>
61 #include "proto.h"
62 #include "driver.h"
64 extern endpoint_t lwip_ep;
66 static err_t low_level_output(__unused struct netif *netif, struct pbuf *pbuf)
68 struct nic * nic;
70 nic = (struct nic *) netif->state;
71 assert(&nic->netif == netif);
73 debug_print("device /dev/%s", nic->name);
75 if (driver_tx_enqueue(nic, pbuf) != OK)
76 return ERR_MEM;
78 /* if the driver is idle, start transmitting the packet */
79 if (nic->state == DRV_IDLE) {
80 if (!driver_tx(nic))
81 return ERR_MEM;
84 return ERR_OK;
87 static void low_level_init(struct netif *netif)
89 message m;
90 struct nic * nic = (struct nic *) netif->state;
92 assert(nic);
94 /* set MAC hardware address length */
95 netif->hwaddr_len = ETHARP_HWADDR_LEN;
97 /* maximum transfer unit */
98 netif->mtu = 1500;
99 nic->max_pkt_sz = ETH_MAX_PACK_SIZE;
100 nic->min_pkt_sz = ETH_MIN_PACK_SIZE;
102 /* device capabilities */
103 netif->flags = NETIF_FLAG_ETHARP;
105 m.DL_MODE = DL_NOMODE;
106 if (nic->flags & NWEO_EN_BROAD)
107 m.DL_MODE |= DL_BROAD_REQ;
108 if (nic->flags & NWEO_EN_MULTI)
109 m.DL_MODE |= DL_MULTI_REQ;
110 if (nic->flags & NWEO_EN_PROMISC)
111 m.DL_MODE |= DL_PROMISC_REQ;
113 m.m_type = DL_CONF;
115 if (asynsend(((struct nic *)netif->state)->drv_ep , &m) != OK)
116 printf("LWIP : ERROR cannot send DL_CONF to driver\n");
120 err_t ethernetif_init(struct netif *netif)
123 * Initialize the snmp variables and counters inside the struct netif.
124 * The last argument should be replaced with your link speed, in units
125 * of bits per second.
126 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
129 netif->output = etharp_output;
130 netif->linkoutput = low_level_output;
132 /* initialize the hardware */
133 low_level_init(netif);
135 return ERR_OK;