home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include "werr.h"
- #include "kernel.h"
- #include "global.h"
- #include "mbuf.h"
- #include "internet.h"
- #include "iface.h"
- #include "cmdparse.h"
- #include "misc.h"
- #include "aun.h"
- #include "arc.h"
- #include "os.h"
- #include "swis.h"
- #include "timer.h"
- #include "ip.h"
- #include "trace.h"
- #include "wimpt.h"
- #include "bbc.h"
-
- struct aun aun[AUN_MAX];
- unsigned int naun;
- extern struct interface *ifaces;
-
- extern char nospace[];
-
- static int aun_init(int16, struct interface *, int);
- static int aun_stop(struct interface *);
- static int aun_send(struct mbuf *, struct interface *, int32, int, int, int, int);
- static void aun_recv(struct interface *);
-
- /* Attach an aun interface to the system
- * argv[0]: hardware type, must be "aun"
- * argv[1]: interface label, e.g., "ka0"
- */
- int aun_attach(int argc, char **argv)
- {
- struct interface *if_aun;
- int16 dev;
-
- argc = argc;
-
- if (naun >= AUN_MAX){
- cwprintf(NULL,"Too many AUN controllers\n");
- return 0;
- }
-
- dev = naun;
-
- /* Create interface structure and fill in details */
- if_aun = (struct interface *)calloc(1,sizeof(struct interface));
- if_aun->name = strdup(argv[1]);
- if_aun->mtu = 1500;
- if_aun->dev = dev;
- if_aun->recv = aun_recv;
- if_aun->stop = aun_stop;
- if_aun->send = aun_send;
- if_aun->output = NULLFP;
- if_aun->raw = NULLFP;
- if_aun->ioctl = NULLFP;
- if_aun->flags = 0;
- if_aun->trace = 0;
- if_aun->forw = NULLIF;
- if (!aun_init(dev, if_aun, 0))
- {
- cwprintf(NULL, "Unable to attach AUN device\r\n");
- free(if_aun);
- }
- else
- {
- naun++;
- if_aun->next = ifaces;
- ifaces = if_aun;
- }
- return 0;
- }
-
- /* Initialize aun port "dev" */
- static int aun_init(int16 dev, struct interface *iface, int port)
- {
- _kernel_swi_regs rin, rout;
-
- aun[dev].iface = iface;
- aun[dev].port = port;
-
- rin.r[0] = port;
- rin.r[1] = (int)wimpt_task();
- rin.r[2] = (int)NULL; /* pollword */
- rin.r[3] = 0; /* pollflag */
- return (_kernel_swi(AUN_OPEN, &rin, &rout)==NULL);
- }
-
- static int aun_stop(struct interface *iface)
- {
- _kernel_swi_regs rin, rout;
-
- rin.r[0] = aun[iface->dev].port;
- _kernel_swi(AUN_CLOSE, &rin, &rout);
-
- return(0);
- }
-
- /* Send a packet to transmitter */
- static int aun_send(struct mbuf *bp, struct interface *iface, int32 gateway, int precedence, int delay, int throughput, int reliability)
- {
- _kernel_swi_regs rin, rout;
- char buffer[1500];
- int size;
-
- gateway = gateway;
- precedence = precedence;
- delay = delay;
- throughput = throughput;
- reliability = reliability;
-
- dump(iface, IF_TRACE_OUT, TRACE_IP, bp);
-
- size = dqdata(bp, buffer, iface->mtu);
-
- rin.r[0] = aun[iface->dev].port;
- rin.r[1] = (int)buffer;
- rin.r[2] = size;
- _kernel_swi(AUN_WRITE, &rin, &rout);
-
- return(0);
- }
-
- /* Receive characters from line
- * Returns count of characters read
- */
- static void aun_recv(struct interface *iface)
- {
- _kernel_oserror *e;
- _kernel_swi_regs rin, rout;
- struct mbuf *bp;
-
- while (1)
- {
- if ((bp = alloc_mbuf(iface->mtu)) == NULLBUF) return;
-
- rin.r[0] = aun[iface->dev].port;
- rin.r[1] = (int)bp->data;
- rin.r[2] = iface->mtu;
- e = _kernel_swi(AUN_READ, &rin, &rout);
-
- if (e!=NULL || (bp->cnt = rout.r[0]) == 0)
- {
- free_p(bp);
- return;
- }
- else
- {
- dump(iface, IF_TRACE_IN, TRACE_IP, bp);
- ip_route(bp, 0);
- }
- }
-
- return;
- }
-