home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_slave.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  4.8 KB  |  216 lines

  1. # include  "util.h"
  2. # include  "ll_log.h"
  3. # include  "d_proto.h"
  4. # include  "d_returns.h"
  5. # include  "d_structs.h"
  6.  
  7. /*    May 82  D. Crocker  added startup newline, to bypass some noise
  8.  */
  9.  
  10. extern int errno;
  11. extern int d_errno;
  12.  
  13. /*
  14.  *     D_SLVCONN
  15.  *
  16.  *     this routine is called by the slave protocol module to acknowledge
  17.  *     a connection by the remote system.  it sets the port characteristics
  18.  *     and performs the protocl startup sequence.
  19.  *
  20.  *     logfile -- name of the log file
  21.  *
  22.  *     tson -- set to non-zero to indicate that a transcript of the connection
  23.  *             should be kept
  24.  *
  25.  *     tsfile -- name of the file in which the transcript should be kept
  26.  *
  27.  *     debug -- set to non-zero to enable debug logging
  28.  *
  29.  *     portfd -- file descriptor of the port
  30.  *
  31.  *     maxrecv -- maximum receive packet length
  32.  *
  33.  *     maxxmit -- maximum transmit packet length
  34.  *
  35.  */
  36.  
  37. d_slvconn (logfile, tson, tsfile, debug, portfd, maxrecv, maxxmit)
  38. struct ll_struct *   logfile;
  39. char   tsfile[];
  40. int     tson,
  41.         debug,
  42.         portfd,
  43.         maxrecv,
  44.         maxxmit;
  45. {
  46.     extern int  d_master,
  47.                 d_debug,
  48.         d_snseq,
  49.         d_rcvseq,
  50.         d_lrmax,
  51.         d_lxmax;
  52.     extern  FILE * d_prtfp;
  53.     register int    result;
  54.  
  55.     /*  open the log file and transcript  */
  56.     if ((result = d_opnlog (logfile)) < 0)
  57.     return (result);
  58.  
  59.     if (tson)
  60.     if ((result = d_tsopen (tsfile)) < 0)
  61.         return (result);
  62.  
  63.     /*  set up globals  */
  64.     d_debug = debug;
  65.     d_master = 0;
  66.     d_snseq = 3;        /* these are incremented before any ... */
  67.     d_rcvseq = 3;        /* ... packets are expected */
  68.     d_lrmax = maxrecv;
  69.     d_lxmax = maxxmit;
  70.  
  71.     /* use stdio for input and write() calls for output */
  72.     d_prtfp = fdopen (portfd, "r");
  73.  
  74.     /*  save current tty parameters and and set tty for protocol mode       */
  75.     if (d_ttsave (d_prtfp, NULL) < 0 || d_ttproto (0) < 0)
  76.     {                             /* don't abort; may be ok             */
  77. #ifdef D_LOG
  78.     d_log ("d_slvconn", "error getting port parameters (errno=%d)",
  79.             errno);
  80. #endif D_LOG
  81.     d_errno = D_PRTSGTTY;
  82.     }
  83.  
  84.  
  85.     /*  do the protocol startup sequence  */
  86.     result = d_slvstart ();
  87.     return (result);
  88. }
  89.  
  90. /*
  91.  *     D_SLVDROP
  92.  *
  93.  *     this routine is called to cause the connection from the master to
  94.  *     be dropped.
  95.  *
  96.  *     sndquit -- called with non-zero value if the slave should attempt a
  97.  *                a QUIT exchange.
  98.  */
  99.  
  100. d_slvdrop (sndquit)
  101. int     sndquit;
  102. {
  103.     register int    result;
  104.  
  105.     if (sndquit)
  106.     result = d_snquit ();
  107.  
  108. #ifdef D_LOG
  109.     d_log ("d_slvdrop", "slave dropped connection");
  110. #endif D_LOG
  111.  
  112.     if (d_ttrestore () < 0)
  113.     {                             /* restory tty characteristics        */
  114.     d_errno = D_PRTSGTTY;
  115.     }
  116.     d_tsclose ();
  117.     d_clslog ();
  118.  
  119.     return (result);
  120. }
  121.  
  122. /*
  123.  *     D_SLVSTART
  124.  *
  125.  *     this routine is called in the slave to start the protocol.
  126.  */
  127.  
  128. d_slvstart ()
  129. {
  130.     extern int  d_lxmax,
  131.         d_lrmax,
  132.         d_rxmax,
  133.         d_rrmax,
  134.                 d_maxtext;
  135.     extern char d_snesc,
  136.         d_rcvesc;
  137.     extern  unsigned short d_lxill[],
  138.         d_lrill[],
  139.         d_rxill[],
  140.         d_rrill[],
  141.         d_lcvec[];
  142.     register int    result;
  143.  
  144. #ifdef D_DBGLOG
  145.     d_dbglog ("d_slvstart", "Beginning slave host startup sequence");
  146. #endif D_DBGLOG
  147.  
  148.     sleep (2);  /* wait for line-settling */
  149.  
  150.     d_wrtport ("\n", 1);  /* hack to bypass initial noise */
  151.  
  152.     /*  send XPATH and RPATH to the master  */
  153.     if ((result = d_snpath (XPATH, d_lxmax, d_lxill))
  154.         < 0)
  155.     return (result);
  156.  
  157. #ifdef D_DBGLOG
  158.     d_dbglog ("d_slvstart", "XPATH sent ok.");
  159. #endif D_DBGLOG
  160.  
  161.     if ((result = d_snpath (RPATH, d_lrmax, d_lrill))
  162.         < 0)
  163.     return (result);
  164.  
  165. #ifdef D_DBGLOG
  166.     d_dbglog ("d_slvstart", "RPATH sent ok.");
  167. #endif D_DBGLOG
  168.  
  169.     /*  get XPATH and RPATH from the master.  then form the
  170.      *  local transmission encoding vector.
  171.      */
  172.     if ((result = d_getpath (XPATH, &d_rxmax, d_rxill)) < 0)
  173.     return (result);
  174.  
  175. #ifdef D_DBGLOG
  176.     d_dbglog ("d_slvstart", "XPATH received ok.");
  177. #endif D_DBGLOG
  178.  
  179.     if ((result = d_getpath (RPATH, &d_rrmax, d_rrill)) < 0)
  180.     return (result);
  181.  
  182. #ifdef D_DBGLOG
  183.     d_dbglog ("d_slvstart", "RPATH received ok.");
  184. #endif D_DBGLOG
  185.  
  186.     d_orbitvec (d_lxill, d_rrill, d_lcvec);
  187.  
  188.     d_maxtext = d_minimum (d_lxmax, d_rrmax);
  189. #ifdef D_DBGLOG
  190.     d_dbglog ("d_slvstart", "Maximum transmit packet size set to %d", d_maxtext);
  191. #endif D_DBGLOG
  192.     d_maxtext -= LHEADER;
  193.  
  194.     /*  send our receive escape code to the master and get his  */
  195.     if ((result = d_snfescape ()) < 0)
  196.     return (result);
  197.  
  198. #ifdef D_DBGLOG
  199.     d_dbglog ("d_slvstart", "ESCAPE sent ok.  Receive escape '%c'", d_rcvesc);
  200. #endif D_DBGLOG
  201.  
  202.     if ((result = d_getescape ()) < 0)
  203.     return (result);
  204.  
  205. #ifdef D_DBGLOG
  206.     d_dbglog ("d_slvstart", "ESCAPE received ok.  Transmit escape '%c'",
  207.         d_snesc);
  208. #endif D_DBGLOG
  209.  
  210. #ifdef D_LOG
  211.     d_log ("d_slvstart", "Slave protocol startup completed ok.");
  212. #endif D_LOG
  213.  
  214.     return (D_OK);
  215. }
  216.