From 17e762ca3d7f0a25ab58077cbb482c1659bf46f8 Mon Sep 17 00:00:00 2001
From: "Jordan K. Hubbard" <jkh@FreeBSD.org>
Date: Sun, 22 Dec 1996 17:09:17 +0000
Subject: [PATCH] Make CRTSTS selection a runtime option.  Closes PR#1392
 Submitted by:	Mike McGaughey <mmcg@heraclitus.cs.monash.edu.au>

---
 usr.sbin/ppp/command.c | 21 ++++++++++++++++++++-
 usr.sbin/ppp/defs.h    |  3 ++-
 usr.sbin/ppp/modem.c   | 34 ++++++++++++++++++----------------
 usr.sbin/ppp/ppp.8     | 18 +++++++++++++++---
 usr.sbin/ppp/ppp.8.m4  | 18 +++++++++++++++---
 usr.sbin/ppp/vars.c    |  6 +++---
 usr.sbin/ppp/vars.h    |  4 +++-
 7 files changed, 76 insertions(+), 28 deletions(-)

diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index 870ef4473031..bf40cb34a121 100644
--- a/usr.sbin/ppp/command.c
+++ b/usr.sbin/ppp/command.c
@@ -17,7 +17,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: command.c,v 1.24 1996/10/13 15:05:14 sos Exp $
+ * $Id: command.c,v 1.25 1996/12/03 21:38:39 nate Exp $
  *
  */
 #include <sys/types.h>
@@ -949,6 +949,23 @@ int param;
   return(1);
 }
 
+static int SetCtsRts(list, argc, argv)
+struct cmdtab *list;
+int argc;
+char **argv;
+{
+  if (argc > 0) {
+    if (strcmp(*argv, "on") == 0)
+      VarCtsRts = TRUE;
+    else if (strcmp(*argv, "off") == 0)
+      VarCtsRts = FALSE;
+    else
+      printf("usage: set ctsrts [on|off].\n");
+  }
+  return(1);
+}
+
+
 static int SetOpenMode(list, argc, argv)
 struct cmdtab *list;
 int argc;
@@ -979,6 +996,8 @@ struct cmdtab const SetCommands[] = {
 	"Set authentication key", "key", (void *)VAR_AUTHKEY},
   { "authname", NULL,     SetVariable,		LOCAL_AUTH,
 	"Set authentication name", "name", (void *)VAR_AUTHNAME},
+  { "ctsrts", NULL,	  SetCtsRts,		LOCAL_AUTH,
+	"Use CTS/RTS modem signalling", "[on|off]"},
   { "debug",    NULL,	  SetDebugLevel,	LOCAL_AUTH,
 	"Set debug level", StrValue},
   { "device",     "line", SetVariable, 		LOCAL_AUTH,
diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h
index 898ec195f3a3..3b690ffea332 100644
--- a/usr.sbin/ppp/defs.h
+++ b/usr.sbin/ppp/defs.h
@@ -15,7 +15,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: defs.h,v 1.5 1996/12/03 21:38:42 nate Exp $
+ * $Id: defs.h,v 1.6 1996/12/12 14:39:39 jkh Exp $
  *
  *	TODO:
  */
@@ -45,6 +45,7 @@
 #define MODEM_SPEED	B38400			/* tty speed */
 #define	SERVER_PORT	3000			/* Base server port no. */
 
+#define	MODEM_CTSRTS	TRUE		/* Default (true): use CTS/RTS signals */
 #define	REDIAL_PERIOD	30			/* Default Hold time to redial */
 
 #define	CONFFILE 	"ppp.conf"
diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c
index 3caa566e3a85..b0e0f71cf91b 100644
--- a/usr.sbin/ppp/modem.c
+++ b/usr.sbin/ppp/modem.c
@@ -17,7 +17,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: modem.c,v 1.23 1996/03/29 15:24:04 ache Exp $
+ * $Id: modem.c,v 1.24 1996/05/11 20:48:36 phk Exp $
  *
  *  TODO:
  */
@@ -39,7 +39,6 @@
 #define O_NONBLOCK O_NDELAY
 #endif
 #endif
-#define USE_CTSRTS
 
 extern int DoChat();
 
@@ -448,12 +447,12 @@ int mode;
     rstio.c_iflag, rstio.c_oflag, rstio.c_cflag);
 #endif
     cfmakeraw(&rstio);
-#ifdef USE_CTSRTS
-    rstio.c_cflag |= CLOCAL | CCTS_OFLOW|CRTS_IFLOW;
-#else
-    rstio.c_cflag |= CLOCAL;
-    rstio.c_iflag |= IXOFF;
-#endif
+    if (VarCtsRts)
+	rstio.c_cflag |= CLOCAL | CCTS_OFLOW|CRTS_IFLOW;
+    else {
+	rstio.c_cflag |= CLOCAL;
+	rstio.c_iflag |= IXOFF;
+    }
     rstio.c_iflag |= IXON;
     if (!(mode & MODE_DEDICATED))
       rstio.c_cflag |= HUPCL;
@@ -516,11 +515,11 @@ int modem;
   }
   tcgetattr(modem, &rstio);
   cfmakeraw(&rstio);
-#ifdef USE_CTSRTS
-    rstio.c_cflag |= CLOCAL | CCTS_OFLOW|CRTS_IFLOW;
-#else
-    rstio.c_cflag |= CLOCAL;
-#endif
+  if (VarCtsRts)
+      rstio.c_cflag |= CLOCAL | CCTS_OFLOW|CRTS_IFLOW;
+  else
+      rstio.c_cflag |= CLOCAL;
+
   if (!(mode & MODE_DEDICATED))
     rstio.c_cflag |= HUPCL;
   tcsetattr(modem, TCSADRAIN, &rstio);
@@ -772,11 +771,14 @@ ShowModemStatus()
   }
   if (VarParity & PARENB) {
     if (VarParity & PARODD)
-      printf("odd parity\n");
+      printf("odd parity, ");
     else
-      printf("even parity\n");
+      printf("even parity, ");
   } else
-    printf("none parity\n");
+    printf("no parity, ");
+
+  printf("CTS/RTS %s.\n", (VarCtsRts? "on" : "off"));
+
 #ifdef DEBUG
   printf("fd = %d, modem control = %o\n", modem, mbits);
 #endif
diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8
index 7a4227bea0e6..929d3835adcb 100644
--- a/usr.sbin/ppp/ppp.8
+++ b/usr.sbin/ppp/ppp.8
@@ -1,5 +1,5 @@
 .\" manual page [] for ppp 0.94 beta2 + alpha
-.\" $Id: ppp.8,v 1.20 1996/12/03 21:38:52 nate Exp $
+.\" $Id: ppp.8,v 1.21 1996/12/12 14:39:47 jkh Exp $
 .Dd 20 September 1995
 .Os FreeBSD
 .Dt PPP 8
@@ -172,8 +172,18 @@ ppp on tama> pass <password>
 
 ppp ON tama>
 
-* You can specify the device name and speed for your modem using the
-following commands: *
+* You can now specify the device name, speed and parity
+for your modem, and whether
+CTS/RTS signalling should be used (CTS/RTS is used by default).
+If your hardware does not provide CTS/RTS lines (as
+may happen when you are connected directly to certain ppp-capable
+terminal servers),
+.Nm
+will never send any output through the port; it
+waits for a signal which never comes.
+Thus, if you have a direct line and can't seem to make
+a connection, try turning ctsrts off: *
+
 
 ppp ON tama> set line /dev/cuaa0
 
@@ -181,6 +191,8 @@ ppp ON tama> set speed 38400
 
 ppp ON tama> set parity even
 
+ppp ON tama> set ctsrts on
+
 ppp ON tama> show modem
 
 * Modem related parameters are shown in here *
diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4
index 7a4227bea0e6..929d3835adcb 100644
--- a/usr.sbin/ppp/ppp.8.m4
+++ b/usr.sbin/ppp/ppp.8.m4
@@ -1,5 +1,5 @@
 .\" manual page [] for ppp 0.94 beta2 + alpha
-.\" $Id: ppp.8,v 1.20 1996/12/03 21:38:52 nate Exp $
+.\" $Id: ppp.8,v 1.21 1996/12/12 14:39:47 jkh Exp $
 .Dd 20 September 1995
 .Os FreeBSD
 .Dt PPP 8
@@ -172,8 +172,18 @@ ppp on tama> pass <password>
 
 ppp ON tama>
 
-* You can specify the device name and speed for your modem using the
-following commands: *
+* You can now specify the device name, speed and parity
+for your modem, and whether
+CTS/RTS signalling should be used (CTS/RTS is used by default).
+If your hardware does not provide CTS/RTS lines (as
+may happen when you are connected directly to certain ppp-capable
+terminal servers),
+.Nm
+will never send any output through the port; it
+waits for a signal which never comes.
+Thus, if you have a direct line and can't seem to make
+a connection, try turning ctsrts off: *
+
 
 ppp ON tama> set line /dev/cuaa0
 
@@ -181,6 +191,8 @@ ppp ON tama> set speed 38400
 
 ppp ON tama> set parity even
 
+ppp ON tama> set ctsrts on
+
 ppp ON tama> show modem
 
 * Modem related parameters are shown in here *
diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c
index f19683f0d14e..ec8500e34532 100644
--- a/usr.sbin/ppp/vars.c
+++ b/usr.sbin/ppp/vars.c
@@ -17,7 +17,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: vars.c,v 1.8 1996/10/06 13:32:36 jkh Exp $
+ * $Id: vars.c,v 1.9 1996/10/06 19:39:08 jkh Exp $
  *
  */
 #include "fsm.h"
@@ -29,7 +29,7 @@
 #include "defs.h"
 
 char VarVersion[] = "Version 0.94";
-char VarLocalVersion[] = "$Date: 1996/10/06 13:32:36 $";
+char VarLocalVersion[] = "$Date: 1996/10/06 19:39:08 $";
 
 /*
  * Order of conf option is important. See vars.h.
@@ -49,7 +49,7 @@ struct confdesc pppConfs[] = {
 };
 
 struct pppvars pppVars = {
-  DEF_MRU, 0, MODEM_SPEED, CS8, 180, 30, 3,
+  DEF_MRU, 0, MODEM_SPEED, CS8, MODEM_CTSRTS, 180, 30, 3,
   REDIAL_PERIOD, 1, MODEM_DEV, OPEN_PASSIVE, LOCAL_NO_AUTH,
 };
 
diff --git a/usr.sbin/ppp/vars.h b/usr.sbin/ppp/vars.h
index ef1dc98de287..e9354dcce8f5 100644
--- a/usr.sbin/ppp/vars.h
+++ b/usr.sbin/ppp/vars.h
@@ -15,7 +15,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: vars.h,v 1.6 1996/03/08 13:22:23 ache Exp $
+ * $Id: vars.h,v 1.7 1996/10/06 13:32:37 jkh Exp $
  *
  *	TODO:
  */
@@ -58,6 +58,7 @@ struct pppvars {
   int    var_accmap;		/* Initial ACCMAP value */
   int    modem_speed;		/* Current modem speed */
   int    modem_parity;		/* Parity setting */
+  int    modem_ctsrts;		/* Use CTS/RTS on modem port? (boolean) */
   int    idle_timeout;		/* Idle timeout value */
   int	 lqr_timeout;		/* LQR timeout value */
   int    retry_timeout;		/* Retry timeout value */
@@ -85,6 +86,7 @@ struct pppvars {
 #define	VarDevice	pppVars.modem_dev
 #define	VarSpeed	pppVars.modem_speed
 #define	VarParity	pppVars.modem_parity
+#define	VarCtsRts	pppVars.modem_ctsrts
 #define	VarOpenMode	pppVars.open_mode
 #define	VarLocalAuth	pppVars.lauth
 #define	VarDialScript	pppVars.dial_script