home *** CD-ROM | disk | FTP | other *** search
- /* PPPdriver.c
- * (c) Andrew Draper 1993
- * This code may be distributed freely as long as no
- * charge is made (except a small charge for the
- * media involved).
- */
-
- #include "kernel.h"
-
- #include <stdlib.h>
- #include <string.h>
-
- #include "GLOBAL.h"
- #include "IFACE.h"
- #include "MBUF.h"
- #include "TIMER.h"
- #include "TRACE.h"
- #include "MISC.h"
-
- #include "IP.h"
-
- #include "PPPDriver.h"
-
- /* Put these lines into the cmnds_attab structure
- * / Internet PPP driver /
- * "ppp", ppp_attach, 1,
- * "attach ppp",
- * "Could not attach ppp",
- */
-
- static int ppp_send(struct mbuf *data, struct interface *interface,
- int32 gateway, char precedence, char delay,
- char throughput, char reliability);
-
- static void ppp_recv(struct interface *interface);
-
- static int ppp_stop(struct interface *interface);
-
-
- int ppp_attach(int argc, char **argv)
- {
- register struct interface *if_drv;
- extern struct interface *ifaces;
- int dev,ndev,mtu,n;
- char *name;
-
- n = 0;
- for (dev = 0 ; dev >= 0 ; dev = ndev)
- {
- name = NULL; /* Set it here just in case there's an error */
- ndev = pppmod_find(dev,0,&name,&mtu);
-
- if (name != NULL)
- {
- if_drv = (struct interface *)calloc(1,sizeof(struct interface));
- memset(if_drv, '\0', sizeof(struct interface));
-
- if_drv->name = malloc((unsigned)strlen(name)+1);
- strcpy(if_drv->name,name);
-
- if_drv->ioctl = NULLFP;
- if_drv->send = (int(*)())ppp_send;
- if_drv->output = NULLFP;
- if_drv->raw = NULLFP;
- if_drv->recv = ppp_recv;
- if_drv->stop = ppp_stop;
- if_drv->flags = 0;
-
- if_drv->mtu = mtu;
- if_drv->dev = dev;
-
- if_drv->next = ifaces;
- ifaces = if_drv;
-
- if (n++ == 0)
- cwprintf(NULL, "Attaching %s",name);
- else
- cwprintf(NULL, ",%s",name);
- }
- }
-
- if (n == 0)
- cwprintf(NULL, "Can't find ppp driver module\n");
- else
- cwprintf(NULL, "\n");
-
- return 0;
- }
-
- static int ppp_send(struct mbuf *data, struct interface *interface,
- int32 gateway, char precedence, char delay,
- char throughput, char reliability)
- {
- struct mbuf *send;
- register char *cp;
- char c;
-
- if (interface == NULLIF)
- {
- free_p(data);
- return -1;
- }
-
- dump(interface,IF_TRACE_OUT,TRACE_IP,data);
-
- send = alloc_mbuf(len_mbuf(data));
- cp = send->data;
- while(pullone(&data,&c) == 1)
- *cp++ = c;
-
- pppmod_txpacket(interface->dev, send->data, cp - send->data, gateway);
- free_p(send);
- return 0;
-
- precedence = precedence;
- delay = delay;
- throughput = throughput;
- reliability = reliability;
- }
-
- static void ppp_recv(struct interface *interface)
- {
- static struct mbuf *recv = NULLBUF;
-
- /* allocate a buffer if we don't have one */
- if (recv == NULLBUF)
- {
- recv = alloc_mbuf(interface->mtu);
- if (recv == NULLBUF)
- return;
- }
-
- /* try to get a received buffer */
- recv->cnt = pppmod_rxpacket(interface->dev, recv->data, recv->size);
- if (recv->cnt != 0)
- {
- recv->size = recv->cnt;
- dump(interface,IF_TRACE_IN,TRACE_IP,recv);
- ip_route(recv,0);
- recv = NULLBUF;
- }
- }
-
- static int ppp_stop(struct interface *interface)
- {
- pppmod_close(interface->dev);
-
- return 0;
- }
-