Help in writing a Modem driver

Rohit Mehrotra rohit at dmdev.UUCP
Fri Aug 3 01:35:51 AEST 1990


Hi,

I am looking for help in writing a simple program which would
open a serial port (has a modem connected to it), dial a 
number, and then hangup the modem after the call, on a SparcStation
running SunOS 4.1.

I have the above routines more or LESS written and working.  My
problem is that the modem does not hangup by just using the ioctl()
calls. 

I have heard that there is a way to do it cleanly by just using 
ioctl() calls correctly, but well I do not know it.

Any help would be greatly appreciated.

Please EMAIL any responses directly, and I would post the summary.

EMAIL : uunet!dmdev!rohit
	rohit!dmdev at uunet.UUCP
VMAIL : 1-800-289-7500 x 469

Thanks a lot in advance

rohit

Following is the code that I have got:
/******************************************************************/
#include <fcntl.h>
#include <termio.h>
#include <time.h>
#include <sys/types.h>

struct termio atermio,btermio;
int	fdtty = -1;		/* File descriptor for tty line */

/******************************************************************/
void mdflush() /* flushes the modem out */
{
          ioctl(fdtty, TCFLSH, 0) ;
}
/*****************************************************************/
int 
openout(ttynam,baud)/* Open the serial line for an outgoing call.*/
	char	*ttynam;
	long	baud;
{
	char	devname[MAXSIZE];
        signal(SIGINT, sigint);
        signal(SIGTERM, sigint);
 
        sprintf(devname, "/dev/%s", ttynam);
 
        if ((fdtty = open(devname, O_RDWR)) < 0)
        {
                perror(devname);
                return FAIL;
        }
        ioctl(fdtty,TCGETA,&atermio);
        btermio = atermio;
        btermio.c_iflag = btermio.c_oflag = btermio.c_lflag = 0;
        btermio.c_cc[VMIN] = 1;
        btermio.c_cc[VTIME] = 0;
        btermio.c_cflag = (btermio.c_cflag & ~CBAUD) | ( B1200 );
        ioctl(fdtty,TCSETA,&btermio);
        return SUCCESS;
}
/******************************************************************/
void
hangup()
{
	/* Restore terminal settings on dialout line */
	ioctl(fdtty, TCGETA, &atermio);
	btermio = atermio;
	btermio.c_cflag |= HUPCL;    /*  make sure modem hangs up */
        btermio.c_cflag = (btermio.c_cflag & ~CBAUD) | ( B0 );
	ioctl(fdtty, TCSETA, &btermio);
        fprintf (stdout,"HANGING UP \n");
        fflush (stdout);
	if (0 != close(fdtty)) 
	{
		perror("closing tty");
	}
	sleep(2);	/* To be sure DTR stays down that long */
}
/********************************************************************/
int
dial_nbr(nbr)
	char  *nbr;
{
   /* this routine works correctly, without any problems. */
}
/********************************************************************/
-- 
Rohit Mehrotra
Fleet Credit Corporation
8325 NW 53rd St, Miami, Fl 33166.
E-MAIL Address uunet!dmdev!rohit VOICE 1-(305)-477-0390 Ext 469



More information about the Comp.unix.wizards mailing list