]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-ultrix.c
don't need to be group kmem any more
[ppp.git] / pppd / sys-ultrix.c
index ca8f2a4a187532eac34ffebcc9659cf95fa58b81..cad794b5e50fc43a9657e10c6dbe62480c9f407a 100644 (file)
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-ultrix.c,v 1.4 1994/05/25 06:30:49 paulus Exp $";
+static char rcsid[] = "$Id: sys-ultrix.c,v 1.5 1994/09/01 00:39:09 paulus Exp $";
 #endif
 
 /*
  * TODO:
  */
 
+#include <stdio.h>
 #include <syslog.h>
+#include <termios.h>
 #include <utmp.h>
 #include <sys/types.h>
 #include <sys/file.h>
@@ -46,7 +48,31 @@ static char rcsid[] = "$Id: sys-ultrix.c,v 1.4 1994/05/25 06:30:49 paulus Exp $"
 #include "ppp.h"
 
 static int initdisc = -1;              /* Initial TTY discipline */
-extern int kdebugflag;
+
+static int restore_term;       /* 1 => we've munged the terminal */
+static struct termios inittermios;     /* Initial TTY termios */
+
+/*
+ * sys_init - System-dependent initialization.
+ */
+void
+sys_init()
+{
+    openlog("pppd", LOG_PID);
+    if (debug)
+       setlogmask(LOG_UPTO(LOG_DEBUG));
+}
+
+/*
+ * note_debug_level - note a change in the debug level.
+ */
+void
+note_debug_level()
+{
+    if (debug) {
+       syslog(LOG_INFO, "Debug turned ON, Level %d", debug);
+    }
+}
 
 /*
  * establish_ppp - Turn the serial port into a ppp interface.
@@ -130,6 +156,208 @@ disestablish_ppp()
 }
 
 
+/*
+ * List of valid speeds.
+ */
+struct speed {
+    int speed_int, speed_val;
+} speeds[] = {
+#ifdef B50
+    { 50, B50 },
+#endif
+#ifdef B75
+    { 75, B75 },
+#endif
+#ifdef B110
+    { 110, B110 },
+#endif
+#ifdef B134
+    { 134, B134 },
+#endif
+#ifdef B150
+    { 150, B150 },
+#endif
+#ifdef B200
+    { 200, B200 },
+#endif
+#ifdef B300
+    { 300, B300 },
+#endif
+#ifdef B600
+    { 600, B600 },
+#endif
+#ifdef B1200
+    { 1200, B1200 },
+#endif
+#ifdef B1800
+    { 1800, B1800 },
+#endif
+#ifdef B2000
+    { 2000, B2000 },
+#endif
+#ifdef B2400
+    { 2400, B2400 },
+#endif
+#ifdef B3600
+    { 3600, B3600 },
+#endif
+#ifdef B4800
+    { 4800, B4800 },
+#endif
+#ifdef B7200
+    { 7200, B7200 },
+#endif
+#ifdef B9600
+    { 9600, B9600 },
+#endif
+#ifdef B19200
+    { 19200, B19200 },
+#endif
+#ifdef B38400
+    { 38400, B38400 },
+#endif
+#ifdef EXTA
+    { 19200, EXTA },
+#endif
+#ifdef EXTB
+    { 38400, EXTB },
+#endif
+#ifdef B57600
+    { 57600, B57600 },
+#endif
+#ifdef B115200
+    { 115200, B115200 },
+#endif
+    { 0, 0 }
+};
+
+/*
+ * Translate from bits/second to a speed_t.
+ */
+int
+translate_speed(bps)
+    int bps;
+{
+    struct speed *speedp;
+
+    if (bps == 0)
+       return 0;
+    for (speedp = speeds; speedp->speed_int; speedp++)
+       if (bps == speedp->speed_int)
+           return speedp->speed_val;
+    syslog(LOG_WARNING, "speed %d not supported", bps);
+    return 0;
+}
+
+/*
+ * Translate from a speed_t to bits/second.
+ */
+int
+baud_rate_of(speed)
+    int speed;
+{
+    struct speed *speedp;
+
+    if (speed == 0)
+       return 0;
+    for (speedp = speeds; speedp->speed_int; speedp++)
+       if (speed == speedp->speed_val)
+           return speedp->speed_int;
+    return 0;
+}
+
+/*
+ * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity,
+ * at the requested speed, etc.  If `local' is true, set CLOCAL
+ * regardless of whether the modem option was specified.
+ */
+set_up_tty(fd, local)
+    int fd, local;
+{
+    int speed, x;
+    struct termios tios;
+
+    if (tcgetattr(fd, &tios) < 0) {
+       syslog(LOG_ERR, "tcgetattr: %m");
+       die(1);
+    }
+
+    if (!restore_term)
+       inittermios = tios;
+
+#ifdef CRTSCTS
+    tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL | CRTSCTS);
+    if (crtscts == 1)
+       tios.c_cflag |= CRTSCTS;
+#else
+    tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
+#endif /* CRTSCTS */
+
+    tios.c_cflag |= CS8 | CREAD | HUPCL;
+    if (local || !modem)
+       tios.c_cflag |= CLOCAL;
+    tios.c_iflag = IGNBRK | IGNPAR;
+    tios.c_oflag = 0;
+    tios.c_lflag = 0;
+    tios.c_cc[VMIN] = 1;
+    tios.c_cc[VTIME] = 0;
+
+    if (crtscts == 2) {
+       tios.c_iflag |= IXOFF;
+       tios.c_cc[VSTOP] = 0x13;        /* DC3 = XOFF = ^S */
+       tios.c_cc[VSTART] = 0x11;       /* DC1 = XON  = ^Q */
+    }
+
+    speed = translate_speed(inspeed);
+    if (speed) {
+       cfsetospeed(&tios, speed);
+       cfsetispeed(&tios, speed);
+    } else {
+       speed = cfgetospeed(&tios);
+    }
+
+    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
+       syslog(LOG_ERR, "tcsetattr: %m");
+       die(1);
+    }
+
+    x = 0;
+    if (ioctl(fd, (crtscts || modem)? TIOCMODEM: TIOCNMODEM, &x) < 0)
+       syslog(LOG_WARNING, "TIOC(N)MODEM: %m");
+    if (ioctl(fd, (local || !modem)? TIOCNCAR: TIOCCAR) < 0)
+       syslog(LOG_WARNING, "TIOC(N)CAR: %m");
+
+    baud_rate = inspeed = baud_rate_of(speed);
+    restore_term = TRUE;
+}
+
+/*
+ * restore_tty - restore the terminal to the saved settings.
+ */
+void
+restore_tty()
+{
+    if (restore_term) {
+       if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
+           if (errno != ENXIO)
+               syslog(LOG_WARNING, "tcsetattr: %m");
+       restore_term = FALSE;
+    }
+}
+
+/*
+ * setdtr - control the DTR line on the serial port.
+ * This is called from die(), so it shouldn't call die().
+ */
+setdtr(fd, on)
+int fd, on;
+{
+    int modembits = TIOCM_DTR;
+
+    ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits);
+}
+
+
 /*
  * output - Output PPP packet.
  */
@@ -151,6 +379,27 @@ output(unit, p, len)
 }
 
 
+/*
+ * wait_input - wait until there is data available on fd,
+ * for the length of time specified by *timo (indefinite
+ * if timo is NULL).
+ */
+wait_input(timo)
+    struct timeval *timo;
+{
+    fd_set ready;
+    int n;
+
+    FD_ZERO(&ready);
+    FD_SET(fd, &ready);
+    n = select(fd+1, &ready, NULL, &ready, timo);
+    if (n < 0 && errno != EINTR) {
+       syslog(LOG_ERR, "select: %m");
+       die(1);
+    }
+}
+
+
 /*
  * read_packet - get a PPP packet from the serial device.
  */
@@ -179,7 +428,7 @@ read_packet(buf)
 void
 ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     int unit, mtu;
-    u_long asyncmap;
+    uint32 asyncmap;
     int pcomp, accomp;
 {
     u_int x;
@@ -230,7 +479,7 @@ ppp_set_xaccm(unit, accm)
 void
 ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
     int unit, mru;
-    u_long asyncmap;
+    uint32 asyncmap;
     int pcomp, accomp;
 {
     int x;
@@ -254,6 +503,25 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
     }
 }
 
+/*
+ * ccp_flags_set - inform kernel about the current state of CCP.
+ */
+void
+ccp_flags_set(unit, isopen, isup)
+    int unit, isopen, isup;
+{
+    int x;
+
+    if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
+       syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+       return;
+    }
+    x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
+    x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
+    if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+}
+
 /*
  * sifvjcomp - config tcp header compression
  */
@@ -449,7 +717,7 @@ cifdefaultroute(u, g)
 int
 sifproxyarp(unit, hisaddr)
     int unit;
-    u_long hisaddr;
+    uint32 hisaddr;
 {
     struct arpreq arpreq;
 
@@ -481,7 +749,7 @@ sifproxyarp(unit, hisaddr)
 int
 cifproxyarp(unit, hisaddr)
     int unit;
-    u_long hisaddr;
+    uint32 hisaddr;
 {
     struct arpreq arpreq;
 
@@ -503,11 +771,11 @@ cifproxyarp(unit, hisaddr)
 
 int
 get_ether_addr(ipaddr, hwaddr)
-    u_long ipaddr;
+    uint32 ipaddr;
     struct sockaddr *hwaddr;
 {
     struct ifreq *ifr, *ifend, *ifp;
-    u_long ina, mask;
+    uint32 ina, mask;
     struct sockaddr_dl *dla;
     struct ifreq ifreq;
     struct ifconf ifc;