home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / s920603.zip / ASY.C < prev    next >
C/C++ Source or Header  |  1992-05-15  |  3KB  |  141 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 "n8250.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.     char *cp;
  54.  
  55.     if(if_lookup(argv[4]) != NULLIF){
  56.         printf("Interface %s already exists\n",argv[4]);
  57.         return -1;
  58.     }
  59.     /* Find unused asy control block */
  60.     for(dev=0;dev < ASY_MAX;dev++){
  61.         if(Asy[dev].iface == NULLIF)
  62.             break;
  63.     }
  64.     if(dev >= ASY_MAX){
  65.         printf("Too many asynch controllers\n");
  66.         return -1;
  67.     }
  68.  
  69.     /* Create interface structure and fill in details */
  70.     ifp = (struct iface *)callocw(1,sizeof(struct iface));
  71.     ifp->addr = Ip_addr;
  72.     ifp->name = strdup(argv[4]);
  73.     ifp->mtu = atoi(argv[6]);
  74.     ifp->dev = dev;
  75.     ifp->stop = asy_detach;
  76.     if(argc > 8 && strchr(argv[8],'v') != NULLCHAR)
  77.         vj = 1;
  78.     else
  79.         vj = 0;
  80.  
  81.     /* Look for the interface mode in the table */
  82.     for(ap = Asymode;ap->name != NULLCHAR;ap++){
  83.         if(stricmp(argv[3],ap->name) == 0){
  84.             trigchar = uchar(ap->trigchar);
  85.             if((*ap->init)(ifp,vj) != 0){
  86.                 printf("%s: mode %s Init failed\n",
  87.                  ifp->name,argv[3]);
  88.                 if_detach(ifp);
  89.                 return -1;
  90.             }
  91.             break;
  92.         }
  93.     }
  94.     if(ap->name == NULLCHAR){
  95.         printf("Mode %s unknown for interface %s\n",
  96.          argv[3],argv[4]);
  97.         if_detach(ifp);
  98.         return -1;
  99.     }
  100.     /* Link in the interface */
  101.     ifp->next = Ifaces;
  102.     Ifaces = ifp;
  103.  
  104.     cts = rlsd = 0;
  105.     if(argc > 8){
  106.         if(strchr(argv[8],'c') != NULLCHAR)
  107.             cts = 1;
  108.         if(strchr(argv[8],'r') != NULLCHAR)
  109.             rlsd = 1;
  110.     }
  111.     asy_init(dev,ifp,argv[1],argv[2],(int16)atol(argv[5]),
  112.         trigchar,(int16)atol(argv[7]),cts,rlsd);
  113.     cp = if_name(ifp," tx");
  114.     ifp->txproc = newproc(cp,768,if_tx,0,ifp,NULL,0);
  115.     free(cp);
  116.     return 0;
  117. }
  118.  
  119. static int
  120. asy_detach(ifp)
  121. struct iface *ifp;
  122. {
  123.     struct asymode *ap;
  124.  
  125.     if(ifp == NULLIF)
  126.         return -1;
  127.     asy_stop(ifp);
  128.  
  129.     /* Call mode-dependent routine */
  130.     for(ap = Asymode;ap->name != NULLCHAR;ap++){
  131.         if(ifp->iftype != NULLIFT
  132.          && stricmp(ifp->iftype->name,ap->name) == 0
  133.          && ap->free != NULLFP){
  134.             (*ap->free)(ifp);
  135.         }
  136.     }
  137.     return 0;
  138. }
  139.  
  140.  
  141.