home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / internet / tcpip / src205 / TCPIP_Src / Drivers / c / aun < prev    next >
Encoding:
Text File  |  1995-02-28  |  3.9 KB  |  162 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include "werr.h"
  6. #include "kernel.h"
  7. #include "global.h"
  8. #include "mbuf.h"
  9. #include "internet.h"
  10. #include "iface.h"
  11. #include "cmdparse.h"
  12. #include "misc.h"
  13. #include "aun.h"
  14. #include "arc.h"
  15. #include "os.h"
  16. #include "swis.h"
  17. #include "timer.h"
  18. #include "ip.h"
  19. #include "trace.h"
  20. #include "wimpt.h"
  21. #include "bbc.h"
  22.  
  23. struct aun aun[AUN_MAX];
  24. unsigned int naun;
  25. extern struct interface *ifaces;
  26.  
  27. extern char nospace[];
  28.  
  29. static int aun_init(int16, struct interface *, int);
  30. static int aun_stop(struct interface *);
  31. static int aun_send(struct mbuf *, struct interface *, int32, int, int, int, int);
  32. static void aun_recv(struct interface *);
  33.  
  34. /* Attach an aun interface to the system
  35.  * argv[0]: hardware type, must be "aun"
  36.  * argv[1]: interface label, e.g., "ka0"
  37.  */
  38. int aun_attach(int argc, char **argv)
  39. {
  40.         struct interface *if_aun;
  41.         int16 dev;
  42.  
  43.         argc = argc;
  44.  
  45.         if (naun >= AUN_MAX){
  46.                 cwprintf(NULL,"Too many AUN controllers\n");
  47.                 return 0;
  48.         }
  49.  
  50.         dev = naun;
  51.  
  52.         /* Create interface structure and fill in details */
  53.         if_aun = (struct interface *)calloc(1,sizeof(struct interface));
  54.         if_aun->name   = strdup(argv[1]);
  55.         if_aun->mtu    = 1500;
  56.         if_aun->dev    = dev;
  57.         if_aun->recv   = aun_recv;
  58.         if_aun->stop   = aun_stop;
  59.         if_aun->send   = aun_send;
  60.         if_aun->output = NULLFP;
  61.         if_aun->raw    = NULLFP;
  62.         if_aun->ioctl  = NULLFP;
  63.         if_aun->flags  = 0;
  64.         if_aun->trace  = 0;
  65.         if_aun->forw   = NULLIF;
  66.         if (!aun_init(dev, if_aun, 0))
  67.         {
  68.           cwprintf(NULL, "Unable to attach AUN device\r\n");
  69.           free(if_aun);
  70.         }
  71.         else
  72.         {
  73.           naun++;
  74.           if_aun->next = ifaces;
  75.           ifaces = if_aun;
  76.         }
  77.         return 0;
  78. }
  79.  
  80. /* Initialize aun port "dev" */
  81. static int aun_init(int16 dev, struct interface *iface, int port)
  82. {
  83.         _kernel_swi_regs rin, rout;
  84.  
  85.         aun[dev].iface = iface;
  86.         aun[dev].port  = port;
  87.  
  88.         rin.r[0] = port;
  89.         rin.r[1] = (int)wimpt_task();
  90.         rin.r[2] = (int)NULL;  /* pollword */
  91.         rin.r[3] = 0;          /* pollflag */
  92.         return (_kernel_swi(AUN_OPEN, &rin, &rout)==NULL);
  93. }
  94.  
  95. static int aun_stop(struct interface *iface)
  96. {
  97.         _kernel_swi_regs rin, rout;
  98.  
  99.         rin.r[0] = aun[iface->dev].port;
  100.         _kernel_swi(AUN_CLOSE, &rin, &rout);
  101.  
  102.         return(0);
  103. }
  104.  
  105. /* Send a packet to transmitter */
  106. static int aun_send(struct mbuf *bp, struct interface *iface, int32 gateway, int precedence, int delay, int throughput, int reliability)
  107. {
  108.         _kernel_swi_regs rin, rout;
  109.         char buffer[1500];
  110.         int size;
  111.  
  112.         gateway     = gateway;
  113.         precedence  = precedence;
  114.         delay       = delay;
  115.         throughput  = throughput;
  116.         reliability = reliability;
  117.  
  118.         dump(iface, IF_TRACE_OUT, TRACE_IP, bp);
  119.  
  120.         size = dqdata(bp, buffer, iface->mtu);
  121.  
  122.         rin.r[0] = aun[iface->dev].port;
  123.         rin.r[1] = (int)buffer;
  124.         rin.r[2] = size;
  125.         _kernel_swi(AUN_WRITE, &rin, &rout);
  126.  
  127.         return(0);
  128. }
  129.  
  130. /* Receive characters from line
  131.  * Returns count of characters read
  132.  */
  133. static void aun_recv(struct interface *iface)
  134. {
  135.         _kernel_oserror *e;
  136.         _kernel_swi_regs rin, rout;
  137.         struct mbuf *bp;
  138.  
  139.         while (1)
  140.         {
  141.                 if ((bp = alloc_mbuf(iface->mtu)) == NULLBUF) return;
  142.  
  143.                 rin.r[0] = aun[iface->dev].port;
  144.                 rin.r[1] = (int)bp->data;
  145.                 rin.r[2] = iface->mtu;
  146.                 e = _kernel_swi(AUN_READ, &rin, &rout);
  147.  
  148.                 if (e!=NULL || (bp->cnt = rout.r[0]) == 0)
  149.                 {
  150.                        free_p(bp);
  151.                        return;
  152.                 }
  153.                 else
  154.                 {
  155.                   dump(iface, IF_TRACE_IN, TRACE_IP, bp);
  156.                   ip_route(bp, 0);
  157.                 }
  158.         }
  159.  
  160.         return;
  161. }
  162.