#include <sys/param.h>
#include <termios.h>

int	fd;
char	*dev;
char    name[32];
char    devname[32];

#define DEFAULT_BAUD	38400

int speed = DEFAULT_BAUD;

/* Close the tty port. */

closetty() {

	if (fd == -1) return;			/* not open */

	write(fd, "\r", 1);			/* abort any command */
	delay(200);
	write(fd, "ATH0\r", 5);			/* go onhook */
	delay(200);
	write(fd, "ATZ\r", 4);			/* reset the modem */
	delay(400);
	close(fd);
	fd= -1;
}


/* Open the device on handle 'fd', exit if error (not very nice). */

opentty() {
	struct termios tp;

	if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) {
		perror(dev);
		exit(1);
	}

	if (tcgetattr (fd, &tp) < 0) {
		perror("ixocico:opentty:tcgetattr");
		exit(1);
	};
	cfmakeraw(&tp);
	tp.c_cflag |= CLOCAL | CREAD | HUPCL | CRTSCTS;
	cfsetspeed(&tp, speed);

	if (tcsetattr (fd,TCSADRAIN, &tp) < 0) {
		perror("fone:setup2:tcsetattr");
		exit(1);
	};
}
