Пример #1
0
static void
unidialer_disconnect(void)
{
	int okay, retries;

	acu_flush (); /* flush any clutter */

	unidialer_tty_clocal (TRUE);

 	/* first hang up the modem*/
	ioctl (FD, TIOCCDTR, 0);
	acu_nap (250);
	ioctl (FD, TIOCSDTR, 0);

	/*
	 * If AT&D2, then dropping DTR *should* just hangup the modem. But
	 * some modems reset anyway; also, the modem may be programmed to reset
	 * anyway with AT&D3. Play it safe and wait for the full reset time before
	 * proceeding.
	 */
	acu_nap (reset_delay);

	if (!unidialer_waitfor_modem_ready (reset_delay))
	{
#ifdef DEBUG
			printf ("unidialer_disconnect: warning CTS low.\r\n");
#endif
	}

	/*
	 * If not strapped for DTR control, try to get command mode.
	 */
	for (retries = okay = 0; retries < MAXRETRY && !okay; retries++)
	{
		int timeout_value;
		/* flush any clutter */
		if (!acu_flush ())
		{
#ifdef DEBUG
			printf ("unidialer_disconnect: warning flush failed.\r\n");
#endif
		}
		timeout_value = escape_guard_time;
		timeout_value += (timeout_value * retries / MAXRETRY);
		acu_nap (timeout_value);
		acu_flush (); /* flush any clutter */
		unidialer_modem_cmd (FD, escape_sequence);
		acu_nap (timeout_value);
		unidialer_modem_cmd (FD, hangup_command);
		okay = unidialer_get_okay (reset_delay);
	}
	if (!okay)
	{
		logent(value(HOST), "", modem_name, "can't hang up modem");
		if (boolean(value(VERBOSE)))
			printf("hang up failed\n");
	}
	(void) acu_flush ();
	close (FD);
}
Пример #2
0
static int
unidialer_dialer(char *num, char *acu)
{
	char *cp;
	char dial_string [80];
#if ACULOG
	char line [80];
#endif

	#ifdef DEBUG
	dumpmodemparms (modem_name);
	#endif

	if (lock_baud) {
		int i;
		if ((i = speed(number(value(BAUDRATE)))) == 0)
			return 0;
		ttysetup (i);
	}

	if (boolean(value(VERBOSE)))
		printf("Using \"%s\"\n", acu);

	acu_hupcl ();

	/*
	 * Get in synch.
	 */
	if (!unidialersync()) {
badsynch:
		printf("tip: can't synchronize with %s\n", modem_name);
#if ACULOG
		logent(value(HOST), num, modem_name, "can't synch up");
#endif
		return (0);
	}

	unidialer_modem_cmd (FD, echo_off_command);	/* turn off echoing */

	sleep(1);

#ifdef DEBUG
	if (boolean(value(VERBOSE)))
		unidialer_verbose_read();
#endif

	acu_flush (); /* flush any clutter */

	unidialer_modem_cmd (FD, init_string);

	if (!unidialer_get_okay (reset_delay))
		goto badsynch;

	fflush (stdout);

	for (cp = num; *cp; cp++)
		if (*cp == '=')
			*cp = ',';

	(void) sprintf (dial_string, dial_command, num);

	unidialer_modem_cmd (FD, dial_string);

	connected = unidialer_connect ();

	if (connected && hw_flow_control) {
		acu_hw_flow_control (hw_flow_control);
	}

#if ACULOG
	if (timeout) {
		sprintf(line, "%d second dial timeout",
			number(value(DIALTIMEOUT)));
		logent(value(HOST), num, modem_name, line);
	}
#endif

	if (timeout)
		unidialer_disconnect ();

	return (connected);
}