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