summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/tty.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1999-08-06 20:04:08 +0000
committerbrian <brian@FreeBSD.org>1999-08-06 20:04:08 +0000
commit8229df47c3e2374322058e43333045e6fe030427 (patch)
tree0dcd97a0d9e4b6f52cd1f2aa158c28fca4e9e808 /usr.sbin/ppp/tty.c
parent82b15b21003b7e5df8e9a7bae9330508378a0ee8 (diff)
downloadFreeBSD-src-8229df47c3e2374322058e43333045e6fe030427.zip
FreeBSD-src-8229df47c3e2374322058e43333045e6fe030427.tar.gz
Add ISDN support via isdnd & i4b. This requires version
0.81.1 of the i4b code - namely support of the I4B_VR_REQ ioctl via the i4brbchX device. Ppp controls the phone number, but idle timers and SYNC/RAW decisions are still made by isdnd (in isdnd.rc). This involves a new datalink state machine phase. The ``wait for carrier'' phase happens after dialing but before logging in. The whole dial state should really be abstracted so that each device type can deal with it in its own way (thinking about PPPoE) - but that'll have to wait. The ``set cd'' symantics remain the same for tty devices, but we now delay until we either get CD or timeout waiting (at which time we drop the link if we require CD). For i4b devices we always insist on carrier. Thanks to hm@ for his help, and especially for pointing out that I *don't* need to re-implement isdnd (that was a huge waste of time !) :-]
Diffstat (limited to 'usr.sbin/ppp/tty.c')
-rw-r--r--usr.sbin/ppp/tty.c139
1 files changed, 63 insertions, 76 deletions
diff --git a/usr.sbin/ppp/tty.c b/usr.sbin/ppp/tty.c
index 72b3bae..4cf7192 100644
--- a/usr.sbin/ppp/tty.c
+++ b/usr.sbin/ppp/tty.c
@@ -23,32 +23,20 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: tty.c,v 1.8 1999/05/27 08:42:49 brian Exp $
+ * $Id: tty.c,v 1.9 1999/06/05 21:35:57 brian Exp $
*/
#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
#include <sys/un.h>
#if defined(__OpenBSD__) || defined(__NetBSD__)
#include <sys/ioctl.h>
-#include <util.h>
-#else
-#include <libutil.h>
#endif
#include <errno.h>
#include <fcntl.h>
-#include <paths.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
-#include <sys/wait.h>
#include <sys/uio.h>
#include <termios.h>
#include <unistd.h>
@@ -57,8 +45,6 @@
#include "defs.h"
#include "mbuf.h"
#include "log.h"
-#include "id.h"
-#include "sync.h"
#include "timer.h"
#include "lqr.h"
#include "hdlc.h"
@@ -68,20 +54,10 @@
#include "ccp.h"
#include "link.h"
#include "async.h"
-#include "slcompress.h"
-#include "iplist.h"
-#include "ipcp.h"
-#include "filter.h"
#include "descriptor.h"
#include "physical.h"
#include "mp.h"
-#ifndef NORADIUS
-#include "radius.h"
-#endif
#include "chat.h"
-#include "command.h"
-#include "bundle.h"
-#include "prompt.h"
#include "auth.h"
#include "chap.h"
#include "cbcp.h"
@@ -95,6 +71,7 @@ struct ttydevice {
struct device dev; /* What struct physical knows about */
struct pppTimer Timer; /* CD checks */
int mbits; /* Current DCD status */
+ int carrier_seconds; /* seconds before CD is *required* */
struct termios ios; /* To be able to reset from raw mode */
};
@@ -124,9 +101,9 @@ tty_Timeout(void *data)
if (p->fd >= 0) {
if (ioctl(p->fd, TIOCMGET, &dev->mbits) < 0) {
- log_Printf(LogPHASE, "%s: ioctl error (%s)!\n", p->link.name,
+ /* we must be a pty ? */
+ log_Printf(LogDEBUG, "%s: ioctl error (%s)!\n", p->link.name,
strerror(errno));
- datalink_Down(p->dl, CLOSE_NORMAL);
timer_Stop(&dev->Timer);
return;
}
@@ -136,16 +113,24 @@ tty_Timeout(void *data)
if (ombits == -1) {
/* First time looking for carrier */
if (Online(dev))
- log_Printf(LogDEBUG, "%s: %s: CD detected\n", p->link.name, p->name.full);
- else if (p->cfg.cd.required) {
- log_Printf(LogPHASE, "%s: %s: Required CD not detected\n",
- p->link.name, p->name.full);
- datalink_Down(p->dl, CLOSE_NORMAL);
- } else {
- log_Printf(LogPHASE, "%s: %s doesn't support CD\n",
- p->link.name, p->name.full);
+ log_Printf(LogPHASE, "%s: %s: CD detected\n", p->link.name, p->name.full);
+ else if (++dev->carrier_seconds >= p->cfg.cd.delay) {
+ if (p->cfg.cd.required)
+ log_Printf(LogPHASE, "%s: %s: Required CD not detected\n",
+ p->link.name, p->name.full);
+ else {
+ log_Printf(LogPHASE, "%s: %s doesn't support CD\n",
+ p->link.name, p->name.full);
+ dev->mbits = TIOCM_CD; /* Dodgy null-modem cable ? */
+ }
timer_Stop(&dev->Timer);
- dev->mbits = TIOCM_CD;
+ /* tty_AwaitCarrier() will notice */
+ } else {
+ /* Keep waiting */
+ log_Printf(LogDEBUG, "%s: %s: Still no carrier (%d/%d)\n",
+ p->link.name, p->name.full, dev->carrier_seconds,
+ p->cfg.cd.delay);
+ dev->mbits = -1;
}
} else {
change = ombits ^ dev->mbits;
@@ -170,52 +155,66 @@ tty_StartTimer(struct physical *p)
struct ttydevice *dev = device2tty(p->handler);
timer_Stop(&dev->Timer);
- dev->Timer.load = SECTICKS * p->cfg.cd.delay;
+ dev->Timer.load = SECTICKS;
dev->Timer.func = tty_Timeout;
dev->Timer.name = "tty CD";
dev->Timer.arg = p;
log_Printf(LogDEBUG, "%s: Using tty_Timeout [%p]\n",
p->link.name, tty_Timeout);
- dev->mbits = -1; /* So we know it's the first time */
timer_Start(&dev->Timer);
}
static int
+tty_AwaitCarrier(struct physical *p)
+{
+ struct ttydevice *dev = device2tty(p->handler);
+
+ if (physical_IsSync(p))
+ return CARRIER_OK;
+
+ if (dev->mbits == -1) {
+ if (dev->Timer.state == TIMER_STOPPED) {
+ dev->carrier_seconds = 0;
+ tty_StartTimer(p);
+ }
+ return CARRIER_PENDING; /* Not yet ! */
+ }
+
+ return Online(dev) || !p->cfg.cd.required ? CARRIER_OK : CARRIER_LOST;
+}
+
+static int
tty_Raw(struct physical *p)
{
struct ttydevice *dev = device2tty(p->handler);
struct termios ios;
int oldflag;
- if (physical_IsSync(p))
- return 1;
-
- log_Printf(LogDEBUG, "%s: Entering physical_Raw\n", p->link.name);
+ log_Printf(LogDEBUG, "%s: Entering tty_Raw\n", p->link.name);
if (p->type != PHYS_DIRECT && p->fd >= 0 && !Online(dev))
log_Printf(LogDEBUG, "%s: Raw: descriptor = %d, mbits = %x\n",
p->link.name, p->fd, dev->mbits);
- tcgetattr(p->fd, &ios);
- cfmakeraw(&ios);
- if (p->cfg.rts_cts)
- ios.c_cflag |= CLOCAL | CCTS_OFLOW | CRTS_IFLOW;
- else
- ios.c_cflag |= CLOCAL;
+ if (!physical_IsSync(p)) {
+ tcgetattr(p->fd, &ios);
+ cfmakeraw(&ios);
+ if (p->cfg.rts_cts)
+ ios.c_cflag |= CLOCAL | CCTS_OFLOW | CRTS_IFLOW;
+ else
+ ios.c_cflag |= CLOCAL;
- if (p->type != PHYS_DEDICATED)
- ios.c_cflag |= HUPCL;
+ if (p->type != PHYS_DEDICATED)
+ ios.c_cflag |= HUPCL;
- tcsetattr(p->fd, TCSANOW, &ios);
+ tcsetattr(p->fd, TCSANOW, &ios);
+ }
oldflag = fcntl(p->fd, F_GETFL, 0);
if (oldflag < 0)
return 0;
fcntl(p->fd, F_SETFL, oldflag | O_NONBLOCK);
- if (ioctl(p->fd, TIOCMGET, &dev->mbits) == 0)
- tty_StartTimer(p);
-
return 1;
}
@@ -226,7 +225,7 @@ tty_Offline(struct physical *p)
if (p->fd >= 0) {
timer_Stop(&dev->Timer);
- dev->mbits &= ~TIOCM_DTR;
+ dev->mbits &= ~TIOCM_DTR; /* XXX: Hmm, what's this supposed to do ? */
if (Online(dev)) {
struct termios tio;
@@ -249,12 +248,12 @@ tty_Cooked(struct physical *p)
tty_Offline(p); /* In case of emergency close()s */
tcflush(p->fd, TCIOFLUSH);
- if (!physical_IsSync(p)) {
+
+ if (!physical_IsSync(p))
tcsetattr(p->fd, TCSAFLUSH, &dev->ios);
- oldflag = fcntl(p->fd, F_GETFL, 0);
- if (oldflag == 0)
- fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK);
- }
+
+ if ((oldflag = fcntl(p->fd, F_GETFL, 0)) != -1)
+ fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK);
}
static void
@@ -296,6 +295,7 @@ tty_OpenInfo(struct physical *p)
else
strcpy(buf, "no");
strcat(buf, " carrier");
+
return buf;
}
@@ -323,6 +323,7 @@ tty_device2iov(struct device *d, struct iovec *iov, int *niov,
static struct device basettydevice = {
TTY_DEVICE,
"tty",
+ tty_AwaitCarrier,
tty_Raw,
tty_Offline,
tty_Cooked,
@@ -393,6 +394,7 @@ tty_Create(struct physical *p)
memcpy(&dev->dev, &basettydevice, sizeof dev->dev);
memset(&dev->Timer, '\0', sizeof dev->Timer);
+ dev->mbits = -1;
tcgetattr(p->fd, &ios);
dev->ios = ios;
@@ -424,22 +426,6 @@ tty_Create(struct physical *p)
"cflag = %lx\n", p->link.name, (u_long)ios.c_iflag,
(u_long)ios.c_oflag, (u_long)ios.c_cflag);
- if (ioctl(p->fd, TIOCMGET, &dev->mbits) == -1) {
- if (p->type != PHYS_DIRECT) {
- /* Complete failure - parent doesn't continue trying to ``create'' */
-
- log_Printf(LogWARN, "%s: Open: Cannot get physical status: %s\n",
- p->link.name, strerror(errno));
- tty_Cooked(p);
- close(p->fd);
- p->fd = -1;
- return NULL;
- } else
- dev->mbits = TIOCM_CD;
- }
- log_Printf(LogDEBUG, "%s: Open: physical control = %o\n",
- p->link.name, dev->mbits);
-
oldflag = fcntl(p->fd, F_GETFL, 0);
if (oldflag < 0) {
/* Complete failure - parent doesn't continue trying to ``create'' */
@@ -449,6 +435,7 @@ tty_Create(struct physical *p)
tty_Cooked(p);
close(p->fd);
p->fd = -1;
+ free(dev);
return NULL;
} else
fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK);
OpenPOWER on IntegriCloud