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); }
void multitech_disconnect () { int okay, retries; for (retries = okay = 0; retries < 3 && !okay; retries++) { /* first hang up the modem*/ ioctl (FD, TIOCCDTR, 0); acu_nap (escape_guard_time); ioctl (FD, TIOCSDTR, 0); acu_nap (escape_guard_time); /* * If not strapped for DTR control, try to get command mode. */ acu_nap (escape_guard_time); multitech_write_str (FD, escape_sequence); acu_nap (escape_guard_time); multitech_write_str (FD, hangup_command); okay = multitech_swallow ("\r\nOK\r\n"); } if (!okay) { #if ACULOG logent(value(HOST), "", "multitech", "can't hang up modem"); #endif if (boolean(value(VERBOSE))) printf("hang up failed\n"); } close (FD); }
static void unidialer_write (int fd, const char *cp, int n) { acu_nap (intercharacter_delay); for ( ; n-- ; cp++) { write (fd, cp, 1); acu_nap (intercharacter_delay); } }
void multitech_write (int fd, const char *cp, int n) { acu_flush (); acu_nap (intercharacter_delay); for ( ; n-- ; cp++) { write (fd, cp, 1); acu_flush (); acu_nap (intercharacter_delay); } }
/* Send commands to modem; impose delay between commands. */ static void unidialer_modem_cmd (int fd, const char *cmd) { static struct timeval oldt = { 0, 0 }; struct timeval newt; tod_gettime (&newt); if (tod_lt (&newt, &oldt)) { unsigned int naptime; tod_subfrom (&oldt, newt); naptime = oldt.tv_sec * 1000 + oldt.tv_usec / 1000; if (naptime > intercommand_delay) { #ifdef DEBUG printf ("unidialer_modem_cmd: suspicious naptime (%u ms)\r\n", naptime); #endif naptime = intercommand_delay; } #ifdef DEBUG printf ("unidialer_modem_cmd: delaying %u ms\r\n", naptime); #endif acu_nap (naptime); } unidialer_write_str (fd, cmd); tod_gettime (&oldt); newt.tv_sec = 0; newt.tv_usec = intercommand_delay; tod_addto (&oldt, &newt); }
static int unidialer_waitfor_modem_ready (int ms) { #ifdef TIOCMGET int count; for (count = 0; count < ms; count += 100) { if (unidialer_modem_ready ()) { #ifdef DEBUG printf ("unidialer_waitfor_modem_ready: modem ready.\n"); #endif break; } acu_nap (100); } return (count < ms); #else acu_nap (250); return (1); #endif }
/* * This convoluted piece of code attempts to get * the unidialer in sync. */ static int unidialersync(void) { int already = 0; int len; char buf[40]; while (already++ < MAXRETRY) { acu_nap (intercommand_delay); acu_flush (); /* flush any clutter */ unidialer_write_str (FD, reset_command); /* reset modem */ bzero(buf, sizeof(buf)); acu_nap (reset_delay); ioctl (FD, FIONREAD, &len); if (len) { len = read(FD, buf, sizeof(buf)); #ifdef DEBUG buf [len] = '\0'; printf("unidialersync (%s): (\"%s\")\n\r", modem_name, buf); #endif if (index(buf, '0') || (index(buf, 'O') && index(buf, 'K'))) return(1); } /* * If not strapped for DTR control, * try to get command mode. */ acu_nap (escape_guard_time); unidialer_write_str (FD, escape_sequence); acu_nap (escape_guard_time); unidialer_write_str (FD, hangup_command); /* * Toggle DTR to force anyone off that might have left * the modem connected. */ acu_nap (escape_guard_time); ioctl (FD, TIOCCDTR, 0); acu_nap (1000); ioctl (FD, TIOCSDTR, 0); } acu_nap (intercommand_delay); unidialer_write_str (FD, reset_command); return (0); }
int multitech_dialer (char *num, char *acu) { char *cp; #if ACULOG char line [80]; #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 (!multitechsync()) { badsynch: printf("can't synchronize with multitech\n"); #if ACULOG logent(value(HOST), num, "multitech", "can't synch up"); #endif return (0); } acu_nap (intercommand_delay); multitech_write_str (FD, echo_off_command); /* turn off echoing */ sleep(1); #ifdef DEBUG if (boolean(value(VERBOSE))) multitech_verbose_read(); #endif acu_flush (); acu_nap (intercommand_delay); multitech_write_str (FD, init_string); if (!multitech_swallow ("\r\nOK\r\n")) goto badsynch; fflush (stdout); acu_nap (intercommand_delay); multitech_write_str (FD, dial_command); for (cp = num; *cp; cp++) if (*cp == '=') *cp = ','; multitech_write_str (FD, num); multitech_write_str (FD, "\r"); connected = multitech_connect(); #if ACULOG if (timeout) { sprintf(line, "%d second dial timeout", number(value(DIALTIMEOUT))); logent(value(HOST), num, "multitech", line); } #endif if (timeout) multitech_disconnect (); return (connected); }