home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / uucico / modem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-21  |  3.8 KB  |  201 lines

  1.  
  2. /*
  3.  *  MODEM.C
  4.  *
  5.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  6.  *
  7.  *  $Header: Beta:src/uucp/src/uucico/RCS/modem.c,v 1.1 90/02/02 11:56:00 dillon Exp Locker: dillon $
  8.  */
  9.  
  10. #include "includes.h"
  11. #include "uucp.h"
  12. #include "log.h"
  13. #include <dos.h>
  14.  
  15. Prototype void openline(void);
  16. Prototype int  get_baud(void);
  17. Prototype void modem_init(void);
  18. Prototype int  dial_nbr(const char *);
  19. Prototype void reset_modem(void);
  20.  
  21. /*
  22.  *  NOTE:   modem stuff pretty much ignored if we are run from
  23.  *        a getty.
  24.  */
  25.  
  26. #define MULTIMODEM    /*  I have a multi-modem    */
  27.  
  28. extern int Getty;
  29. extern int IgnoreCD;
  30.  
  31.  
  32.  
  33. void
  34. openline()
  35. {
  36.     signal(SIGINT,sigint);
  37.     IgnoreCD |= 4;
  38. start_again:
  39.     chkabort();
  40.     if (instr("CONNECT", 7))
  41.     goto start_again;
  42.  
  43.  
  44. #ifdef MULTIMODEM
  45.  
  46. #else
  47.     set_baud(get_baud());
  48. #endif
  49.     Delay(120); /* sleep 2 seconds */
  50.  
  51.     IgnoreCD &= ~4;
  52. }
  53.  
  54. #ifndef MULTIMODEM
  55.  
  56. int
  57. get_baud()
  58. {
  59. /* We've seen the CONNECT message, now we must see what baud rate
  60.    we've connected with */
  61. /* gather input until \r then see if it's 300, 1200, or 2400 */
  62. /* this is for hayes compatibles */
  63.  
  64.     int data;
  65.     char rate[10];
  66.     int rate_inx = 0;
  67.  
  68.     DEBUG(2,"looking for baud rate\n",0);
  69.  
  70.     while ( ((data = xgetc(BYTE_TO)) != EOF) && ((char)data != '\r')) {
  71.         if ((char)data == ' ') continue;
  72.         rate[rate_inx++] = (char)data;
  73.     }
  74.     DEBUG(2, "found baud rate of %s\n", rate);
  75.     if (strncmp(rate,"1200",4) == 0) return 1200;
  76.     if (strncmp(rate,"2400",4) == 0) return 2400;
  77.     if (rate_inx == 0) return 300;
  78.     return 1200;  /* default */
  79. }
  80.  
  81. #endif
  82.  
  83. void
  84. modem_init()
  85. {
  86.     reset_modem();
  87. }
  88.  
  89. /*
  90.  * Simple dialer routine.  Needs replacement with a full blown
  91.  * script driven dialer.  Next week maybe :-).    FIXME.
  92.  */
  93.  
  94. int
  95. dial_nbr(nbr)
  96. const char *nbr;
  97. {
  98.     char  *dial;
  99.     int   i;
  100.  
  101.     IgnoreCD |= 4;
  102.  
  103.     dial = malloc(strlen(nbr) + 16);
  104.  
  105.     dial[0] = 0;
  106.     if (strncmp(nbr, "AT", 2) != 0 && strncmp(nbr, "at", 2) != 0)
  107.     strcpy(dial, "ATDP"); /* 12-Aug-90 -IF- */
  108.     strcat(dial, nbr);
  109.     strcat(dial, "\r");
  110.  
  111.     DEBUG(2,"dialing %s\n", dial);
  112.  
  113.     twrite(dial, strlen(dial));
  114.  
  115.     i = instr("CONNECT", 7);
  116.  
  117.     if (i == 0)     /*  for those modems which don't bring CD up */
  118.     Delay(50);  /*  immediately                              */
  119.  
  120.     IgnoreCD &= ~4;
  121.  
  122.     free(dial);
  123.  
  124.     return (i);
  125. }
  126.  
  127. /*
  128.  *  RESET_MODEM()
  129.  *
  130.  *  If run from a Getty we do NOT reset the modem, which would
  131.  *  disconnect an already connected connection.
  132.  *
  133.  *  Note that the delay between CloseSerial() and OpenSerial() only
  134.  *  serves to give the Getty, if running, time to lock the port and
  135.  *  begin a disconnect sequence.
  136.  */
  137.  
  138. void
  139. reset_modem()
  140. {
  141.     if (Getty)          /*  called from a getty             */
  142.     return;
  143.     DEBUG(4, "Beg-Reset\n", 0);
  144.     CloseSerial();      /*  drop dtr            */
  145.     Delay(50*3);        /*  delay 3 seconds     */
  146.     DEBUG(4, "End-Reset-1\n", 0);
  147.     OpenSerial();       /*  re-open serial      */
  148.     DEBUG(4, "End-Reset-2\n", 0);
  149. }
  150.  
  151. #ifdef NOTDEF
  152.  
  153.     if (GettyCmd(DeviceName, DeviceUnit, '0', NULL) == 0)
  154.     return;
  155.  
  156.     /*
  157.      *    Getty doesn't exist, we have to reset the modem ourselves!
  158.      */
  159.  
  160.     IgnoreCD |= 4;
  161.  
  162. #ifdef MULTIMODEM
  163.     set_baud(19200);
  164.  
  165.     if (CheckCarrier()) {
  166.     Delay(60);
  167.     twrite("+++", 3);
  168.     Delay(120);
  169.     }
  170.     twrite("ATH0\r", 5);
  171.     instr("OK\r\n", 4);
  172.     twrite("ATZ\r", 4);
  173.     instr("OK\r\n", 4);
  174.     twrite("ATZ\r", 4);
  175.     instr("OK\r\n", 4);
  176.  
  177.     /*amiga_closeopen();*/
  178.     sprintf(init, "%s\r", "ATM0S0=2X4$BA0");
  179.     if (debug > 0)
  180.     init[3] = '1';
  181.     twrite(init, strlen(init));
  182.     instr("OK\r\n",4);
  183. #else
  184.     twrite("+++", 3);
  185.     Delay(60);
  186.     twrite("ATH0\r", 5);
  187.     Delay(120);
  188.     twrite("ATZ\r", 4);
  189.     Delay(60);
  190.     twrite("ATZ\r", 4);
  191.     Delay(60);
  192.     sprintf(init, "%s\r", "ATS2");
  193.     twrite(init, strlen(init));
  194.     Delay(60);
  195. #endif
  196.     IgnoreCD &= ~4;
  197. }
  198.  
  199. #endif
  200.  
  201.