1 /* $NetBSD: netif_small.c,v 1.12 2009/10/21 23:12:09 snj Exp $ */
3 /* minimal netif - for boot ROMs we don't have to select between
4 several interfaces, and we have to save space
6 hacked from netbsd:sys/arch/mvme68k/stand/libsa/netif.c
10 * Copyright (c) 1995 Gordon W. Ross
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
35 #include <sys/socket.h>
37 #include <lib/libkern/libkern.h>
43 #include <net/if_ether.h>
45 #include <netinet/in.h>
46 #include <netinet/in_systm.h>
48 #include <lib/libsa/stand.h>
49 #include <lib/libsa/net.h>
51 #include "netif_small.h"
58 /* we allow for one socket only */
59 static struct iodesc iosocket
;
78 printf("netif_open: device busy\n");
82 memset(io
, 0, sizeof(*io
));
84 if (!EtherInit(io
->myea
)) {
85 printf("EtherInit failed\n");
89 io
->io_netif
= (void*)1; /* mark busy */
111 * Send a packet. The ether header is already there.
112 * Return the length sent (or -1 on error).
115 netif_put(struct iodesc
*desc
, void *pkt
, size_t len
)
119 struct ether_header
*eh
;
121 printf("netif_put: desc=%p pkt=%p len=%d\n",
124 printf("dst: %s ", ether_sprintf(eh
->ether_dhost
));
125 printf("src: %s ", ether_sprintf(eh
->ether_shost
));
126 printf("type: 0x%x\n", eh
->ether_type
& 0xFFFF);
129 return EtherSend(pkt
, len
);
133 * Receive a packet, including the ether header.
134 * Return the total length received (or -1 on error).
137 netif_get(struct iodesc
*desc
, void *pkt
, size_t maxlen
, saseconds_t timo
)
144 printf("netif_get: pkt=%p, maxlen=%d, tmo=%d\n",
150 while (((getsecs() - t
) < timo
) && !len
) {
151 len
= EtherReceive(pkt
, maxlen
);
156 struct ether_header
*eh
= pkt
;
158 printf("dst: %s ", ether_sprintf(eh
->ether_dhost
));
159 printf("src: %s ", ether_sprintf(eh
->ether_shost
));
160 printf("type: 0x%x\n", eh
->ether_type
& 0xFFFF);