home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / tcpipsrc / Drivers / c / PPPdriver < prev    next >
Text File  |  1994-06-24  |  3KB  |  150 lines

  1. /* PPPdriver.c
  2.  * (c) Andrew Draper 1993
  3.  * This code may be distributed freely as long as no
  4.  * charge is made (except a small charge for the
  5.  * media involved).
  6.  */
  7.  
  8. #include "kernel.h"
  9.  
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #include "GLOBAL.h"
  14. #include "IFACE.h"
  15. #include "MBUF.h"
  16. #include "TIMER.h"
  17. #include "TRACE.h"
  18. #include "MISC.h"
  19.  
  20. #include "IP.h"
  21.  
  22. #include "PPPDriver.h"
  23.  
  24. /* Put these lines into the cmnds_attab structure
  25.  *        / Internet PPP driver /
  26.  *        "ppp", ppp_attach, 1, 
  27.  *        "attach ppp",
  28.  *        "Could not attach ppp",
  29.  */
  30.  
  31. static int ppp_send(struct mbuf *data, struct interface *interface,
  32.                        int32 gateway, char precedence, char delay,
  33.                        char throughput, char reliability);
  34.  
  35. static void ppp_recv(struct interface *interface);
  36.  
  37. static int ppp_stop(struct interface *interface);
  38.  
  39.  
  40. int ppp_attach(int argc, char **argv)
  41. {
  42.   register struct interface *if_drv;
  43.   extern struct interface *ifaces;
  44.   int dev,ndev,mtu,n;
  45.   char *name;
  46.  
  47.   n = 0;
  48.   for (dev = 0 ; dev >= 0 ; dev = ndev)
  49.     {
  50.     name = NULL;  /* Set it here just in case there's an error */
  51.     ndev = pppmod_find(dev,0,&name,&mtu);
  52.  
  53.     if (name != NULL)
  54.       {
  55.       if_drv = (struct interface *)calloc(1,sizeof(struct interface));
  56.       memset(if_drv, '\0', sizeof(struct interface));
  57.  
  58.       if_drv->name = malloc((unsigned)strlen(name)+1);
  59.       strcpy(if_drv->name,name);
  60.  
  61.       if_drv->ioctl = NULLFP;
  62.       if_drv->send = (int(*)())ppp_send;
  63.       if_drv->output = NULLFP;
  64.       if_drv->raw = NULLFP;
  65.       if_drv->recv = ppp_recv;
  66.       if_drv->stop = ppp_stop;
  67.       if_drv->flags = 0;
  68.  
  69.       if_drv->mtu = mtu;
  70.       if_drv->dev = dev;
  71.  
  72.       if_drv->next = ifaces;
  73.       ifaces = if_drv;
  74.  
  75.       if (n++ == 0)
  76.         cwprintf(NULL, "Attaching %s",name);
  77.       else
  78.         cwprintf(NULL, ",%s",name);
  79.       }
  80.     }
  81.  
  82.   if (n == 0)
  83.     cwprintf(NULL, "Can't find ppp driver module\n");
  84.   else
  85.     cwprintf(NULL, "\n");
  86.  
  87.   return 0;
  88. }
  89.  
  90. static int ppp_send(struct mbuf *data, struct interface *interface,
  91.                 int32 gateway, char precedence, char delay,
  92.                 char throughput, char reliability)
  93. {
  94.   struct mbuf *send;
  95.   register char *cp;
  96.   char c;
  97.  
  98.   if (interface == NULLIF)
  99.     {
  100.     free_p(data);
  101.     return -1;
  102.     }
  103.  
  104.   dump(interface,IF_TRACE_OUT,TRACE_IP,data);
  105.  
  106.   send = alloc_mbuf(len_mbuf(data));
  107.   cp = send->data;
  108.   while(pullone(&data,&c) == 1)
  109.     *cp++ = c;
  110.  
  111.   pppmod_txpacket(interface->dev, send->data, cp - send->data, gateway);
  112.   free_p(send);
  113.   return 0;
  114.  
  115.   precedence = precedence;
  116.   delay = delay;
  117.   throughput = throughput;
  118.   reliability = reliability;
  119. }
  120.  
  121. static void ppp_recv(struct interface *interface)
  122. {
  123.   static struct mbuf *recv = NULLBUF;
  124.  
  125.   /* allocate a buffer if we don't have one */
  126.   if (recv == NULLBUF)
  127.     {
  128.     recv = alloc_mbuf(interface->mtu);
  129.     if (recv == NULLBUF)
  130.       return;
  131.     }
  132.  
  133.   /* try to get a received buffer */
  134.   recv->cnt = pppmod_rxpacket(interface->dev, recv->data, recv->size);
  135.   if (recv->cnt != 0)
  136.     {
  137.     recv->size = recv->cnt;
  138.     dump(interface,IF_TRACE_IN,TRACE_IP,recv);
  139.     ip_route(recv,0);
  140.     recv = NULLBUF;
  141.     }
  142. }
  143.  
  144. static int ppp_stop(struct interface *interface)
  145. {
  146.   pppmod_close(interface->dev);
  147.  
  148.   return 0;
  149. }
  150.