Subject: [Douglas Wells on bsdi-users]: Re: ppp and port speed
To: None <netbsd-bugs@NetBSD.ORG>
From: Chris G Demetriou <Chris_G_Demetriou@BALVENIE.PDL.CS.CMU.EDU>
List: netbsd-bugs
Date: 11/16/1995 21:39:52
[ from bsdi-users, a public mailing list... ]
Somebody may want to look into fixing some of the tip aculib code, in
any case...
chris
------- Forwarded Message
16 Nov 95 21:33:24 EST
16 Nov 95 21:32:43 EST
From: Douglas Wells <dmw@contek.com>
Message-Id: <199511170112.UAA26130@buckeye.contek.com>
Subject: Re: ppp and port speed
To: web@primenet.com (Wayne Bouchard)
Date: Thu, 16 Nov 1995 20:12:39 -0500 (EST)
Cc: bsdi-users@BSDI.COM
In-Reply-To: <199511160930.CAA09918@usr3.primenet.com> from "Wayne Bouchard" at Nov 16, 95 02:30:01 am
Organization: Connection Technologies
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 9955
> Oh! Forgot to mention, I had to define the modem as a 'hayes' since the
> courier listed in the Makefile is apparently only capable of a whopping
> 2400 baud and when I get a 28800 connection, the program core dumps. ;-)
>
> Wayne Bouchard __ __ ____ ___ ___ ____
Here are my changes to fix courier.c. They are not entirely cleanup up (there
is still an assert), but they have worked very reliably for me. One big change
is that I expect to run the courier at a fixed interface speed and do *not*
alter the line speed to follow the modem's speed.
In order to use these changes, you have to define DMWCHANGES in
your ppp Makefile under CFLAGS to get the bug fixes (and a few
other changes). You can also define PPP and DEBUG in your ppp
Makefile under DRIVERDEFS to get better debugging capabilities.
Actually, I run with all the above defined, so I may not have
recently tested having only some of them defined.
- dmw
*** ORIG.courier.c Fri Feb 3 08:09:35 1995
- --- courier.c Sun Sep 17 12:58:40 1995
***************
*** 43,48 ****
- --- 43,49 ----
*/
#include "tip.h"
#include <stdio.h>
+ #include <assert.h>
#define MAXRETRY 5
***************
*** 51,56 ****
- --- 52,64 ----
static int connected = 0;
static jmp_buf timeoutbuf, intbuf;
static int coursync();
+ static int cour_read(int fd, char *cp, int n);
+ static void cour_write(int fd, const char *cp, int n);
+
+ #if defined (PPP)
+ extern int debug;
+ extern char *printable (const char *);
+ #endif /* defined (PPP) */
cour_dialer(num, acu)
register char *num;
***************
*** 62,68 ****
- --- 70,80 ----
#endif
static int cour_connect(), cour_swallow();
+ #if defined (PPP) && defined (DEBUG)
+ if (debug || boolean(value(VERBOSE)))
+ #else
if (boolean(value(VERBOSE)))
+ #endif
printf("Using \"%s\"\n", acu);
set_hupcl(FD);
***************
*** 80,94 ****
- --- 92,119 ----
cour_write(FD, "AT E0\r", 6); /* turn off echoing */
sleep(1);
#ifdef DEBUG
+ #if defined (PPP)
+ if (debug || boolean(value(VERBOSE)))
+ #else
if (boolean(value(VERBOSE)))
+ #endif
verbose_read();
#endif
tcflush(FD, TCIFLUSH); /* flush any clutter */
cour_write(FD, "AT C1 E0 H0 Q0 X6 V1\r", 21);
if (!cour_swallow("\r\nOK\r\n"))
goto badsynch;
+ #if ! defined (ORIGPPP)
+ cour_write(FD, "AT S15=8 &K3\r", 0); /* disable big buffer */
+ if (!cour_swallow("\r\nOK\r\n"))
+ goto badsynch;
+ #endif
fflush(stdout);
+ #if defined (DMWCHANGES)
+ cour_write(FD, "AT DT", 0);
+ #else
cour_write(FD, "AT D", 4);
+ #endif
for (cp = num; *cp; cp++)
if (*cp == '=')
*cp = ',';
***************
*** 103,115 ****
- --- 128,152 ----
}
#endif
if (timeout)
+ {
+ #if defined (DEBUG) && defined (PPP)
+ if (debug)
+ fprintf (stderr, "timeout occurred\n");
+ #endif /* defined (DEBUG) && defined (PPP) */
+
cour_disconnect();
+ }
return (connected);
}
cour_disconnect()
{
/* first hang up the modem*/
+ #if defined (DEBUG) && defined (PPP)
+ if (debug)
+ fprintf (stderr, "\ncour_disconnect: disconnecting\n");
+ #endif /* defined (DEBUG) && defined (PPP) */
+
ioctl(FD, TIOCCDTR, 0);
sleep(1);
ioctl(FD, TIOCSDTR, 0);
***************
*** 119,124 ****
- --- 156,165 ----
cour_abort()
{
+ #if defined (DEBUG) && defined (PPP)
+ if (debug)
+ fprintf (stderr, "\nccur_abort: aborting\n");
+ #endif /* defined (DEBUG) && defined (PPP) */
cour_write(FD, "\r", 1); /* send anything to abort the call */
cour_disconnect();
}
***************
*** 150,171 ****
return (0);
}
alarm(number(value(DIALTIMEOUT)));
! read(FD, &c, 1);
alarm(0);
c &= 0177;
#ifdef DEBUG
! if (boolean(value(VERBOSE)))
putchar(c);
#endif
} while (c == *match++);
#ifdef DEBUG
! if (boolean(value(VERBOSE)))
fflush(stdout);
#endif
signal(SIGALRM, SIG_DFL);
return (0);
}
struct baud_msg {
char *msg;
long baud;
- --- 191,213 ----
return (0);
}
alarm(number(value(DIALTIMEOUT)));
! cour_read(FD, &c, 1);
alarm(0);
c &= 0177;
#ifdef DEBUG
! if (debug)
putchar(c);
#endif
} while (c == *match++);
#ifdef DEBUG
! if (debug)
fflush(stdout);
#endif
signal(SIGALRM, SIG_DFL);
return (0);
}
+ #if ! defined (DMWCHANGES)
struct baud_msg {
char *msg;
long baud;
***************
*** 175,180 ****
- --- 217,223 ----
" 2400", B2400,
0, 0,
};
+ #endif /* DMWCHANGES */
static int
cour_connect()
***************
*** 183,189 ****
- --- 226,234 ----
int nc, nl, n;
struct termios sb;
char dialer_buf[64];
+ #if ! defined (DMWCHANGES)
struct baud_msg *bm;
+ #endif
sig_t f;
if (cour_swallow("\r\n") == 0)
***************
*** 197,203 ****
if (setjmp(timeoutbuf))
break;
alarm(number(value(DIALTIMEOUT)));
! n = read(FD, &c, 1);
alarm(0);
if (n <= 0)
break;
- --- 242,248 ----
if (setjmp(timeoutbuf))
break;
alarm(number(value(DIALTIMEOUT)));
! n = cour_read(FD, &c, 1);
alarm(0);
if (n <= 0)
break;
***************
*** 207,222 ****
break;
if (!dialer_buf[0])
goto again;
if (strcmp(dialer_buf, "RINGING") == 0 &&
boolean(value(VERBOSE))) {
#ifdef DEBUG
! printf("%s\r\n", dialer_buf);
#endif
goto again;
}
if (strncmp(dialer_buf, "CONNECT",
sizeof("CONNECT")-1) != 0)
break;
for (bm = baud_msg ; bm ; bm++)
if (strcmp(bm->msg,
dialer_buf+sizeof("CONNECT")-1) == 0) {
- --- 252,287 ----
break;
if (!dialer_buf[0])
goto again;
+ #if defined (DMWCHANGES)
+ # ifdef DEBUG
+ if (debug || boolean(value(VERBOSE)))
+ #else
+ if (boolean(value(VERBOSE)))
+ #endif
+ {
+ printf("%s\r\n", dialer_buf);
+ }
+ if (strcmp(dialer_buf, "RINGING") == 0)
+ goto again;
+ #else /* defined (DMWCHANGES) */
if (strcmp(dialer_buf, "RINGING") == 0 &&
boolean(value(VERBOSE))) {
#ifdef DEBUG
! if (debug)
! printf("%s\r\n", dialer_buf);
#endif
goto again;
}
+ #endif /* defined (DMWCHANGES) */
if (strncmp(dialer_buf, "CONNECT",
sizeof("CONNECT")-1) != 0)
break;
+ #if defined (DMWCHANGES) /* we run fixed speed */
+ tcgetattr(FD, &sb);
+ sb.c_cflag |= CCTS_OFLOW | CRTS_IFLOW;
+ tcsetattr(FD, TCSAFLUSH, &sb);
+ return 1;
+ #else
for (bm = baud_msg ; bm ; bm++)
if (strcmp(bm->msg,
dialer_buf+sizeof("CONNECT")-1) == 0) {
***************
*** 225,235 ****
- --- 290,305 ----
tcsetattr(FD, TCSAFLUSH, &sb);
signal(SIGALRM, f);
#ifdef DEBUG
+ #if defined (PPP)
+ if (debug || boolean(value(VERBOSE)))
+ #else
if (boolean(value(VERBOSE)))
+ #endif /* defined (PPP) */
printf("%s\r\n", dialer_buf);
#endif
return (1);
}
+ #endif /* defined (DMWCHANGES) */
break;
}
dialer_buf[nc] = c;
***************
*** 263,272 ****
sleep(1);
ioctl(FD, FIONREAD, &len);
if (len) {
! len = read(FD, buf, sizeof(buf));
#ifdef DEBUG
buf[len] = '\0';
! printf("coursync: (\"%s\")\n\r", buf);
#endif
if (index(buf, '0') ||
(index(buf, 'O') && index(buf, 'K')))
- --- 333,345 ----
sleep(1);
ioctl(FD, FIONREAD, &len);
if (len) {
! len = cour_read(FD, buf, sizeof(buf));
#ifdef DEBUG
buf[len] = '\0';
! #if defined (PPP)
! if (debug)
! #endif
! printf("coursync: (\"%s\")\n\r", buf);
#endif
if (index(buf, '0') ||
(index(buf, 'O') && index(buf, 'K')))
***************
*** 291,314 ****
return (0);
}
! cour_write(fd, cp, n)
! int fd;
! char *cp;
! int n;
{
#ifdef notdef
if (boolean(value(VERBOSE)))
write(1, cp, n);
#endif
tcflush(fd, TCIOFLUSH);
cour_nap();
for ( ; n-- ; cp++) {
! write(fd, cp, 1);
tcflush(fd, TCIOFLUSH);
cour_nap();
}
}
#ifdef DEBUG
verbose_read()
{
- --- 364,410 ----
return (0);
}
! static void
! cour_write(int fd, const char *cp, int n)
{
#ifdef notdef
if (boolean(value(VERBOSE)))
write(1, cp, n);
#endif
+ #if defined (PPP) && defined (DEBUG)
+ if (n == 0)
+ n = strlen (cp);
+ else assert (strlen (cp) == n);
+ if (debug)
+ fprintf (stderr, "writing: %s\n", printable (cp));
+ #endif /* defined (PPP) && defined (DEBUG) */
+
tcflush(fd, TCIOFLUSH);
cour_nap();
for ( ; n-- ; cp++) {
! write(fd, (const void *) cp, (size_t) 1);
tcflush(fd, TCIOFLUSH);
cour_nap();
}
}
+ static int
+ cour_read(int fd, char *cp, int n)
+ {
+ #if defined (PPP) && defined (DEBUG)
+ int result;
+ result = read(fd, cp, n);
+ if (result < 0)
+ return result;
+ cp [result] = '\0';
+ if (debug)
+ fprintf (stderr, "read %s, ", printable (cp));
+ return result;
+ #else
+ return read(fd, cp, n);
+ #endif /* defined (PPP) && defined (DEBUG) */
+ }
+
#ifdef DEBUG
verbose_read()
{
***************
*** 319,325 ****
return;
if (n <= 0)
return;
! if (read(FD, buf, n) != n)
return;
write(1, buf, n);
}
- --- 415,421 ----
return;
if (n <= 0)
return;
! if (cour_read(FD, buf, n) != n)
return;
write(1, buf, n);
}
***************
*** 338,344 ****
cour_nap()
{
!
static void cour_napx();
int omask;
struct itimerval itv, oitv;
- --- 434,443 ----
cour_nap()
{
!
! #if defined (DMWCHANGES)
! usleep (napms * 1000);
! #else
static void cour_napx();
int omask;
struct itimerval itv, oitv;
***************
*** 362,367 ****
- --- 461,467 ----
(void) sigvec(SIGALRM, &ovec, (struct sigvec *)0);
(void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0);
(void) sigsetmask(omask);
+ #endif /* DMWCHANGES */
}
static void
- --
Douglas M. Wells Internet: dmw@contek.com
Connection Technologies UUCP: ...!uunet!mv!contek!dmw
Voice: +1 508 456 3480 Fax: +1 508 456 8621
------- End of Forwarded Message