int xf86OpenSerial (pointer options)
{
	APIRET rc;
	HFILE fd, i;
	ULONG action;
	GLINECTL linectl;

	char* dev = xf86FindOptionValue (options, "Device");
	xf86MarkOptionUsedByName (options, "Device");
	if (!dev) {
		xf86Msg (X_ERROR, "xf86OpenSerial: No Device specified.\n");
		return -1;
	}

	rc = DosOpen(dev, &fd, &action, 0, FILE_NORMAL, FILE_OPEN,
		     OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, NULL);
	if (rc) {
		xf86Msg (X_ERROR,
			 "xf86OpenSerial: Cannot open device %s, rc=%d.\n",
			 dev, rc);
		return -1;
	}

	/* check whether it is an async device */
	if (_get_linectrl(fd,&linectl)) {
		xf86Msg (X_WARNING,
			 "xf86OpenSerial: Specified device %s is not a tty\n",
			 dev);
		DosClose(fd);
		return -1;
	}

	/* set up default port parameters */
	_set_baudrate(fd, 9600);

	linectl.databits = 8;
	linectl.parity = 0;
	linectl.stopbits = 0;
	_set_linectl(fd, &linectl);

	if (xf86SetSerial (fd, options) == -1) {
		DosClose(fd);
		return -1;
	}

	return fd;
}
Beispiel #2
0
int
xf86SetSerial(int fd, XF86OptionPtr options)
{
    struct termios t;
    int val;
    const char *s;
    int baud, r;

    if (fd < 0)
        return -1;

    /* Don't try to set parameters for non-tty devices. */
    if (!isatty(fd))
        return 0;

    SYSCALL(tcgetattr(fd, &t));

    if ((val = xf86SetIntOption(options, "BaudRate", 0))) {
        if ((baud = GetBaud(val))) {
            cfsetispeed(&t, baud);
            cfsetospeed(&t, baud);
        }
        else {
            xf86Msg(X_ERROR, "Invalid Option BaudRate value: %d\n", val);
            return -1;
        }
    }

    if ((val = xf86SetIntOption(options, "StopBits", 0))) {
        switch (val) {
        case 1:
            t.c_cflag &= ~(CSTOPB);
            break;
        case 2:
            t.c_cflag |= CSTOPB;
            break;
        default:
            xf86Msg(X_ERROR, "Invalid Option StopBits value: %d\n", val);
            return -1;
            break;
        }
    }

    if ((val = xf86SetIntOption(options, "DataBits", 0))) {
        switch (val) {
        case 5:
            t.c_cflag &= ~(CSIZE);
            t.c_cflag |= CS5;
            break;
        case 6:
            t.c_cflag &= ~(CSIZE);
            t.c_cflag |= CS6;
            break;
        case 7:
            t.c_cflag &= ~(CSIZE);
            t.c_cflag |= CS7;
            break;
        case 8:
            t.c_cflag &= ~(CSIZE);
            t.c_cflag |= CS8;
            break;
        default:
            xf86Msg(X_ERROR, "Invalid Option DataBits value: %d\n", val);
            return -1;
            break;
        }
    }

    if ((s = xf86SetStrOption(options, "Parity", NULL))) {
        if (xf86NameCmp(s, "Odd") == 0) {
            t.c_cflag |= PARENB | PARODD;
        }
        else if (xf86NameCmp(s, "Even") == 0) {
            t.c_cflag |= PARENB;
            t.c_cflag &= ~(PARODD);
        }
        else if (xf86NameCmp(s, "None") == 0) {
            t.c_cflag &= ~(PARENB);
        }
        else {
            xf86Msg(X_ERROR, "Invalid Option Parity value: %s\n", s);
            return -1;
        }
    }

    if ((val = xf86SetIntOption(options, "Vmin", -1)) != -1) {
        t.c_cc[VMIN] = val;
    }
    if ((val = xf86SetIntOption(options, "Vtime", -1)) != -1) {
        t.c_cc[VTIME] = val;
    }

    if ((s = xf86SetStrOption(options, "FlowControl", NULL))) {
        xf86MarkOptionUsedByName(options, "FlowControl");
        if (xf86NameCmp(s, "Xoff") == 0) {
            t.c_iflag |= IXOFF;
        }
        else if (xf86NameCmp(s, "Xon") == 0) {
            t.c_iflag |= IXON;
        }
        else if (xf86NameCmp(s, "XonXoff") == 0) {
            t.c_iflag |= IXON | IXOFF;
        }
        else if (xf86NameCmp(s, "None") == 0) {
            t.c_iflag &= ~(IXON | IXOFF);
        }
        else {
            xf86Msg(X_ERROR, "Invalid Option FlowControl value: %s\n", s);
            return -1;
        }
    }

    if ((xf86SetBoolOption(options, "ClearDTR", FALSE))) {
#ifdef CLEARDTR_SUPPORT
#if defined(TIOCMBIC)
        val = TIOCM_DTR;
        SYSCALL(ioctl(fd, TIOCMBIC, &val));
#else
        SYSCALL(ioctl(fd, TIOCCDTR, NULL));
#endif
#else
        xf86Msg(X_WARNING, "Option ClearDTR not supported on this OS\n");
        return -1;
#endif
        xf86MarkOptionUsedByName(options, "ClearDTR");
    }

    if ((xf86SetBoolOption(options, "ClearRTS", FALSE))) {
        xf86Msg(X_WARNING, "Option ClearRTS not supported on this OS\n");
        return -1;
        xf86MarkOptionUsedByName(options, "ClearRTS");
    }

    SYSCALL(r = tcsetattr(fd, TCSANOW, &t));
    return r;
}
int xf86SetSerial (int fd, pointer options)
{
	APIRET rc;
	USHORT baud;
	ULONG plen,dlen;
	char *s;

	GLINECTL linectl;
	DCBINFO dcb;

	if ((s = xf86FindOptionValue (options, "BaudRate"))) {
		xf86MarkOptionUsedByName (options, "BaudRate");
		if ((rc = _set_baudrate(fd, atoi(s)))) {
			xf86Msg (X_ERROR,"Set Baudrate: %s, rc=%d\n", s, rc);
			return -1;
		}
	}

	/* get line parameters */
	if (DosDevIOCtl((HFILE)fd,IOCTL_ASYNC, ASYNC_GETLINECTRL,
			NULL,0,NULL,
			(PULONG)&linectl,sizeof(GLINECTL),&dlen)) return -1;

	if ((s = xf86FindOptionValue (options, "StopBits"))) {
		xf86MarkOptionUsedByName (options, "StopBits");
		switch (atoi (s)) {
		case 1:	linectl.stopbits = 0;
			break;
		case 2:	linectl.stopbits = 2;
			break;
		default: xf86Msg (X_ERROR,
				 "Invalid Option StopBits value: %s\n", s);
			return -1;
		}
	}

	if ((s = xf86FindOptionValue (options, "DataBits"))) {
		int db;
		xf86MarkOptionUsedByName (options, "DataBits");
		switch (db = atoi (s)) {
		case 5: case 6: case 7: case 8:
			linectl.databits = db;
			break;
		default: xf86Msg (X_ERROR,
				 "Invalid Option DataBits value: %s\n", s);
			return -1;
		}
	}

	if ((s = xf86FindOptionValue (options, "Parity"))) {
		xf86MarkOptionUsedByName (options, "Parity");
		if (xf86NameCmp (s, "Odd") == 0)
			linectl.parity = 1; /* odd */
		else if (xf86NameCmp (s, "Even") == 0)
			linectl.parity = 2; /* even */
		else if (xf86NameCmp (s, "None") == 0)
			linectl.parity = 0; /* none */
		else {
			xf86Msg (X_ERROR,
				 "Invalid Option Parity value: %s\n", s);
			return -1;
		}
	}

	/* set line parameters */
	if (_set_linectl(fd,&linectl)) return -1;

	if (xf86FindOptionValue (options, "Vmin"))
		xf86Msg (X_ERROR, "Vmin unsupported on this OS\n");

	if (xf86FindOptionValue (options, "Vtime"))
		xf86Msg (X_ERROR, "Vtime unsupported on this OS\n");

	/* get device parameters */
	if (_get_dcb(fd,&dcb)) return -1;

	if ((s = xf86FindOptionValue (options, "FlowControl"))) {
		xf86MarkOptionUsedByName (options, "FlowControl");
		if (xf86NameCmp (s, "XonXoff") == 0)
			dcb.fbFlowReplace |= 0x03;
		else if (xf86NameCmp (s, "None") == 0)
			dcb.fbFlowReplace &= ~0x03;
		else {
			xf86Msg (X_ERROR,
				 "Invalid Option FlowControl value: %s\n", s);
			return -1;
		}
	}

	if ((s = xf86FindOptionValue (options, "ClearDTR"))) {
		dcb.fbCtlHndShake &= ~0x03; /* DTR=0 */
		xf86MarkOptionUsedByName (options, "ClearDTR");
	}

	if ((s = xf86FindOptionValue (options, "ClearRTS"))) {
		dcb.fbFlowReplace &= ~0xc0; /* RTS=0 */
		xf86MarkOptionUsedByName (options, "ClearRTS");
	}

	/* set device parameters */
	return _set_dcb(fd,&dcb) ? -1 : 0;
}