home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3 / hamradioversion3.0examsandprograms1992.iso / misc / 9q920411 / asy.c < prev    next >
C/C++ Source or Header  |  1992-04-06  |  3KB  |  138 lines

  1. /* Generic serial line interface routines
  2.  * Copyright 1992 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "proc.h"
  7. #include "iface.h"
  8. #include "netuser.h"
  9. #include "slhc.h"
  10. #include "8250.h"
  11. #include "asy.h"
  12. #include "ax25.h"
  13. #include "kiss.h"
  14. #include "nrs.h"
  15. #include "pktdrvr.h"
  16. #include "slip.h"
  17. #include "ppp.h"
  18. #include "commands.h"
  19.  
  20. static int asy_detach __ARGS((struct iface *ifp));
  21.  
  22. /* Attach a serial interface to the system
  23.  * argv[0]: hardware type, must be "asy"
  24.  * argv[1]: I/O address, e.g., "0x3f8"
  25.  * argv[2]: vector, e.g., "4"
  26.  * argv[3]: mode, may be:
  27.  *        "slip" (point-to-point SLIP)
  28.  *        "ax25" (AX.25 frame format in SLIP for raw TNC)
  29.  *        "nrs" (NET/ROM format serial protocol)
  30.  *        "ppp" (Point-to-Point Protocol, RFC1171, RFC1172)
  31.  * argv[4]: interface label, e.g., "sl0"
  32.  * argv[5]: receiver ring buffer size in bytes
  33.  * argv[6]: maximum transmission unit, bytes
  34.  * argv[7]: interface speed, e.g, "9600"
  35.  * argv[8]: optional flags,
  36.  *        'v' for Van Jacobson TCP header compression (SLIP only,
  37.  *            use ppp command for VJ compression with PPP);
  38.  *        'c' for cts flow control
  39.  *        'r' for rlsd (cd) detection
  40.  */
  41. int
  42. asy_attach(argc,argv,p)
  43. int argc;
  44. char *argv[];
  45. void *p;
  46. {
  47.     register struct iface *ifp;
  48.     int dev;
  49.     int trigchar = -1;
  50.     int cts,rlsd;
  51.     struct asymode *ap;
  52.     int vj;
  53.  
  54.     if(if_lookup(argv[4]) != NULLIF){
  55.         tprintf("Interface %s already exists\n",argv[4]);
  56.         return -1;
  57.     }
  58.     /* Find unused asy control block */
  59.     for(dev=0;dev < ASY_MAX;dev++){
  60.         if(Asy[dev].iface == NULLIF)
  61.             break;
  62.     }
  63.     if(dev >= ASY_MAX){
  64.         tprintf("Too many asynch controllers\n");
  65.         return -1;
  66.     }
  67.  
  68.     /* Create interface structure and fill in details */
  69.     ifp = (struct iface *)callocw(1,sizeof(struct iface));
  70.     ifp->addr = Ip_addr;
  71.     ifp->name = strdup(argv[4]);
  72.     ifp->mtu = atoi(argv[6]);
  73.     ifp->dev = dev;
  74.     ifp->stop = asy_detach;
  75.     if(argc > 8 && strchr(argv[8],'v') != NULLCHAR)
  76.         vj = 1;
  77.     else
  78.         vj = 0;
  79.  
  80.     /* Look for the interface mode in the table */
  81.     for(ap = Asymode;ap->name != NULLCHAR;ap++){
  82.         if(stricmp(argv[3],ap->name) == 0){
  83.             trigchar = uchar(ap->trigchar);
  84.             if((*ap->init)(ifp,vj) != 0){
  85.                 tprintf("%s: mode %s Init failed\n",
  86.                  ifp->name,argv[3]);
  87.                 if_detach(ifp);
  88.                 return -1;
  89.             }
  90.             break;
  91.         }
  92.     }
  93.     if(ap->name == NULLCHAR){
  94.         tprintf("Mode %s unknown for interface %s\n",
  95.          argv[3],argv[4]);
  96.         if_detach(ifp);
  97.         return -1;
  98.     }
  99.     /* Link in the interface */
  100.     ifp->next = Ifaces;
  101.     Ifaces = ifp;
  102.  
  103.     cts = rlsd = 0;
  104.     if(argc > 8){
  105.         if(strchr(argv[8],'c') != NULLCHAR)
  106.             cts = 1;
  107.         if(strchr(argv[8],'r') != NULLCHAR)
  108.             rlsd = 1;
  109.     }
  110.     asy_init(dev,ifp,argv[1],argv[2],(int16)atol(argv[5]),
  111.         trigchar,(int16)atol(argv[7]),cts,rlsd);
  112.     ifp->txproc = newproc("asy tx",768,if_tx,0,ifp,NULL,0);
  113.     return 0;
  114. }
  115.  
  116. static int
  117. asy_detach(ifp)
  118. struct iface *ifp;
  119. {
  120.     struct asymode *ap;
  121.  
  122.     if(ifp == NULLIF)
  123.         return -1;
  124.     asy_stop(ifp);
  125.  
  126.     /* Call mode-dependent routine */
  127.     for(ap = Asymode;ap->name != NULLCHAR;ap++){
  128.         if(ifp->iftype != NULLIFT
  129.          && stricmp(ifp->iftype->name,ap->name) == 0
  130.          && ap->free != NULLFP){
  131.             (*ap->free)(ifp);
  132.         }
  133.     }
  134.     return 0;
  135. }
  136.  
  137.  
  138.