📄 condevs.c
字号:
ttbuf.c_cflag |= HUPCL; ioctl(dnf, TCSETA, &ttbuf); }#endif alarm(0); fflush(stdout); fixline(dnf, dev->D_speed); return(dnf);}/* * df0cls() close the DF02/DF03 call unit * * return codes: none */df0cls(fd)register int fd;{ char msg[20]; DEBUG(5, "close df02/df03, Dcf=%d\n", fd); if (fd > 0) { ioctl(fd, TIOCCDTR, STBNULL); write(fd, "\01", 1); if (close(fd) < 0) { sprintf(msg,"errno=%d, fd=%d",errno, fd); logent(msg, "could not close acu"); } else { sprintf(msg,"fd=%d",fd); logent(msg,"closed df0 type acu"); } sleep(5); delock(devSel); }}#endif DF0#ifdef DF112/*** * df112opn(telno, flds, dev) connect to df112 * char *flds[], *dev[]; * * return codes: * >0 - file number - ok * CF_DIAL,CF_DEVICE - failed *//* * Assume touch tone for now */df112opn(telno, flds, dev)char *telno;char *flds[];struct Devices *dev;{ int dh = -1; register int i; extern errno; char dcname[20]; sprintf(dcname, "/dev/%s", dev->D_line); DEBUG(4, "dc - %s\n", dcname); if (setjmp(Sjbuf)) { DEBUG(1, "timeout df112 open %s\n", dcname); logent("df112 open", "TIMEOUT"); if (Dcf >= 0) clsacu(); delock(dev->D_line); return(CF_DIAL); } signal(SIGALRM, alarmtr); getnextfd(); /* translate telephone number for df112 */ for (i = 0; i < strlen(telno); ++i) { switch(telno[i]) { case '-': /* delay */ telno[i] = '='; break; /* = is the only character interpreted by the df112 */ } }#ifdef ONDELAY dh = open(dcname, O_RDWR|O_NDELAY);#else alarm(10); dh = open(dcname, 2); /* read/write */ alarm(0);#endif /* modem is open */ next_fd = -1; if (dh >= 0) {#ifdef ULTRIX if (ioctl(dh, TIOCSINUSE)<0 && errno==EALREADY) { logent(dcname, "SHARED LINE IN USE"); close(dh); return(FAIL); } /* ensure correct process group if run in background by cron */ { int ret=0; int pgrp = getpid(); /* XXX: was getpgrp(), not getpid() */ int temp = 0; ret=setpgrp(pgrp, pgrp); /* XXX: first pgrp is really our pid */ if (ret < 0) DEBUG(6,"setpgrp failed, errno=%d\n", errno); ioctl(dh, TIOCSPGRP, &pgrp);#ifdef ONDELAY /* we are attatched to a modem so dont ignore modem signals */ ioctl(dh, TIOCMODEM, &temp); ioctl(dh, TIOCNCAR); /* ignore soft carr while dialing number */#endif }#endif Dcf=dh; /* so clsacu will work */ fixline(dh, dev->D_speed); sleep(2); /*cntrl B = interactive mode, P = pulse dial */ write(dh, "\01", 1);/* * unfortunately this stuff will probably break on a dmf32 because * the dmf will drop characters until carrier comes up * if (expect("Ready", dh) != 0) { * logent("df112 not ready", "FAILED"); * strcpy(devSel, dev->D_line); * df112cls(dh); * return(CF_DIAL); * }*/ write(dh, "P", 1); write(dh, telno, strlen(telno)); write(dh, "#", 1);/* if (expect("tached", dh) != 0) { logent("df112 no carrier", "FAILED"); strcpy(devSel, dev->D_line); df112cls(dh); return(CF_DIAL); }*/ } if (dh < 0) { DEBUG(4, "df112 failed\n", ""); delock(dev->D_line); return(FAIL); }#ifdef ONDELAY ioctl(dh, TIOCCAR); /* dont ignore carrier anymore */ alarm(40); /* find a better timeout value */ if (setjmp(Sjbuf)) { char msg[50]; DEBUG(1, "no carrier", "timeout"); sprintf(msg, "no carrier df112 - dh=%d",dh); logent(msg, "TIMEOUT"); delock(dev->D_line); clsacu(); return(FAIL); } ioctl(dh, TIOCWONLINE); /* wait for carrier */ alarm(0);#endif DEBUG(4, "df112 ok\n", ""); return(dh);}df112cls(fd)int fd;{ char dcname[20]; struct sgttyb hup, sav; char msg[50]; if (fd > 0) { sprintf(dcname, "/dev/%s", devSel); DEBUG(4, "Hanging up fd = %d\n", fd); ioctl(fd, TIOCCDTR, STBNULL); sleep(2); sprintf(msg, "fd= %d", fd); logent(msg, "df112: closing"); errno = 0; if (close(fd)<0) { sprintf(msg, "errno =%d", errno); logent(msg, "df112: could not close"); } delock(devSel); } }#endif DF112#ifdef HAYES/*** * hysopn(telno, flds, dev) connect to hayes smartmodem * char *flds[], *dev[]; * * return codes: * >0 - file number - ok * CF_DIAL,CF_DEVICE - failed *//* * Define HAYSTONE if you have touch tone dialing. *//*#define HAYSTONE */hysopn(telno, flds, dev)char *telno;char *flds[];struct Devices *dev;{ int dh = -1; register int i; extern errno; char dcname[20]; sprintf(dcname, "/dev/%s", dev->D_line); DEBUG(4, "dc - %s\n", dcname); if (setjmp(Sjbuf)) { DEBUG(1, "timeout hayes open %s\n", dcname); logent("hayes open", "TIMEOUT"); if (Dcf >= 0) clsacu(); delock(dev->D_line); return(CF_DIAL); } signal(SIGALRM, alarmtr); getnextfd(); /* translate telephone number for hayes */ for (i = 0; i < strlen(telno); ++i) { switch(telno[i]) { case '-': /* delay */ telno[i] = ','; break; case '=': /* await dial tone */ telno[i] = ','; break; } }#ifdef ONDELAY dh = open(dcname, O_RDWR|O_NDELAY);#else alarm(10); dh = open(dcname, 2); /* read/write */ alarm(0);#endif /* modem is open */ next_fd = -1; if (dh >= 0) {#ifdef ULTRIX if (ioctl(dh, TIOCSINUSE)<0 && errno==EALREADY) { logent(dcname, "SHARED LINE IN USE"); close(dh); return(FAIL); } Dcf = dh; /* ensure correct process group if run in background by cron */ { int ret=0; int pgrp = getpid(); /* XXX: was getpgrp(), not getpid() */ int temp = 0; ret=setpgrp(pgrp, pgrp); /* XXX: first pgrp is really our pid */ if (ret < 0) DEBUG(6,"setpgrp failed, errno=%d\n", errno); ioctl(dh, TIOCSPGRP, &pgrp);#ifdef ONDELAY /* we are attatched to a modem so dont ignore modem signals */ ioctl(dh, TIOCMODEM, &temp); ioctl(dh, TIOCNCAR); /* ignore soft carr while dialing number */#endif }#endif fixline(dh, dev->D_speed); sleep(2); write(dh, "+++", 3); sleep(2); write(dh, "ATH\r", 4); sleep(1); write(dh, "ATZ\r", 4); sleep(2); write(dh, "+++", 3); sleep(2);#ifdef HAYSTONE write(dh, "ATDT", 4);#else write(dh, "ATDP", 4);#endif write(dh, telno, strlen(telno)); write(dh, "\r", 1); if (expect("CONNECT", dh) != 0) { logent("HSM no carrier", "FAILED"); strcpy(devSel, dev->D_line); hyscls(dh); return(CF_DIAL); } } if (dh < 0) { DEBUG(4, "hayes failed\n", ""); return(FAIL); }#ifdef ONDELAY ioctl(dh, TIOCCAR); /* dont ignore carrier anymore */ alarm(40); /* find a better timeout value */ if (setjmp(Sjbuf)) { char msg[50]; DEBUG(1, "no carrier", "timeout"); sprintf(msg, "no carrier hayes - dh=%d",dh); logent(msg, "TIMEOUT"); delock(dev->D_line); clsacu(); return(FAIL); } ioctl(dh, TIOCWONLINE); /* wait for carrier */ alarm(0);#endif DEBUG(4, "hayes ok\n", ""); return(dh);}hyscls(fd)int fd;{ char dcname[20]; struct sgttyb hup, sav; char msg[50]; if (fd > 0) { sprintf(dcname, "/dev/%s", devSel); DEBUG(4, "Hanging up fd = %d\n", fd); ioctl(fd, TIOCCDTR, STBNULL); sleep(2);/* * If you have a getty sleeping on this line, when it wakes up it sends * all kinds of garbage to the modem. Unfortunatly, the modem likes to * execute the previous command when it sees the garbage. The previous * command was to dial the phone, so let's make the last command reset * the modem. */ sleep(2); write(fd, "+++", 3); sleep(2); write(fd, "ATZ\r", 4); sprintf(msg, "fd= %d", fd); logent(msg, "hayes: closing"); errno = 0; if (close(fd)<0) { sprintf(msg, "errno =%d", errno); logent(msg, "hayesq: could not close"); } delock(devSel); } }#endif HAYES#ifdef HAYESQ/* * New dialout routine to work with Hayes' SMART MODEM * 13-JUL-82, Mike Mitchell * Modified 23-MAR-83 to work with Tom Truscott's (rti!trt) * version of UUCP (ncsu!mcm) * * The modem should be set to NOT send any result codes to * the system (switch 3 up, 4 down). This end will figure out * what is wrong. * * I had lots of problems with the modem sending * result codes since I am using the same modem for both incomming and * outgoing calls. I'd occasionally miss the result code (getty would * grab it), and the connect would fail. Worse yet, the getty would * think the result code was a user name, and send garbage to it while * it was in the command state. I turned off ALL result codes, and hope * for the best. 99% of the time the modem is in the correct state. * Occassionally it doesn't connect, or the phone was busy, etc., and * uucico sits there trying to log in. It eventually times out, calling * clsacu() in the process, so it resets itself for the next attempt. *//* * Define HAYSTONE if touch-tone dialing is to be used. If it is not defined, * Pulse dialing is assumed. *//*#define HAYSTONE*/hysqopn(telno, flds, dev)char *telno, *flds[];struct Devices *dev;{ char dcname[20], phone[MAXPH+10], c = 0;#ifdef SYSIII struct termio ttbuf;#endif int status, dnf; register int i; unsigned timelim; signal(SIGALRM, alarmtr); sprintf(dcname, "/dev/%s", dev->D_line); /* translate telephone number for hayes */ for (i = 0; i < strlen(telno); ++i) { switch(telno[i]) { case '-': /* delay */ telno[i] = ','; break; case '=': /* await dial tone */ telno[i] = ','; break; } } getnextfd(); if (setjmp(Sjbuf)) { delock(dev->D_line); logent("TIMEOUT", "HAYESQ"); DEBUG(4, "Open timed out %s", dcname); if (Dcf > 0) clsacu(); return(CF_NODEV); } alarm(10); if ((dnf = open(dcname, 2)) <= 0) { delock(dev->D_line); logent("DEVICE", "NO"); DEBUG(4, "Can't open %s", dcname); return(CF_NODEV); }#ifdef ULTRIX /* ensure correct process group if run in background by cron */ { int ret=0; int pgrp = getpid(); /* XXX: was getpgrp(), not getpid() */ ret=setpgrp(pgrp, pgrp); /* XXX: first pgrp is really our pid */ if (ret < 0) DEBUG(6,"setpgrp failed, errno=%d\n", errno); ioctl(dnf, TIOCSPGRP, &pgrp); } if (ioctl(dnf, TIOCSINUSE)<0 && errno==EALREADY) { logent(dcname, "SHARED LINE IN USE"); close(dnf); return(FAIL); }#endif Dcf = dnf; alarm(0); next_fd = -1; fixline(dnf, dev->D_speed); DEBUG(4, "Hayes port - %s, ", dcname); sleep(2); write(dnf, "+++", 3); sleep(2); write(dnf, "ATH\r", 4); sleep(1); write(dnf, "ATZ\r", 4); sleep(2); write(dnf, "+++", 3); sleep(2);#ifdef HAYSTONE sprintf(phone, "ATDT%s\r", telno);#else sprintf(phone, "ATDP%s\r", telno);#endif write(dnf, phone, strlen(phone));/* calculate delay time for the other system to answer the phone. * Default is 15 seconds, add 2 seconds for each comma in the phone * number. */ timelim = 150; while(*telno) { c = *telno++; if (c == ',') timelim += 20; else {#ifdef HAYSTONE timelim += 2; /* .2 seconds per tone */ }#else if (c == '0') timelim += 10; /* .1 second per digit */ else if (c > '0' && c <= '9') timelim += (c - '0'); }#endif } alarm(timelim/10); if (setjmp(Sjbuf) == 0) { read(dnf, &c, 1); alarm(0); } return(dnf); }hysqcls(fd)int fd;{ char dcname[20]; struct sgttyb hup, sav; char msg[50]; if (fd > 0) { sprintf(dcname, "/dev/%s", devSel); DEBUG(4, "Hanging up fd = %d\n", fd); ioctl(fd, TIOCCDTR, STBNULL); sleep(2);/* * If you have a getty sleeping on this line, when it wakes up it sends * all kinds of garbage to the modem. Unfortunatly, the modem likes to * execute the previous command when it sees the garbage. The previous * command was to dial the phone, so let's make the last command reset * the modem. */ sleep(2); write(fd, "+++", 3); sleep(2); write(fd, "ATZ\r", 4); sprintf(msg, "fd= %d", fd); logent(msg, "hayesq: closing"); errno = 0; if (close(fd)<0) { sprintf(msg, "errno =%d", errno); logent(msg, "hayesq: could not close"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -