1 /*- 2 * Copyright (c) 1985, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)sy.c 8.1 (Berkeley) 06/06/93"; 10 #endif /* not lint */ 11 12 #include "condevs.h" 13 14 #ifdef SYTEK 15 16 /* 17 * sykopn: establish connection through a sytek port. 18 * Returns descriptor open to tty for reading and writing. 19 * Negative values (-1...-7) denote errors in connmsg. 20 * Will try to change baud rate of local port to match 21 * that of the remote side. 22 */ 23 char sykspeed[50]; /* speed to reset to on close */ 24 25 sykopn(flds) 26 register char *flds[]; 27 { 28 extern errno; 29 char *rindex(), *fdig(), dcname[20]; 30 int dh, ok = 0, speed; 31 register FILE *dfp; 32 struct Devices dev; 33 char speedbuf[50]; 34 35 dfp = fopen(DEVFILE, "r"); 36 ASSERT(dfp != NULL, "Can't open", DEVFILE, 0); 37 38 signal(SIGALRM, alarmtr); 39 dh = -1; 40 while(rddev(dfp, &dev) != FAIL) { 41 /* we'll set our own speed; F_CLASS is how cynthia configures it every night 42 if (strcmp(flds[F_CLASS], dev.D_class) != SAME) 43 continue; 44 */ 45 if (snccmp(flds[F_LINE], dev.D_type) != SAME) 46 continue; 47 if (mlock(dev.D_line) == FAIL) 48 continue; 49 50 sprintf(dcname, "/dev/%s", dev.D_line); 51 getnextfd(); 52 alarm(10); 53 if (setjmp(Sjbuf)) { 54 delock(dev.D_line); 55 logent(dev.D_line,"sytek open TIMEOUT"); 56 dh = -1; 57 break; 58 } 59 dh = open(dcname, 2); 60 alarm(0); 61 next_fd = -1; 62 if (dh > 0) { 63 break; 64 } 65 devSel[0] = '\0'; 66 delock(dev.D_line); 67 } 68 fclose(dfp); 69 if (dh < 0) 70 return(CF_NODEV); 71 72 speed = atoi(fdig(dev.D_class)); 73 fixline(dh, speed); 74 sleep(1); 75 76 /* negotiate with sytek */ 77 genbrk(dh, 3); 78 79 DEBUG(4, "wanted %s ", "#"); 80 ok = expect("#", dh); 81 DEBUG(4, "got %s\n", ok ? "?" : "that"); 82 if(ok != 0){ 83 if(atoi(fdig(dev.D_class)) == 9600){ 84 fixline(dh, 2400); 85 speed = 2400; 86 } else { 87 fixline(dh, 9600); 88 speed = 9600; 89 } 90 sleep(1); 91 genbrk(dh, 3); 92 ok = expect("#", dh); 93 if(ok){ 94 close(dh); 95 DEBUG(4, "sytek BREAK failed\n", ""); 96 delock(dev.D_line); 97 return(CF_DIAL); 98 } 99 } 100 write(dh, "done \r", 6); 101 ok = expect("#", dh); 102 DEBUG(4, "got %s\n", ok ? "?" : "that"); 103 if(speed != atoi(fdig(flds[F_CLASS]))){ 104 DEBUG(4, "changing speed\n", ""); 105 sprintf(speedbuf, "baud %s\r", fdig(flds[F_CLASS])); 106 write(dh, speedbuf, strlen(speedbuf)); 107 sleep(1); 108 speed = atoi(fdig(flds[F_CLASS])); 109 fixline(dh, speed); 110 genbrk(dh, 3); 111 ok = expect("#", dh); 112 DEBUG(4, "speed set %s\n", ok ? "failed" : flds[F_CLASS]); 113 } 114 strcpy(sykspeed, dev.D_class); 115 write(dh, "command break\r", 14); 116 ok = expect("#", dh); 117 DEBUG(4, "got %s\n", ok ? "?" : "that"); 118 if (ok == 0) { 119 write(dh, "call ", 5); 120 write(dh, flds[F_PHONE], strlen(flds[F_PHONE])); 121 write(dh, "\r", 1); 122 DEBUG(4, "sytek dial %s\n", flds[F_PHONE]); 123 DEBUG(4, "wanted %s ", "COMPLETED TO "); 124 ok = expect("COMPLETED TO ", dh); 125 DEBUG(4, "got %s\n", ok ? "?" : "that"); 126 } 127 128 if (ok != 0) { 129 close(dh); 130 DEBUG(4, "sytek failed\n", ""); 131 delock(dev.D_line); 132 return(CF_DIAL); 133 } else 134 DEBUG(4, "sytek ok\n", ""); 135 136 CU_end = sykcls; 137 strcpy(devSel, dev.D_line); /* for later unlock */ 138 return(dh); 139 140 } 141 142 sykcls(fd) 143 register int fd; 144 { 145 register int ok, speed; 146 147 148 if (fd > 0) { 149 genbrk(fd, 3); 150 ok = expect("#", fd); 151 DEBUG(4, "got %s\n", ok ? "?" : "that"); 152 if(ok != 0){ 153 genbrk(fd, 3); 154 ok = expect("#", fd); 155 } 156 if(ok == 0){ 157 write(fd, "done 1\r", 7); 158 ok = expect("#", fd); 159 DEBUG(4, "got %s\n", ok ? "?" : "that"); 160 DEBUG(4, "reset baud to %s\n", sykspeed); 161 write(fd, "baud ", 5); 162 write(fd, sykspeed, strlen(sykspeed)); 163 write(fd, "\r", 1); 164 sleep(1); 165 } 166 close(fd); 167 delock(devSel); 168 } 169 } 170 #endif SYTEK 171