home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / s920603.zip / TIP.C < prev    next >
C/C++ Source or Header  |  1992-05-15  |  2KB  |  115 lines

  1. /* "Dumb terminal" session command for serial lines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *    Feb '91    Bill Simpson
  5.  *        rlsd control and improved dialer
  6.  */
  7. #include "global.h"
  8. #include "mbuf.h"
  9. #include "proc.h"
  10. #include "iface.h"
  11. #ifndef    UNIX
  12. #include "n8250.h"
  13. #endif
  14. #include "asy.h"
  15. #include "tty.h"
  16. #include "session.h"
  17. #include "socket.h"
  18. #include "commands.h"
  19. #include "devparam.h"
  20.  
  21.  
  22. static void tip_out __ARGS((int dev,void *n1,void *n2));
  23.  
  24.  
  25. /* Execute user telnet command */
  26. int
  27. dotip(argc,argv,p)
  28. int argc;
  29. char *argv[];
  30. void *p;
  31. {
  32.     struct session *sp;
  33.     register struct iface *ifp;
  34.     char *ifn;
  35.     int (*rawsave) __ARGS((struct iface *,struct mbuf *));
  36.     int c;
  37.  
  38.     if((ifp = if_lookup(argv[1])) == NULLIF){
  39.         printf("Interface %s unknown\n",argv[1]);
  40.         return 1;
  41.     }
  42.     if( ifp->dev >= ASY_MAX || Asy[ifp->dev].iface != ifp ){
  43.         printf("Interface %s not asy port\n",argv[1]);
  44.         return 1;
  45.     }
  46.     if(ifp->raw == bitbucket){
  47.         printf("tip or dialer session already active on %s\n",argv[1]);
  48.         return 1;
  49.     }
  50.  
  51.     /* Allocate a session descriptor */
  52.     if((sp = newsession(argv[1],TIP,1)) == NULLSESSION){
  53.         printf("Too many sessions\n");
  54.         return 1;
  55.     }
  56.     /* Save output handler and temporarily redirect output to null */
  57.     rawsave = ifp->raw;
  58.     ifp->raw = bitbucket;
  59.  
  60.     /* Suspend the packet input driver. Note that the transmit driver
  61.      * is left running since we use it to send buffers to the line.
  62.      */
  63.     suspend(ifp->rxproc);
  64.  
  65.     /* Put tty into raw mode */
  66.     sp->ttystate.echo = 0;
  67.     sp->ttystate.edit = 0;
  68.     fmode(stdin,STREAM_BINARY);
  69.     fmode(stdout,STREAM_BINARY);
  70.  
  71.     /* Now fork into two paths, one rx, one tx */
  72.     ifn = if_name( ifp, " tip out" );
  73.     sp->proc1 = newproc(ifn,256,tip_out,ifp->dev,NULL,NULL,0);
  74.     free( ifn );
  75.  
  76.     ifn = if_name( ifp, " tip in" );
  77.     chname( Curproc, ifn );
  78.     free( ifn );
  79.  
  80.     /* bring the line up (just in case) */
  81.     if ( ifp->ioctl != NULL )
  82.         (*ifp->ioctl)( ifp, PARAM_UP, TRUE, 0L );
  83.  
  84.     while((c = get_asy(ifp->dev)) != -1)
  85.         putchar(c & 0x7f);
  86.     fflush(stdout);
  87.  
  88.     killproc(sp->proc1);
  89.     sp->proc1 = NULLPROC;
  90.     ifp->raw = rawsave;
  91.     resume(ifp->rxproc);
  92.     keywait(NULLCHAR,1);
  93.     freesession(sp);
  94.     return 0;
  95. }
  96.  
  97.  
  98. /* Output process, DTE version */
  99. static void
  100. tip_out(dev,n1,n2)
  101. int dev;
  102. void *n1,*n2;
  103. {
  104.     int c;
  105.     char c1;
  106.  
  107.     while((c = getchar()) != EOF){
  108.         c1 = c;
  109.         asy_write(dev,&c1,1);
  110.         Asy[dev].iface->lastsent = secclock();
  111.     }
  112. }
  113.  
  114.  
  115.