home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / TIP.C < prev    next >
C/C++ Source or Header  |  1991-06-01  |  3KB  |  118 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 "8250.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.         tprintf("Interface %s unknown\n",argv[1]);
  40.         return 1;
  41.     }
  42.     if( ifp->dev >= ASY_MAX || Asy[ifp->dev].iface != ifp ){
  43.         tprintf("Interface %s not asy port\n",argv[1]);
  44.         return 1;
  45.     }
  46.     if(ifp->raw == bitbucket){
  47.         tprintf("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)) == NULLSESSION){
  53.         tprintf("Too many sessions\n");
  54.         return 1;
  55.     }
  56.  
  57.     /* Save output handler and temporarily redirect output to null */
  58.     rawsave = ifp->raw;
  59.     ifp->raw = bitbucket;
  60.  
  61.     /* Suspend the packet input driver. Note that the transmit driver
  62.      * is left running since we use it to send buffers to the line.
  63.      */
  64.     suspend(ifp->rxproc);
  65.  
  66.     /* Put tty into raw mode */
  67.     sp->ttystate.echo = 0;
  68.     sp->ttystate.edit = 0;
  69.     sockmode(sp->output,SOCK_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.         tputc(c & 0x7f);
  86.     tflush();
  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.     struct mbuf *bp;
  105.     int c;
  106.  
  107.     while((c = recvchar(Curproc->input)) != EOF){
  108.         if(c == '\n')
  109.             c = '\r';        /* NL => CR */
  110.         bp = pushdown(NULLBUF,1);
  111.         bp->data[0] = c;
  112.         asy_send(dev,bp);
  113.         Asy[dev].iface->lastsent = secclock();
  114.     }
  115. }
  116.  
  117.  
  118.