⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 condevs.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 4 页
字号:
		delock(devSel);		}	}#endif HAYESQ#ifdef  VENTELventopn(telno, flds, dev)char *flds[], *telno;struct Devices *dev;{	int     dh;	int     i, ok = -1;	char dcname[20];	sprintf(dcname, "/dev/%s", dev->D_line);	if (setjmp(Sjbuf)) {		DEBUG(1, "timeout ventel open\n", "");		logent("ventel open", "TIMEOUT");		if (dh >= 0)			close(dh);		delock(dev->D_line);		return(CF_NODEV);	}	signal(SIGALRM, alarmtr);	getnextfd();#ifdef ONDELAY	dh = open(dcname, O_RDWR|O_NDELAY);#else	alarm(10);	dh = open(dcname, 2);	alarm(0);#endif	next_fd = -1;	if (dh < 0) {		DEBUG(4,"%s\n", errno == 4 ? "no carrier" : "can't open modem");		delock(dev->D_line);		return(errno == 4 ? CF_DIAL : CF_NODEV);	}#ifdef ULTRIX	if (ioctl(dh, TIOCSINUSE)<0 && errno==EALREADY) {		logent(dcname, "SHARED LINE IN USE");		close(dh);		return(FAIL);	}	Dcf=dh; /* so clsacu will work */	/* 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	/* modem is open */	fixline(dh, dev->D_speed);	/* translate - to % and = to & for VenTel */	DEBUG(4, "calling %s -> ", telno);	for (i = 0; i < strlen(telno); ++i) {		switch(telno[i]) {		case '-':       /* delay */			telno[i] = '%';			break;		case '=':       /* await dial tone */			telno[i] = '&';			break;		case '<':			telno[i] = '%';			break;		}	}	DEBUG(4, "%s\n", telno);	sleep(1);	for(i = 0; i < 5; ++i) {        /* make up to 5 tries */		slowrite(dh, "\r\r");/* awake, thou lowly VenTel! */		DEBUG(4, "wanted %s ", "$");		ok = expect("$", dh);		DEBUG(4, "got %s\n", ok ? "?" : "that");		if (ok != 0)			continue;		slowrite(dh, "K");      /* "K" (enter number) command */		DEBUG(4, "wanted %s ", "DIAL: ");		ok = expect("DIAL: ", dh);		DEBUG(4, "got %s\n", ok ? "?" : "that");		if (ok == 0)			break;	}	if (ok == 0) {		slowrite(dh, telno); /* send telno, send \r */		slowrite(dh, "\r");		DEBUG(4, "wanted %s ", "ONLINE");		ok = expect("ONLINE!", dh);		DEBUG(4, "got %s\n", ok ? "?" : "that");	}	if (ok != 0) {		if (dh > 2)			close(dh);		DEBUG(4, "venDial failed\n", "");		return(CF_DIAL);	} else		DEBUG(4, "venDial ok\n", "");#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 ventel - dh=%d",dh);		logent(msg, "TIMEOUT");		delock(dev->D_line);		clsacu();		return(FAIL);	}	ioctl(dh, TIOCWONLINE); /* wait for carrier */	alarm(0);#endif	return(dh);}/* * uucpdelay:  delay execution for numerator/denominator seconds. */#ifdef INTERVALTIMER#define uucpdelay(num,denom) intervaldelay(1000000*num/denom)#include <sys/time.h>catch alarm sigSIGALRMstruct itimerval itimerval;itimerval.itimer_reload =itimerval.rtime.itimer_interval =itimerval.rtime.itimer_value =settimer(ITIMER_REAL, &itimerval);pause();alarm comes inturn off timer.#endif INTERVALTIMER#ifdef FASTTIMER#define uucpdelay(num,denom) nap(60*num/denom)/*      Sleep in increments of 60ths of second. */nap (time)	register int time;{	static int fd;	if (fd == 0)		fd = open (FASTTIMER, 0);	read (fd, 0, time);}#endif FASTTIMER#ifdef FTIME#define uucpdelay(num,denom) ftimedelay(1000*num/denom)#include <sys/timeb.h>ftimedelay(n){	static struct timeb loctime;	ftime(&loctime);	{register i = loctime.millitm;	   while (abs((int)(loctime.millitm - i))<n) ftime(&loctime);	}}#endif FTIME#ifdef BUSYLOOP#define uucpdelay(num,denom) busyloop(CPUSPEED*num/denom)#define CPUSPEED 1000000        /* VAX 780 is 1MIPS */#define DELAY(n)        { register long N = (n); while (--N > 0); }busyloop(n)	{	DELAY(n);	}#endif BUSYLOOPslowrite(fd, str)register char *str;{	DEBUG(6, "slowrite ", "");	while (*str) {		DEBUG(6, "%c", *str);		uucpdelay(1,10);        /* delay 1/10 second */		write(fd, str, 1);		str++;		}	DEBUG(6, "\n", "");}ventcls(fd)int fd;{	if (fd > 0) {		close(fd);		sleep(5);		delock(devSel);		}}#endif VENTEL#ifdef VADIC/* *      vadopn: establish dial-out connection through a Racal-Vadic 3450. *      Returns descriptor open to tty for reading and writing. *      Negative values (-1...-7) denote errors in connmsg. *      Be sure to disconnect tty when done, via HUPCL or stty 0. */vadopn(telno, flds, dev)char *telno;char *flds[];struct Devices *dev;{	int     dh = -1;	int     i, ok, er = 0, delay;	extern errno;	char dcname[20];	sprintf(dcname, "/dev/%s", dev->D_line);	if (setjmp(Sjbuf)) {		DEBUG(1, "timeout vadic open\n", "");		logent("vadic open", "TIMEOUT");		if (dh >= 0)			close(dh);		delock(dev->D_line);		return(CF_NODEV);	}	signal(SIGALRM, alarmtr);	getnextfd();#ifdef ONDELAY	dh = open(dcname, O_RDWR|O_NDELAY);#else	alarm(10);	dh = open(dcname, 2);	alarm(0);#endif	/* modem is open */	next_fd = -1;	if (dh < 0)		return(FAIL);	/* ensure correct process group if run in background by cron */#ifdef ULTRIX	if (ioctl(dh, TIOCSINUSE)<0 && errno==EALREADY) {		logent(dcname, "SHARED LINE IN USE");		close(dh);		return(FAIL);	}	{	int ret=0;	int temp = 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(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 ULTRIX	fixline(dh, dev->D_speed);/* translate - to K for Vadic */	DEBUG(4, "calling %s -> ", telno);	delay = 0;	for (i = 0; i < strlen(telno); ++i) {		switch(telno[i]) {		case '=':       /* await dial tone */		case '-':       /* delay */		case '<':			telno[i] = 'K';			delay += 5;			break;		}	}	DEBUG(4, "%s\n", telno);	for(i = 0; i < 5; ++i) {        /* make 5 tries */		/* wake up Vadic */		sendthem("\005\\d", dh);		DEBUG(4, "wanted %s ", "*");		ok = expect("*", dh);		DEBUG(4, "got %s\n", ok ? "?" : "that");		if (ok != 0)			continue;		sendthem("D\\d", dh);   /* "D" (enter number) command */		DEBUG(4, "wanted %s ", "NUMBER?\\r\\n");		ok = expect("NUMBER?\r\n", dh);		DEBUG(4, "got %s\n", ok ? "?" : "that");		if (ok != 0)			continue;	/* send telno, send \r */		sendthem(telno, dh);		ok = expect(telno, dh);		if (ok == 0)			ok = expect("\r\n", dh);		DEBUG(4, "got %s\n", ok ? "?" : "that");		if (ok != 0)			continue;		sendthem("", dh); /* confirm number */		DEBUG(4, "wanted %s ", "DIALING: ");		ok = expect("DIALING: ", dh);		DEBUG(4, "got %s\n", ok ? "?" : "that");		if (ok == 0)			break;	}	if (ok == 0) {		sleep(10 + delay);      /* give vadic some time */		DEBUG(4, "wanted ON LINE\\r\\n ", 0);		ok = expect("ON LINE\r\n", dh);		DEBUG(4, "got %s\n", ok ? "?" : "that");	}	if (ok != 0) {		sendthem("I\\d", dh);   /* back to idle */		if (dh > 2)			close(dh);		DEBUG(4, "vadDial failed\n", "");		delock(dev->D_line);		return(CF_DIAL);	}	DEBUG(4, "vadic ok\n", "");#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 vadic - dh=%d",dh);		logent(msg, "TIMEOUT");		delock(dev->D_line);		clsacu();		return(FAIL);	}	ioctl(dh, TIOCWONLINE); /* wait for carrier */	alarm(0);#endif	return(dh);}vadcls(fd) {	if (fd > 0) {		close(fd);		sleep(5);		delock(devSel);		}	}#endif VADIC#ifdef  RVMACS/* * Racal-Vadic 'RV820' MACS system with 831 adaptor. * A typical 300 baud L-devices entry is *      ACU /dev/tty10 /dev/tty11,48 300 rvmacs * where tty10 is the communication line (D_Line), * tty11 is the dialer line (D_calldev), * the '4' is the dialer address + modem type (viz. dialer 0, Bell 103), * and the '8' is the communication port (they are 1-indexed). * BUGS: * Only tested with one dialer, one modem * uses common speed for dialer and communication line. * UNTESTED */#define STX     02      /* Access Adaptor */#define ETX     03      /* Transfer to Dialer */#define SI      017     /* Buffer Empty (end of phone number) */#define SOH     01      /* Abort */rvmacsopn(ph, flds, dev)char *ph, *flds[];struct Devices *dev;{	register int va, i, child;	register char *p;	char c, acu[20], com[20];	child = -1;	if ((p = index(dev->D_calldev, ',')) == NULL) {		DEBUG(2, "No dialer/modem specification\n", 0);		goto failret;	}	*p++ = '\0';	if (setjmp(Sjbuf)) {		logent("rvmacsopn", "TIMEOUT");		i = CF_DIAL;		goto ret;	}	DEBUG(4, "STARTING CALL\n", 0);	sprintf(acu, "/dev/%s", dev->D_calldev);	getnextfd();	signal(SIGALRM, alarmtr);	alarm(30);	if ((va = open(acu, 2)) < 0) {		logent(acu, "CAN'T OPEN");		i = CF_NODEV;		goto ret;	}#ifdef ULTRIX	/* ensure correct process group if run in background by cron */	{	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(va, TIOCSPGRP, &pgrp);	}#endif	fixline(va, dev->D_speed);	p_chwrite(va, STX);     /* access adaptor */	i = *p++ - '0';	if (i < 0 || i > 7) {		logent(p-1, "Bad dialer address/modem type\n");		goto failret;	}	p_chwrite(va, i);               /* Send Dialer Address Digit */	i = *p - '0';	if (i <= 0 || i > 14) {		logent(p-1, "Bad modem address\n");		goto failret;	}	p_chwrite(va, i-1);     /* Send Modem Address Digit */	write(va, ph, strlen(ph));      /* Send Phone Number */	p_chwrite(va, SI);      /* Send Buffer Empty */	p_chwrite(va, ETX);     /* Initiate Call */	sprintf(com, "/dev/%s", dev->D_line);	/* create child to open comm line */	if ((child = fork()) == 0) {		signal(SIGINT, SIG_DFL);		open(com, 0);		sleep(5);		exit(1);	}	if (read(va, &c, 1) != 1) {		logent("ACU READ", "FAILED");		goto failret;	}	switch(c) {	case 'A':		/* Fine! */		break;	case 'B':		DEBUG(2, "CALL ABORTED\n", 0);		goto failret;	case 'D':		DEBUG(2, "Dialer format error\n", 0);		goto failret;	case 'E':		DEBUG(2, "Dialer parity error\n", 0);		goto failret;	case 'F':		DEBUG(2, "Phone number too long\n", 0);		goto failret;	case 'G':		DEBUG(2, "Busy signal\n", 0);		goto failret;	default:		DEBUG(2, "Unknown MACS return code '%c'\n", i);		goto failret;	}	/*	 * open line - will return on carrier	 */	if ((i = open(com, 2)) < 0) {		if (errno == EIO)			logent("carrier", "LOST");		else			logent("dialup open", "FAILED");		goto failret;	}#ifdef ULTRIX	/* ensure correct process group if run in background by cron */	{	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(i, TIOCSPGRP, &pgrp);	}#endif	fixline(i, dev->D_speed);	goto ret;failret:	i = CF_DIAL;ret:	alarm(0);	if (child != -1)		kill(child, SIGKILL);	close(va);	return(i);}rvmacscls(fd)register int fd;{	DEBUG(2, "MACS close %d\n", fd);	p_chwrite(fd, SOH);/*      ioctl(fd, TIOCCDTR, NULL);*/	close(fd);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -