home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / SLIPCA.ZIP / SLIPCALL.C next >
Text File  |  1992-04-15  |  33KB  |  1,032 lines

  1. //************************************************************************** //
  2. //
  3. // program: slipcall.c
  4. //
  5. // syntax:  slipcall [-?] [-r] [-a] [-d] [-s]
  6. //
  7. //          where: -? help
  8. //                 -r reset
  9. //                 -a auto-answer
  10. //                 -d dial
  11. //                 -s status
  12. //
  13. // author:  Paul Seifert.
  14. //
  15. // notes:
  16. //
  17. //      (1) SLIO must be running (creates semaphores).  Any other program
  18. //          that writes to the com port while slip is running should also use
  19. //          the semaphores.  Otherwise, results are unpredictable.
  20. //      (2) Modem must support Hayes AT command set.
  21. //      (3) Any AT command can be sent via SLIP.DIAL, but slipcall expects E0
  22. //          and V0 (these are not defaults), and S2=43, S12=50, Q0 (defaults).
  23. //      (4) Auto-Answer is set by S0=2 (2 rings before answer).
  24. //      (5) SLIP.DELAY (comma pause in SLIP.DIAL) sets S8=n (default is 2).
  25. //      (6) SLIPCALL -r sets the com port to N,8,1.  If you need to use
  26. //          something other than that use the OS2 mode command after reset.
  27. //      (7) The environment variables SLIPCALL.CLASS and SLIPCALL.DELTA can
  28. //          be used to change the priority of this process (not documented).
  29. //      (8) The environment variable SLIPCALL.TIME can be used to change the
  30. //          DosRead timeout when waiting for the modems to connect.  The
  31. //          default is SLIPCALL.TIME=60 (60 seconds).
  32. //      (9) DosRead and DosWrite timeouts are set to 1 second in this program
  33. //          and then put back to their previous values for everthing except
  34. //          the DosRead mentioned in note #8.
  35. //     (10) Commented out the read and write slipcall semaphores used to
  36. //          get exclusive access to the com port.
  37. // ************************************************************************ //
  38.  
  39. // ************************************************************************ //
  40. // Defines and Includes...
  41. // ************************************************************************ //
  42.    #define OS2
  43.    #define INCL_DOS
  44.    #define INCL_SUB
  45.    #define INCL_DOSSEMAPHORES
  46.    #define INCL_DOSPROCESS
  47.    #define BUFFER_LENGTH 1     /* read operation */
  48.    #define TIMEOUT 20000L
  49.    #include <os2.h>
  50.    #include <stdlib.h>
  51.    #include <stdio.h>
  52.    #include <string.h>
  53.    #include <ctype.h>
  54.  
  55. // ************************************************************************ //
  56. // Global Variables...
  57. // ************************************************************************ //
  58.  
  59. // #define debug
  60. // #define yorktown
  61.  
  62.    #define  SLIP_buffer_size 1200
  63.  
  64.    int comhandle, comaction, numbytes;           /* dosread/doswrite vars */
  65.    static char comport[256] = "com1";                 /* default communications port */
  66.    static char baud[256] = "1200";                 /* default baud rate */
  67.    static char reset_str[] = "ATZ\r\n";            /* Reset command */
  68.    static char auto_ans_str[] = "ATS0=2\r\n";      /* Auto answer is set to 2 */
  69.    static char non_defaults[] = "ATE0V1Q0\r\n";    /* Non default string */
  70.    unsigned int baud_rate,i;
  71.    unsigned short status;                          /* Flag set to true if requesting status info */
  72.  
  73.    HSEM read_semhandle, write_semhandle;
  74.    char *szTemp;
  75.    unsigned char comchar[25];                      /* RC from modem */
  76.    unsigned char modem_signals;
  77.    unsigned char line_characteristics[4];
  78.    int carrier, rings, rc, modem_rc;
  79.    long long_delay = 2100;   /* > 2 sec  */
  80.    long medium_delay = 1100; /* > 1 sec  */
  81.    long short_delay = 100;   /* 1/10 sec */
  82.    long timeout = 8000;      /*  8 secs  */
  83.    static unsigned char buffer_bucket[SLIP_buffer_size];
  84.    unsigned int receive_buffer_bytes[2];
  85.    struct DevCtlBlk {
  86.      unsigned int write_time;
  87.      unsigned int read_time;
  88.      unsigned char flag1;
  89.      unsigned char flag2;
  90.      unsigned char flag3;
  91.      unsigned char error_char;
  92.      unsigned char break_char;
  93.      unsigned char xon_char;
  94.      unsigned char xoff_char;
  95.      };
  96.    struct DevCtlBlk comport_info;
  97.    unsigned int write_value = 6000; /* 1 minute...this is default timeout... */
  98.    unsigned int read_value  = 6000; /* not INETSLIO.C's (1/100 not 1/1000).  */
  99.  
  100.    USHORT  com_class;             /* Class and Delta for SLIPCALL */
  101.    SHORT   com_delta;
  102.  
  103. // ************************************************************************ //
  104.    void APIENTRY finish()
  105. // ************************************************************************ //
  106.  
  107.    {
  108.  
  109. // This is to make sure semaphores are cleared...
  110.  
  111.     if (rc=DosSemClear(write_semhandle)) {
  112.  #ifdef debug
  113.      printf("DosSemClear (write) rc=%d\n", rc);
  114.      }
  115.    else {
  116.      printf("Cleared Write Semaphore!!!\n");
  117.  #endif
  118.      }
  119.  
  120.     if (rc=DosSemClear(read_semhandle)) {
  121.  #ifdef debug
  122.      printf("DosSemClear (read) rc=%d\n", rc);
  123.      }
  124.    else {
  125.      printf("Cleared Read Semaphore!!!\n");
  126.  #endif
  127.      }
  128.  
  129. // Put back the DosRead and DosWrite timeouts...
  130. //   comport_info.read_time = read_value;
  131. //   comport_info.write_time = write_value;
  132. //   DosDevIOCtl(NULL, &comport_info, 0x53, 0x01, comhandle);
  133.  
  134. // #ifdef debug
  135. //   printf("Put back DosRead and DosWrite timeouts to %d, %d.\n", read_value, write_value);
  136. // #endif
  137.  
  138.    DosExitList(0x0003, (PFNEXITLIST)0);
  139.  
  140.  }
  141.  
  142. // ************************************************************************ //
  143. // slipcall.c
  144. // ************************************************************************ //
  145.  
  146.    int main(argc, argv)
  147.    char *argv[];
  148.    {
  149.    char **av=argv;
  150. // ************************************************************************ //
  151. // Initialization...
  152. // ************************************************************************ //
  153.    status = FALSE;
  154.    /* Determine class/delta for SLIPCALL */
  155.    if ((szTemp = getenv("SLIPCALL.CLASS")) != NULL) {
  156.      com_class = atoi(szTemp);
  157.      }
  158.    else {
  159.      com_class = PRTYC_REGULAR; /* class default same as INETSLIO.C */
  160.      }
  161.  
  162.    if ((szTemp = getenv("SLIPCALL.DELTA")) != NULL) {
  163.      com_delta = atoi(szTemp);
  164.      }
  165.    else {
  166.      com_delta = 16; /* delta default is higher than INETSLIO.C */
  167.      }
  168.  
  169. // Set priority for this thread as specified
  170.    DosSetPrty(PRTYS_THREAD,com_class,com_delta,0);
  171.  
  172. #ifdef debug
  173.    printf("SLIPCALL class=%d, delta=%d\n", com_class, com_delta);
  174. #endif
  175.  
  176. // Get the SLIP.COM Envionment variable for DosOpen...
  177.    if((szTemp = getenv("SLIP.COM")) != NULL)
  178.      strcpy(comport, szTemp);
  179.  
  180. // Get the communications port handle...
  181.    if (DosOpen(comport,&comhandle,&comaction,0L,0,0x01,0x0042,0L)) {
  182.      printf("\nError: Could not open the communications port \"%s\".\n", comport);
  183.      exit(1);
  184.      }
  185.    DosSleep(medium_delay);
  186.  
  187. // Get the DosRead an DosWrite timeouts
  188.  
  189.    if (DosDevIOCtl(&comport_info, NULL, 0x73, 0x01, comhandle))
  190.      {
  191.       printf("\nError: Could not get the Device Control Block information.\n");
  192.       exit(1);
  193.      }
  194.    else
  195.      {
  196.       read_value = comport_info.read_time;
  197.       write_value = comport_info.write_time;
  198.  
  199. #ifdef debug
  200.       printf("The read time out  = %d.\n", read_value);
  201.       printf("The write time out = %d.\n", write_value);
  202.       printf("Flag 1 is = %x.\n", comport_info.flag1);
  203.       printf("Flag 2 is = %x.\n", comport_info.flag2);
  204.       printf("Flag 3 is  = %x.\n", comport_info.flag3);
  205.       printf("Error char is = %x.\n", comport_info.error_char);
  206.       printf("xon char is  = %x.\n", comport_info.xon_char);
  207.       printf("xoff char is = %x.\n", comport_info.xoff_char);
  208. #endif
  209.      }
  210.  
  211. // Get the semaphore handles created by SLIP (if_sl.c)...
  212. //   if  (DosOpenSem(&read_semhandle, "\\SEM\\SLIP\\COMREAD")
  213. //     || DosOpenSem(&write_semhandle, "\\SEM\\SLIP\\COMWRITE")) {
  214. //     printf("\nCould not get SLIPCALL semaphore because \"slio.exe\" is not running.\n");
  215. //     exit(1);
  216. //     }
  217.  
  218. // Set up an exit routine to be sure semaphores get cleared...
  219. //   DosExitList(0x0001, (PFNEXITLIST)finish);
  220.  
  221. // ************************************************************************ //
  222. // Parse the command line...
  223. // ************************************************************************ //
  224.  
  225.    if(argc == 1)  {
  226.      slipcall_help();
  227.      exit(1);
  228.      }
  229.  
  230.  
  231.  //  get_semaphores();
  232.  
  233.    DosWrite(comhandle, "AT\r",3,&numbytes);
  234.    DosSleep(short_delay);
  235.  
  236. //   clear_semaphores();
  237.  
  238.    clear_receive_buffer();
  239.  
  240.    argc--, av++;
  241.    while (argc > 0 && *av[0] == '-') {
  242.  
  243.      while (*++av[0]) {
  244.  
  245.        switch (*av[0]) {
  246.  
  247.          case 'r':
  248.          case 'R': slipcall_reset();
  249.                    break;
  250.  
  251.          case 'a':
  252.          case 'A': slipcall_answer();
  253.                    break;
  254.  
  255.          case 'd':
  256.          case 'D': slipcall_dial();
  257.                    break;
  258.  
  259.          case 's':
  260.          case 'S': slipcall_status();
  261.                    break;
  262.  
  263.          default:  slipcall_help();
  264.                    exit(1);
  265.  
  266.          } /* end switch */
  267.  
  268.        } /* end inner-while */
  269.  
  270.       argc--, av++;
  271.      } /* end outer-while */
  272.  
  273. // ************************************************************************ //
  274. // Clean up...
  275. // ************************************************************************ //
  276.  
  277. // Close the communications handle...
  278.    if (rc = DosClose(comhandle))
  279.      printf("\nWarning: Device handle failed to close.\n");
  280.  
  281.    } /* end of main */
  282.  
  283. // ************************************************************************ //
  284.    slipcall_reset()
  285. // ************************************************************************ //
  286.    { /* begin reset */
  287.     BYTE data;
  288.     unsigned char mask[2]; /* Used to reset DTR pin */
  289.  
  290.     printf("\nReset...");
  291.  
  292. //     get_semaphores();
  293.  
  294.     get_carrier_status();
  295.     if (carrier)
  296.     {
  297.      mask[0] = 0x00; /* 1's for all pins to be turned on(set) */
  298.      mask[1] = 0xfe; /* 1's for all pins to be turned off */
  299.  
  300.      if (DosDevIOCtl(&data, mask, 0x46, 0x01, comhandle)) /* Reset DTR */
  301.      {
  302.       printf("\n\nError: Could not reset DTR pin on the communications port.\n");
  303.       exit(1);
  304.      }
  305.      DosSleep(medium_delay);
  306.  
  307.      mask[0] = 0x01;   /* 1's for all pins to be turned on(set) */
  308.      mask[1] = 0xff;   /* 1's for all pins to be turned off */
  309.  
  310.      if (DosDevIOCtl(&data, mask, 0x46, 0x01, comhandle)) /* Set DTR */
  311.      {
  312.       printf("\n\nError: Could not reset DTR pin on the communications port.\n");
  313.       exit(1);
  314.      }
  315.     }
  316.  
  317. // ************************************************************************ //
  318. // Set the baud rate and line characteristics...
  319. // ************************************************************************ //
  320. // set the communications port speed (from SLIP.BPS)...
  321.    if((szTemp = getenv("SLIP.BPS")) == NULL) {
  322.      printf("\nSLIP.BPS was not defined (the default is 1200).\n");
  323.      szTemp = baud;
  324.      }
  325.  
  326.    if (strcmp(szTemp, "1200") && strcmp(szTemp, "2400") && strcmp(szTemp, "4800") &&
  327.        strcmp(szTemp, "9600") && strcmp(szTemp, "19200")) {
  328.      printf("\nWarning: The definition for SLIP.BPS is invalid (1200 is being used).\n");
  329.      szTemp = baud;
  330.      }
  331.  
  332.    baud_rate = atoi(szTemp);
  333.    if (DosDevIOCtl(NULL, &baud_rate, 0x41, 0x01, comhandle)) {
  334.      printf("\n\nError: Could not set the baud rate on the communications port.\n");
  335.      exit(1);
  336.      }
  337.  
  338. #ifndef yorktown /* this is for 99% of the SLIP connections */
  339.  
  340. // set the data bits & parity (No Parity, 8 data bits, 1 stop bit)...
  341.    line_characteristics[0] = 0x08;
  342.    line_characteristics[1] = 0x00;
  343.    line_characteristics[2] = 0x00;
  344.  
  345.    if (DosDevIOCtl(NULL, line_characteristics, 0x42, 0x01, comhandle)) {
  346.      printf("\nError: Could not set the line characteristics.\n");
  347.      exit(1);
  348.      }
  349.  
  350. #endif
  351.  
  352. #ifdef yorktown /* this is specific to the SLIP server in Yorktown */
  353.  
  354. // set the data bits & parity (Even Parity, 7 data bits, 1 stop bit)...
  355.    line_characteristics[0] = 0x07;
  356.    line_characteristics[1] = 0x02;
  357.    line_characteristics[2] = 0x00;
  358.  
  359.    if (DosDevIOCtl(NULL, line_characteristics, 0x42, 0x01, comhandle)) {
  360.      printf("\nError: Could not set the line characteristics.\n");
  361.      exit(1);
  362.      }
  363.  
  364. #endif
  365.  
  366.    send_non_defaults();
  367.    DosSleep(medium_delay);
  368.  
  369.    clear_receive_buffer();
  370.  
  371. //   clear_semaphores();
  372.  
  373.    printf("The modem and communications port have been reset.\n");
  374.  
  375.    } /* end reset */
  376.  
  377. // ************************************************************************ //
  378.    slipcall_answer()
  379. // ************************************************************************ //
  380.    { /* begin answer */
  381.  
  382.    printf("\nAuto-Answer...");
  383.  
  384.   //  get_semaphores();
  385.  
  386.    get_carrier_status();
  387.  
  388.    if (carrier)
  389.      send_escape_sequence();
  390.    else
  391.      send_non_defaults();
  392.  
  393.    DosSleep(long_delay);
  394.    clear_receive_buffer();
  395.  
  396. // ************************************************************************ //
  397. // Set auto-answer on...
  398. // ************************************************************************ //
  399. #ifdef debug
  400.    printf("sending auto-answer to the modem...\n");
  401. #endif
  402.  
  403.    DosWrite(comhandle, auto_ans_str,strlen(auto_ans_str), &numbytes);
  404.    clear_receive_buffer();
  405. /*   if (carrier)
  406.      send_online_command();
  407. */
  408.    DosSleep(long_delay);
  409.    clear_receive_buffer();
  410.  
  411. //   clear_semaphores();
  412.  
  413.    printf("The auto-answer mode command has been sent to the modem.\n");
  414.  
  415.    } /* end answer */
  416.  
  417. // ************************************************************************ //
  418.    slipcall_dial()
  419. // ************************************************************************ //
  420.    { /* begin dial */
  421.  
  422.    static char delay_cmd[256] = "ATS8="; /* modem command for comma delay */
  423.    int i;
  424.    unsigned int wait_time;
  425.  
  426. // Get the SLIP.DELAY Envionment variable...
  427. #ifdef debug
  428.    printf("getting SLIP.DELAY...\n");
  429. #endif
  430.  
  431.    if((szTemp = getenv("SLIP.DELAY")) == NULL )
  432.      printf("\n\nSLIP.DELAY was not defined (the modem default is 2 seconds).");
  433.    else {
  434.      strcat(delay_cmd, szTemp);
  435.  
  436.   //   get_semaphores();
  437.  
  438.      send_non_defaults();
  439.  
  440.      clear_receive_buffer();
  441.  
  442. // ************************************************************************ //
  443. //   Set the comma pause from SLIP.DELAY...
  444. // ************************************************************************ //
  445. #ifdef debug
  446.      printf("sending SLIP.DELAY to the modem...\n");
  447. #endif
  448.  
  449.      DosWrite(comhandle, delay_cmd, strlen(delay_cmd), &numbytes);
  450.      DosWrite(comhandle, "\r\n", 2, &numbytes);
  451.      clear_receive_buffer();
  452.  
  453. #ifdef debug
  454.      printf("reading RC from modem...\n");
  455. #endif
  456.  
  457.  
  458. //     clear_semaphores();
  459.  
  460.      } /* end if SLIP.DELAY */
  461.  
  462. // Get the SLIP.DIAL Envionment variable...
  463. #ifdef debug
  464.    printf("getting SLIP.DIAL...\n");
  465. #endif
  466.  
  467.    if((szTemp = getenv("SLIP.DIAL")) == NULL)
  468.      printf("\n\nSLIP.DIAL was not defined (the default is null).\n");
  469.    else if((strlen(szTemp)<2)||(strncmp(szTemp,"AT",2)&&strncmp(szTemp,"at",2)))
  470.      printf("\n\nThe SLIP.DIAL definition must begin with \"AT\" or \"at\".\n");
  471.  
  472.    else { /* SLIP.DIAL */
  473.  
  474. // 1st convert slip.dial to upper case (some modems are picky)...
  475.  
  476. #ifdef debug
  477.    printf("Before...SLIP.DIAL is %s\n", szTemp);
  478. #endif
  479.  
  480.      szTemp = strupr(szTemp);
  481.  
  482. #ifdef debug
  483.    printf("After....SLIP.DIAL is %s\n", szTemp);
  484. #endif
  485.  
  486. //     get_semaphores();
  487.  
  488. // ************************************************************************ //
  489. //   Send the AT command in SLIP.DIAL...
  490. //************************************************************************* //
  491. #ifdef debug
  492.      printf("sending SLIP.DIAL to the modem...\n");
  493. #endif
  494.      printf ("Dialing . . . . .  Please wait \n");
  495.      DosWrite(comhandle, szTemp,strlen(szTemp) ,&numbytes);
  496.      DosWrite(comhandle, "\r\n", 2, &numbytes);
  497.  
  498.  
  499. //   Get SLIPCALL.TIME...
  500.      if ((szTemp = getenv("SLIPCALL.TIME")) != NULL) {
  501.        wait_time = (atoi(szTemp) * 100);
  502.        }
  503.      else {
  504.        wait_time = 6000;  /* 60 second default */
  505.        }
  506.      set_read_timeout (wait_time);
  507.  
  508. #ifdef debug
  509.      printf("reading RC from modem...\n");
  510. #endif
  511.  
  512.      get_modem_rc();
  513.      reset_read_timeout();
  514.      clear_receive_buffer();
  515. //     clear_semaphores();
  516.  
  517. #ifdef yorktown
  518. // set the data bits & parity (No Parity, 8 data bits, 1 stop bit)...
  519.    line_characteristics[0] = 0x08;
  520.    line_characteristics[1] = 0x00;
  521.    line_characteristics[2] = 0x00;
  522.  
  523.    if (DosDevIOCtl(NULL, line_characteristics, 0x42, 0x01, comhandle)) {
  524.      printf("\nError: Could not set the line characteristics.\n");
  525.      exit(1);
  526.      }
  527. #endif
  528.  
  529.      } /* SLIP.DIAL */
  530.  
  531.    } /* end dial */
  532.  
  533. // ************************************************************************ //
  534.    slipcall_status()
  535. // ************************************************************************ //
  536.    { /* begin status */
  537.    int i;
  538. // ************************************************************************ //
  539. // Print the SLIP Environment Variables...
  540. // ************************************************************************ //
  541.    printf("\nSLIP Environment Variables...\n\n");
  542.  
  543. // Get the SLIP.COM Envionment variable...
  544.    if((szTemp = getenv("SLIP.COM")) != NULL ) {
  545.      printf("  SLIP.COM   is defined as \"%s\".\n", szTemp);
  546.      }
  547.    else
  548.      printf("  SLIP.COM   is not defined (the default is COM1).\n");
  549.  
  550. // Get the SLIP.BPS Envionment variable...
  551.    if((szTemp = getenv("SLIP.BPS")) != NULL )
  552.      printf("  SLIP.BPS   is defined as \"%s\".\n", szTemp);
  553.    else
  554.      printf("  SLIP.BPS   is not defined (the default is 1200).\n");
  555.  
  556. // Get the SLIP.DIAL Envionment variable...
  557.    if((szTemp = getenv("SLIP.DIAL")) != NULL )
  558.      printf("  SLIP.DIAL  is defined as \"%s\".\n", szTemp);
  559.    else
  560.      printf("  SLIP.DIAL  is not defined (the default is null).\n");
  561.  
  562. // Get the SLIP.DELAY Envionment variable...
  563.    if((szTemp = getenv("SLIP.DELAY")) != NULL )
  564.      printf("  SLIP.DELAY is defined as %s seconds.\n", szTemp);
  565.    else
  566.      printf("  SLIP.DELAY is not defined (the default is 2 seconds).\n");
  567.  
  568. // ************************************************************************ //
  569. // Print the Line Characteristics
  570. // ************************************************************************ //
  571.    printf("\nSLIP Line Characteristics...\n\n");
  572.  
  573. // Report the baud rate...
  574.    if (DosDevIOCtl(&baud_rate, NULL, 0x61, 0x01, comhandle)) {
  575.      printf("\nError: Could not get the Baud Rate.\n");
  576.      exit(1);
  577.      }
  578.    else
  579.      printf("  The Baud Rate is %d bps.\n", baud_rate);
  580.  
  581. // Report the line characteristics...
  582.    if (DosDevIOCtl(line_characteristics, NULL, 0x62, 0x01, comhandle)) {
  583.      printf("\nError: Could not get the line characteristics.\n");
  584.      exit(1);
  585.      }
  586.    else
  587.      report_line_char();
  588.  
  589. // ************************************************************************ //
  590. // Print the Modem Status
  591. // ************************************************************************ //
  592.    printf("\nSLIP Modem Status...\n\n");
  593.  
  594.    if (DosDevIOCtl(&modem_signals, NULL, 0x67, 0x01, comhandle)) {
  595.      printf("\nError: Could not get the Modem Control Input Signals.\n");
  596.      exit(1);
  597.      }
  598.    else
  599.      print_modem_status(); /* this also sets carrier variable */
  600.  
  601.    if (DosDevIOCtl(&modem_signals, NULL, 0x66, 0x01, comhandle)) {
  602.      printf("\nError: Could not get the Modem Control Output Signals.\n");
  603.      exit(1);
  604.      }
  605.    else
  606.      print_modem_status_2();
  607.  
  608. //   get_semaphores();
  609.    clear_receive_buffer();
  610.  
  611. // ************************************************************************ //
  612. // Get the auto-answer status...
  613. // ************************************************************************ //
  614. // #ifdef debug
  615. //   printf("sending auto-answer query to the modem\n");
  616. // #endif
  617. //   DosWrite(comhandle, "ATS0?\r\n", 7, &numbytes);
  618.  
  619. // #ifdef debug
  620. //   printf("reading RC from the modem\n");
  621. // #endif
  622. // printf ("  AUTO ANSWER (No. of rings) is  ");
  623. // status = TRUE;          /* Set status flag */
  624. // numbytes=0;
  625. // do
  626. // {
  627. //  DosRead(comhandle,comchar,15,&numbytes);
  628. // } while (!numbytes);
  629.  
  630. //
  631.  
  632. // for (i=0; i<numbytes; i++)
  633. //  if(isdigit(comchar[i]))       /* Display only digits */
  634. //   printf ("%c", comchar[i]);
  635. //  printf ("\n\n");
  636.  
  637. //   clear_receive_buffer();
  638.  
  639. //   clear_semaphores();
  640.  
  641.  } /* end status */
  642.  
  643. // ************************************************************************ //
  644.    send_non_defaults()
  645. // ************************************************************************ //
  646.    { /* begin non-defaults */
  647.    int bytes_out;
  648.  
  649. // change the time outs so that checking will be faster
  650.  
  651.    comport_info.write_time = 100; /* 1 second (100/.01)  */
  652.  
  653.    if (DosDevIOCtl(NULL, &comport_info, 0x53, 0x01, comhandle)) {
  654.      printf("\nError: Could not set the Device Control Block information.\n");
  655.      exit(1);
  656.      }
  657.  
  658. #ifdef debug
  659.    printf("sending slipcall's non-defaults...\n");
  660. #endif
  661.  
  662.       DosWrite(comhandle, non_defaults,strlen(non_defaults), &bytes_out);
  663.    /* Q0 is a default, but some modems have a hardware switch */
  664.       clear_receive_buffer();
  665.  
  666. // put back the device control block info (for IF_SLIP.C)
  667.  
  668.    comport_info.write_time = write_value;
  669.  
  670.    if (DosDevIOCtl(NULL, &comport_info, 0x53, 0x01, comhandle)) {
  671.      printf("\nError: Could not set the Device Control Block information.\n");
  672.      exit(1);
  673.      }
  674.  
  675. // Make sure we can write to modem...this is after DevIOCtl in case it exits.
  676.      if (bytes_out < strlen(non_defaults)) {
  677.        printf("\nError: Sending AT commands to the modem failed.  Please check the modem.\n");
  678.        exit(1);
  679.      }
  680.  
  681.    } /* end non-defaults   */
  682.  
  683. // ************************************************************************ //
  684.    set_read_timeout(unsigned int timeout)
  685. // ************************************************************************ //
  686.    {
  687.  
  688. // change the time out so that checking will be faster (and a known value)
  689.  
  690.    comport_info.read_time = timeout;
  691.  
  692.    if (DosDevIOCtl(NULL, &comport_info, 0x53, 0x01, comhandle)) {
  693.      printf("\nError: Could not set the Device Control Block information.\n");
  694.      exit(1);
  695.      }
  696.  
  697. #ifdef debug
  698.    printf("Set DosRead timeout to %d.\n", comport_info.read_time);
  699. #endif
  700.  
  701.    }
  702.  
  703. // ************************************************************************ //
  704.    reset_read_timeout()
  705. // ************************************************************************ //
  706.    {
  707.  
  708. // put back the device control block info (for IF_SLIP.C)
  709.  
  710.    comport_info.read_time = read_value;
  711.  
  712.    if (DosDevIOCtl(NULL, &comport_info, 0x53, 0x01, comhandle)) {
  713.      printf("\nError: Could not set the Device Control Block information.\n");
  714.      exit(1);
  715.      }
  716.  
  717. #ifdef debug
  718.    printf("Reset DosRead timeout to %d.\n", comport_info.read_time);
  719. #endif
  720.  
  721.    }
  722.  
  723. // ************************************************************************ //
  724.    send_escape_sequence()
  725. // ************************************************************************ //
  726.    { /*begin escape */
  727. // this is the delault escape sequence
  728. #ifdef debug
  729.    printf("sending the escape sequence...\n");
  730. #endif
  731.    DosSleep(medium_delay);
  732.    DosWrite(comhandle, "+++\r\n", 5, &numbytes);
  733.    DosSleep(medium_delay);
  734.    clear_receive_buffer();
  735.    } /* end escape  */
  736.  
  737. // ************************************************************************ //
  738.    send_online_command()
  739. // ************************************************************************ //
  740.    { /* begin online */
  741. #ifdef debug
  742.    printf("sending the online command...\n");
  743. #endif
  744.    DosWrite(comhandle, "ATO0\r\n", 6, &numbytes);
  745.    DosSleep(short_delay);
  746.    clear_receive_buffer();
  747.    } /* end online */
  748.  
  749. // ************************************************************************ //
  750. //   get_semaphores()
  751. // ************************************************************************ //
  752. /*   {  begin get */
  753.  
  754. // Request semaphores from IF_SLIP.C...
  755.  
  756. //   if (rc=DosSemRequest(write_semhandle, timeout)) {
  757. //     printf("\nCould not get SLIPCALL write semaphore.  Trying again...\n");
  758. // #ifdef debug
  759. //     printf("The rc=%d\n", rc);
  760. // #endif
  761. //     DosSleep(long_delay);
  762. //     if (rc=DosSemRequest(write_semhandle, timeout)) {
  763. //       printf("Could not get SLIPCALL write semaphore.  Please try SLIPCALL command again...\n");
  764. // #ifdef debug
  765. //       printf("The rc=%d\n", rc);
  766. // #endif
  767. //       exit(1);
  768. //       }
  769. //     }
  770.  
  771. // #ifdef debug
  772. //   printf("Got Write Semaphore!!!\n");
  773. // #endif
  774.  
  775. //   if (rc=DosSemRequest(read_semhandle, timeout)) {
  776. //     printf("\nCould not get SLIPCALL read semaphore.  Trying again...\n");
  777. // #ifdef debug
  778. //     printf("The rc=%d\n", rc);
  779. // #endif
  780. //     DosSleep(long_delay);
  781. //     if (rc=DosSemRequest(read_semhandle, timeout)) {
  782. //       printf("Could not get SLIPCALL read semaphore.  Please try SLIPCALL command again...\n");
  783. // #ifdef debug
  784. //       printf("The rc=%d\n", rc);
  785. // #endif
  786. //       exit(1);
  787. //       }
  788. //     }
  789.  
  790. // #ifdef debug
  791. //   printf("Got Read Semaphore!!!\n");
  792. // #endif
  793.  
  794. //   }
  795.  
  796. // ************************************************************************ //
  797. //   clear_semaphores()
  798. // ************************************************************************ //
  799. //   { /* begin clear */
  800. // This is so that if_slip.c can read and write to com port...
  801.  
  802. //   if (rc=DosSemClear(write_semhandle)) {
  803. //     printf("\nError: Could not Clear SLIP write semaphore.\n");
  804. // #ifdef debug
  805. //     printf("The rc=%d\n", rc);
  806. // #endif
  807. //     exit(1);
  808. //     }
  809. // #ifdef debug
  810. //   else
  811. //     printf("Cleared Write Semaphore!\n");
  812. // #endif
  813.  
  814. //   DosSleep(medium_delay);
  815.  
  816. //   if (rc=DosSemClear(read_semhandle)) {
  817. //     printf("\nError: Could not Clear SLIP read semaphore.\n");
  818. // #ifdef debug
  819. //     printf("The rc=%d\n", rc);
  820. // #endif
  821. //     exit(1);
  822. //     }
  823. // #ifdef debug
  824. //   else
  825. //     printf("Cleared Read Semaphore!\n");
  826. // #endif
  827.  
  828. //   DosSleep(medium_delay);
  829.  
  830. //   } /* end clear  */
  831.  
  832. // ************************************************************************ //
  833.    get_carrier_status()
  834. // ************************************************************************ //
  835.    { /* begin carrier */
  836.    carrier = 0;
  837.    if (DosDevIOCtl(&modem_signals, NULL, 0x67, 0x01, comhandle)) {
  838.      printf("\nError: Could not get the Modem Control Signals.\n");
  839.      exit(1);
  840.      }
  841.    else if (modem_signals & 0x80) {
  842.      carrier = 1;
  843. #ifdef debug
  844.      printf("Carrier detected...\n");
  845. #endif
  846.      }
  847.    } /* end carrier */
  848.  
  849. // ************************************************************************ //
  850.    clear_receive_buffer()
  851. // ************************************************************************ //
  852.    { /* begin clear_buffer */
  853.     struct data_format
  854.      {
  855.       int numchar;    /* Number of char queued */
  856.       int queue_size; /* Size of receive queue */
  857.      };
  858.     struct data_format queue_data;
  859.  
  860. #ifdef debug
  861.    printf("attempting to clear receive buffer..\n");
  862.  
  863.    if (DosDevIOCtl(&queue_data, NULL, 0x68, 0x01, comhandle)) {
  864.      printf("\nError: Could not return the number of characters queued.\n");
  865.      exit(1);
  866.      }
  867.    else
  868.      printf("there are %d bytes to be cleared.\n", queue_data.numchar);
  869. #endif
  870.  
  871.   // Flush the input  and output buffers...
  872.    DosDevIOCtl(0x00, 0x00, 0x01, 0x0B, comhandle);
  873.    DosDevIOCtl(0x00, 0x00, 0x02, 0x0B, comhandle);
  874.  
  875. #ifdef debug
  876.    DosDevIOCtl(&queue_data, NULL, 0x68, 0x01, comhandle);
  877.    if (queue_data.numchar == 0)
  878.      printf("the buffer is cleared...\n");
  879.    else
  880.      printf("the buffer not cleared...\n");
  881. #endif
  882.  
  883.  } /* end clear_buffer */
  884.  
  885. // ************************************************************************ //
  886.    report_line_char()
  887. // ************************************************************************ //
  888.    { /* begin line chars */
  889.  
  890. // data bits
  891.    printf("  The line characteristics are ");
  892.    switch (line_characteristics[0]) {
  893.    case 0x05:  printf("5");
  894.                break;
  895.    case 0x06:  printf("6");
  896.                break;
  897.    case 0x07:  printf("7");
  898.                break;
  899.    case 0x08:  printf("8");
  900.                break;
  901.    default:    printf("invalid");
  902.                break;
  903.    } /* end switch */
  904.    printf(" data bits, ");
  905.  
  906. // parity
  907.    switch (line_characteristics[1]) {
  908.    case 0x00:  printf("no");
  909.                break;
  910.    case 0x01:  printf("odd");
  911.                break;
  912.    case 0x02:  printf("even");
  913.                break;
  914.    case 0x03:  printf("mark");
  915.                break;
  916.    case 0x04:  printf("space");
  917.                break;
  918.    default:    printf("invalid");
  919.                break;
  920.    } /* end switch */
  921.    printf(" parity, and ");
  922.  
  923. // stop bits
  924.    switch (line_characteristics[2]) {
  925.    case 0x00:  printf("1");
  926.                break;
  927.    case 0x01:  printf("1.5");
  928.                break;
  929.    case 0x02:  printf("2");
  930.                break;
  931.    default:    printf("invalid");
  932.                break;
  933.    } /* end switch */
  934.    printf(" stop bit(s).\n");
  935.  
  936.    if ((line_characteristics[0] != 0x08) ||
  937.        (line_characteristics[1] != 0x00) ||
  938.        (line_characteristics[2] != 0x00)) {
  939.      printf("\n  Warning: Most SLIP connections are 8 data bits, ");
  940.      printf("no parity, and 1 stop bit.\n");
  941.      printf("           If you type \"slipcall -r\" it will ");
  942.      printf("reset the communications port.\n");
  943.      }
  944.  
  945.    } /* end line_chars */
  946.  
  947. // ************************************************************************ //
  948.    print_modem_status()
  949. // ************************************************************************ //
  950.    { /* begin print_modem_status */
  951.  
  952.    carrier = 0;
  953.    if (modem_signals & 0x80) /* bit 7 */
  954.      {
  955.      carrier = 1;  /*this is needed by slipcall -s*/
  956.      printf("  DCD...Data Carrier Detect is ON.\n");
  957.      }
  958.    else
  959.      printf("  DCD...Data Carrier Detect is OFF.\n");
  960.  
  961. // if (modem_signals & 0x40) /* bit 6 */
  962. //   printf("  RI....Ring Indicator is ON.\n");
  963. // else
  964. //   printf("  RI....Ring Indicator is OFF.\n");
  965.  
  966.    if (modem_signals & 0x20) /* bit 5 */
  967.      printf("  DSR...Data Set Ready is ON.\n");
  968.    else
  969.      printf("  DSR...Data Set Ready is OFF.\n");
  970.  
  971.    if (modem_signals & 0x10) /* bit 4 */
  972.      printf("  CTS...Clear To Send is ON.\n");
  973.    else
  974.      printf("  CTS...Clear To Send is OFF.\n");
  975.  
  976.    } /* end of print_modem_status */
  977.  
  978. // ************************************************************************ //
  979.    print_modem_status_2()
  980. // ************************************************************************ //
  981.    { /* begin print_modem_status_2 */
  982.  
  983.    if (modem_signals & 0x01) /* bit 0 */
  984.      printf("  DTR...Data Terminal Ready is ON.\n");
  985.    else
  986.      printf("  DTR...Data Terminal Ready is OFF.\n");
  987.  
  988.    if (modem_signals & 0x02) /* bit 1 */
  989.      printf("  RTS...Request To Send is ON.\n");
  990.    else
  991.      printf("  RTS...Request To Send is OFF.\n");
  992.  
  993.    } /* end of print_modem_status_2 */
  994.  
  995. // ************************************************************************ //
  996.    exit_can_not_read()
  997. // ************************************************************************ //
  998.    {
  999.    printf("\n\nError: Could not read the result codes from the modem.\n");
  1000.    printf("       If SLIP.BPS is set to a value higher than your modem will support,\n");
  1001.    printf("       then change SLIP.BPS and use \"slipcall -r\".\n");
  1002.    exit(1);
  1003.    }
  1004.  
  1005. // ************************************************************************ //
  1006.    slipcall_help()
  1007. // ************************************************************************ //
  1008.    { /* begin help */
  1009.  
  1010.    printf("\nUsage: slipcall [-?] [-r] [-a] [-d] [-s]\n\nWhere: ");
  1011.    printf("-?     Displays this information.\n");
  1012.    printf("       -r     Resets the modem and communications port.\n");
  1013.    printf("       -a     Turns on auto-answer.\n");
  1014.    printf("       -d     Sends the AT command in SLIP.DIAL.\n");
  1015.    printf("       -s     Shows status information.\n");
  1016.  
  1017.    } /* end help   */
  1018.  
  1019. // ************************************************************************ //
  1020.  get_modem_rc()
  1021. // ************************************************************************ //
  1022.    {
  1023.     unsigned short  i=0, j=0;
  1024.       numbytes=0;                       /* Reset number of bytes read */
  1025.       do
  1026.       {
  1027.        DosRead(comhandle,comchar,23,&numbytes);
  1028.       } while (!numbytes);
  1029.       comchar[numbytes]='\0';            /* Make it a valid C string */
  1030.       printf ("%s\n",comchar);
  1031.  }
  1032.