home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / tip / aculib / v3451.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-18  |  4.9 KB  |  215 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)v3451.c    5.5 (Berkeley) 3/2/91";
  36. #endif /* not lint */
  37.  
  38. /*
  39.  * Routines for calling up on a Vadic 3451 Modem
  40.  */
  41. #include "tip.h"
  42.  
  43. static    jmp_buf Sjbuf;
  44.  
  45. v3451_dialer(num, acu)
  46.     register char *num;
  47.     char *acu;
  48. {
  49.     sig_t func;
  50.     int ok;
  51.     int slow = number(value(BAUDRATE)) < 1200, rw = 2;
  52.     char phone[50];
  53. #ifdef ACULOG
  54.     char line[80];
  55. #endif
  56.     static int expect();
  57.     static void vawrite();
  58.  
  59.     /*
  60.      * Get in synch
  61.      */
  62.     vawrite("I\r", 1 + slow);
  63.     vawrite("I\r", 1 + slow);
  64.     vawrite("I\r", 1 + slow);
  65.     vawrite("\005\r", 2 + slow);
  66.     if (!expect("READY")) {
  67.         printf("can't synchronize with vadic 3451\n");
  68. #ifdef ACULOG
  69.         logent(value(HOST), num, "vadic", "can't synch up");
  70. #endif
  71.         return (0);
  72.     }
  73.     ioctl(FD, TIOCHPCL, 0);
  74.     sleep(1);
  75.     vawrite("D\r", 2 + slow);
  76.     if (!expect("NUMBER?")) {
  77.         printf("Vadic will not accept dial command\n");
  78. #ifdef ACULOG
  79.         logent(value(HOST), num, "vadic", "will not accept dial");
  80. #endif
  81.         return (0);
  82.     }
  83.     strcpy(phone, num);
  84.     strcat(phone, "\r");
  85.     vawrite(phone, 1 + slow);
  86.     if (!expect(phone)) {
  87.         printf("Vadic will not accept phone number\n");
  88. #ifdef ACULOG
  89.         logent(value(HOST), num, "vadic", "will not accept number");
  90. #endif
  91.         return (0);
  92.     }
  93.     func = signal(SIGINT,SIG_IGN);
  94.     /*
  95.      * You cannot interrupt the Vadic when its dialing;
  96.      * even dropping DTR does not work (definitely a
  97.      * brain damaged design).
  98.      */
  99.     vawrite("\r", 1 + slow);
  100.     vawrite("\r", 1 + slow);
  101.     if (!expect("DIALING:")) {
  102.         printf("Vadic failed to dial\n");
  103. #ifdef ACULOG
  104.         logent(value(HOST), num, "vadic", "failed to dial");
  105. #endif
  106.         return (0);
  107.     }
  108.     if (boolean(value(VERBOSE)))
  109.         printf("\ndialing...");
  110.     ok = expect("ON LINE");
  111.     signal(SIGINT, func);
  112.     if (!ok) {
  113.         printf("call failed\n");
  114. #ifdef ACULOG
  115.         logent(value(HOST), num, "vadic", "call failed");
  116. #endif
  117.         return (0);
  118.     }
  119.     ioctl(FD, TIOCFLUSH, &rw);
  120.     return (1);
  121. }
  122.  
  123. v3451_disconnect()
  124. {
  125.  
  126.     close(FD);
  127. }
  128.  
  129. v3451_abort()
  130. {
  131.  
  132.     close(FD);
  133. }
  134.  
  135. static void
  136. vawrite(cp, delay)
  137.     register char *cp;
  138.     int delay;
  139. {
  140.  
  141.     for (; *cp; sleep(delay), cp++)
  142.         write(FD, cp, 1);
  143. }
  144.  
  145. static
  146. expect(cp)
  147.     register char *cp;
  148. {
  149.     char buf[300];
  150.     register char *rp = buf;
  151.     int timeout = 30, online = 0;
  152.     static int notin();
  153.     static void alarmtr();
  154.  
  155.     if (strcmp(cp, "\"\"") == 0)
  156.         return (1);
  157.     *rp = 0;
  158.     /*
  159.      * If we are waiting for the Vadic to complete
  160.      * dialing and get a connection, allow more time
  161.      * Unfortunately, the Vadic times out 24 seconds after
  162.      * the last digit is dialed
  163.      */
  164.     online = strcmp(cp, "ON LINE") == 0;
  165.     if (online)
  166.         timeout = number(value(DIALTIMEOUT));
  167.     signal(SIGALRM, alarmtr);
  168.     if (setjmp(Sjbuf))
  169.         return (0);
  170.     alarm(timeout);
  171.     while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
  172.         if (online && notin("FAILED CALL", buf) == 0)
  173.             return (0);
  174.         if (read(FD, rp, 1) < 0) {
  175.             alarm(0);
  176.             return (0);
  177.         }
  178.         if (*rp &= 0177)
  179.             rp++;
  180.         *rp = '\0';
  181.     }
  182.     alarm(0);
  183.     return (1);
  184. }
  185.  
  186. static void
  187. alarmtr()
  188. {
  189.     longjmp(Sjbuf, 1);
  190. }
  191.  
  192. static int
  193. notin(sh, lg)
  194.     char *sh, *lg;
  195. {
  196.     static int prefix();
  197.  
  198.     for (; *lg; lg++)
  199.         if (prefix(sh, lg))
  200.             return (0);
  201.     return (1);
  202. }
  203.  
  204. static
  205. prefix(s1, s2)
  206.     register char *s1, *s2;
  207. {
  208.     register char c;
  209.  
  210.     while ((c = *s1++) == *s2++)
  211.         if (c == '\0')
  212.             return (1);
  213.     return (c == '\0');
  214. }
  215.