home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / internet / tcpip / src205 / TCPIP_Src / Drivers / c / PPPdriver < prev    next >
Encoding:
Text File  |  1995-03-13  |  3.6 KB  |  182 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. /*
  122.  * Something wrong with this so have ditched it...
  123.  */
  124.  
  125. #ifdef BUGGY
  126. static void ppp_recv(struct interface *interface)
  127. {
  128.   static struct mbuf *recv = NULLBUF;
  129.  
  130.   /* allocate a buffer if we don't have one */
  131.   if (recv == NULLBUF)
  132.   {
  133.     recv = alloc_mbuf(interface->mtu);
  134.     if (recv == NULLBUF)
  135.       return;
  136.   }
  137.  
  138.   /* try to get a received buffer */
  139.   recv->cnt = pppmod_rxpacket(interface->dev, recv->data, recv->size);
  140.   if (recv->cnt != 0)
  141.   {
  142.     recv->size = recv->cnt;
  143.     dump(interface,IF_TRACE_IN,TRACE_IP,recv);
  144.     ip_route(recv,0);
  145.     recv = NULLBUF;
  146.   }
  147. }
  148. #endif
  149.  
  150. static void ppp_recv(struct interface *iface)
  151. {
  152.   struct mbuf *bp;
  153.  
  154.   for (;;)
  155.   {
  156.     if ((bp = alloc_mbuf(iface->mtu)) == NULLBUF)
  157.       return;
  158.  
  159.     bp->cnt = pppmod_rxpacket(iface->dev, bp->data, iface->mtu);
  160.  
  161.     if (bp->cnt==0)
  162.     {
  163.       free_p(bp);
  164.       return;
  165.     }
  166.     else
  167.     {
  168.       dump(iface, IF_TRACE_IN, TRACE_IP, bp);
  169.       ip_route(bp, 0);
  170.     }
  171.   }
  172.   return;
  173. }
  174.  
  175.  
  176. static int ppp_stop(struct interface *interface)
  177. {
  178.   pppmod_close(interface->dev);
  179.  
  180.   return 0;
  181. }
  182.