summaryrefslogtreecommitdiffstats
path: root/sys/i4b/driver
diff options
context:
space:
mode:
authorhm <hm@FreeBSD.org>2000-10-09 13:18:17 +0000
committerhm <hm@FreeBSD.org>2000-10-09 13:18:17 +0000
commit9fc2bc8a46f4f09ca71eaf59e5c203b5d61533fb (patch)
treeca1e99e8eac9fd3f8c8cecbcbfc102b0bfa6f03f /sys/i4b/driver
parent7fc1fa165474e47dca5d7dfb2584d97d169d686d (diff)
downloadFreeBSD-src-9fc2bc8a46f4f09ca71eaf59e5c203b5d61533fb.zip
FreeBSD-src-9fc2bc8a46f4f09ca71eaf59e5c203b5d61533fb.tar.gz
update to i4b version 0.95.04
Diffstat (limited to 'sys/i4b/driver')
-rw-r--r--sys/i4b/driver/i4b_bsdi_ibc.c8
-rw-r--r--sys/i4b/driver/i4b_ctl.c97
-rw-r--r--sys/i4b/driver/i4b_ing.c860
-rw-r--r--sys/i4b/driver/i4b_ipr.c74
-rw-r--r--sys/i4b/driver/i4b_isppp.c110
-rw-r--r--sys/i4b/driver/i4b_ispppsubr.c4612
-rw-r--r--sys/i4b/driver/i4b_rbch.c178
-rw-r--r--sys/i4b/driver/i4b_tel.c774
-rw-r--r--sys/i4b/driver/i4b_trace.c73
9 files changed, 6546 insertions, 240 deletions
diff --git a/sys/i4b/driver/i4b_bsdi_ibc.c b/sys/i4b/driver/i4b_bsdi_ibc.c
index 2134997..369d4aa 100644
--- a/sys/i4b/driver/i4b_bsdi_ibc.c
+++ b/sys/i4b/driver/i4b_bsdi_ibc.c
@@ -30,11 +30,11 @@
* i4b_bsdi_ibc.c - isdn4bsd kernel BSD/OS point to point driver
* -------------------------------------------------------------
*
- * $Id: i4b_bsdi_ibc.c,v 1.1 1999/04/23 08:35:07 hm Exp $
+ * $Id: i4b_bsdi_ibc.c,v 1.3 2000/08/21 07:21:07 hm Exp $
*
* $FreeBSD$
*
- * last edit-date: [Tue Dec 14 21:55:37 1999]
+ * last edit-date: [Tue Dec 14 21:55:24 1999]
*
*---------------------------------------------------------------------------*/
@@ -184,7 +184,11 @@ ibcattach(void *dummy)
sc->sc_loutb = 0;
sc->sc_fn = 1;
#endif
+#if defined(__FreeBSD_version) && ((__FreeBSD_version >= 500009) || (410000 <= __FreeBSD_version && __FreeBSD_version < 500000))
+ ether_ifattach(ifp, 0);
+#else
if_attach(ifp);
+#endif
p2p_attach(&sc->sc_p2pcom);
}
}
diff --git a/sys/i4b/driver/i4b_ctl.c b/sys/i4b/driver/i4b_ctl.c
index c026fef..a5c7597 100644
--- a/sys/i4b/driver/i4b_ctl.c
+++ b/sys/i4b/driver/i4b_ctl.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
+ * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,11 +27,11 @@
* i4b_ctl.c - i4b system control port driver
* ------------------------------------------
*
- * $Id: i4b_ctl.c,v 1.30 1999/12/13 21:25:23 hm Exp $
+ * $Id: i4b_ctl.c,v 1.37 2000/05/31 08:04:43 hm Exp $
*
* $FreeBSD$
*
- * last edit-date: [Mon Dec 13 21:38:15 1999]
+ * last edit-date: [Wed May 31 09:59:01 2000]
*
*---------------------------------------------------------------------------*/
@@ -62,6 +62,18 @@
#include <net/if.h>
#ifdef __FreeBSD__
+
+#if defined(__FreeBSD__) && __FreeBSD__ == 3
+#include "opt_devfs.h"
+#endif
+
+#ifdef DEVFS
+#include <sys/devfsext.h>
+#endif
+
+#endif /* __FreeBSD__ */
+
+#ifdef __FreeBSD__
#include <machine/i4b_debug.h>
#include <machine/i4b_ioctl.h>
#elif defined(__bsdi__)
@@ -76,7 +88,8 @@
#include <i4b/include/i4b_global.h>
#include <i4b/include/i4b_mbuf.h>
-#include <i4b/layer1/i4b_l1.h>
+#include <i4b/include/i4b_l3l4.h>
+
#include <i4b/layer2/i4b_l2.h>
static int openflag = 0;
@@ -126,6 +139,9 @@ PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
#endif /* __FreeBSD__ */
#if defined(__FreeBSD__) && __FreeBSD__ == 3
+#ifdef DEVFS
+static void *devfs_token;
+#endif
#endif
#ifndef __FreeBSD__
@@ -204,6 +220,11 @@ i4bctlattach()
#if defined(__FreeBSD__)
#if __FreeBSD__ == 3
+#ifdef DEVFS
+ devfs_token = devfs_add_devswf(&i4bctl_cdevsw, 0, DV_CHR,
+ UID_ROOT, GID_WHEEL, 0600,
+ "i4bctl");
+#endif
#else
make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
@@ -250,10 +271,12 @@ i4bctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
i4bctlioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
#endif
{
+#if DO_I4B_DEBUG
ctl_debug_t *cdbg;
int error = 0;
+#endif
-#ifndef DO_I4B_DEBUG
+#if !DO_I4B_DEBUG
return(ENODEV);
#else
if(minor(dev))
@@ -277,63 +300,19 @@ i4bctlioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
i4b_l4_debug = cdbg->l4;
break;
- case I4B_CTL_GET_HSCXSTAT:
+ case I4B_CTL_GET_CHIPSTAT:
{
- hscxstat_t *hst;
- struct l1_softc *sc;
- hst = (hscxstat_t *)data;
-
- if( hst->unit < 0 ||
- hst->unit > ISIC_MAXUNIT ||
- hst->chan < 0 ||
- hst->chan > 1 )
- {
- error = EINVAL;
- break;
- }
-
-#ifndef __FreeBSD__
- sc = isic_find_sc(hst->unit);
-#else
- sc = &l1_sc[hst->unit];
-#endif
- hst->vfr = sc->sc_chan[hst->chan].stat_VFR;
- hst->rdo = sc->sc_chan[hst->chan].stat_RDO;
- hst->crc = sc->sc_chan[hst->chan].stat_CRC;
- hst->rab = sc->sc_chan[hst->chan].stat_RAB;
- hst->xdu = sc->sc_chan[hst->chan].stat_XDU;
- hst->rfo = sc->sc_chan[hst->chan].stat_RFO;
+ struct chipstat *cst;
+ cst = (struct chipstat *)data;
+ (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_GCST, cst);
break;
}
- case I4B_CTL_CLR_HSCXSTAT:
+ case I4B_CTL_CLR_CHIPSTAT:
{
- hscxstat_t *hst;
- struct l1_softc *sc;
- hst = (hscxstat_t *)data;
-
- if( hst->unit < 0 ||
- hst->unit > ISIC_MAXUNIT ||
- hst->chan < 0 ||
- hst->chan > 1 )
- {
- error = EINVAL;
- break;
- }
-
-#ifndef __FreeBSD__
- sc = isic_find_sc(hst->unit);
-#else
- sc = &l1_sc[hst->unit];
-#endif
-
- sc->sc_chan[hst->chan].stat_VFR = 0;
- sc->sc_chan[hst->chan].stat_RDO = 0;
- sc->sc_chan[hst->chan].stat_CRC = 0;
- sc->sc_chan[hst->chan].stat_RAB = 0;
- sc->sc_chan[hst->chan].stat_XDU = 0;
- sc->sc_chan[hst->chan].stat_RFO = 0;
-
+ struct chipstat *cst;
+ cst = (struct chipstat *)data;
+ (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_CCST, cst);
break;
}
@@ -343,7 +322,7 @@ i4bctlioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
l2_softc_t *sc;
l2s = (l2stat_t *)data;
- if( l2s->unit < 0 || l2s->unit > ISIC_MAXUNIT)
+ if( l2s->unit < 0 || l2s->unit > MAXL1UNITS)
{
error = EINVAL;
break;
@@ -361,7 +340,7 @@ i4bctlioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
l2_softc_t *sc;
up = (int *)data;
- if( *up < 0 || *up > ISIC_MAXUNIT)
+ if( *up < 0 || *up > MAXL1UNITS)
{
error = EINVAL;
break;
diff --git a/sys/i4b/driver/i4b_ing.c b/sys/i4b/driver/i4b_ing.c
new file mode 100644
index 0000000..dc6d348
--- /dev/null
+++ b/sys/i4b/driver/i4b_ing.c
@@ -0,0 +1,860 @@
+/*
+ * Copyright (c) 1999, 2000 Hellmuth Michaelis. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *---------------------------------------------------------------------------
+ *
+ * i4b_ing.c - isdn4bsd B-channel to netgraph driver
+ * -------------------------------------------------
+ *
+ * $Id: i4b_ing.c,v 1.10 2000/04/27 11:35:00 hm Exp $
+ *
+ * $FreeBSD$
+ *
+ * last edit-date: [Thu Apr 27 13:33:18 2000]
+ *
+ *---------------------------------------------------------------------------*/
+
+#include "i4bing.h"
+
+#if NI4BING > 0
+
+#include "opt_i4b.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/errno.h>
+#include <sys/ctype.h>
+#include <sys/ioccom.h>
+#include <sys/syslog.h>
+#include <sys/malloc.h>
+
+#include <net/if.h>
+
+#include <netgraph/ng_message.h>
+#include <netgraph/ng_parse.h>
+#include <netgraph/netgraph.h>
+
+#include <machine/i4b_ioctl.h>
+#include <machine/i4b_debug.h>
+
+#include <i4b/include/i4b_global.h>
+#include <i4b/include/i4b_mbuf.h>
+#include <i4b/include/i4b_l3l4.h>
+
+#include <i4b/layer4/i4b_l4.h>
+
+#define I4BINGACCT 1 /* enable accounting messages */
+#define I4BINGACCTINTVL 2 /* accounting msg interval in secs */
+
+#define I4BINGMAXQLEN 50 /* max queue length */
+
+/* initialized by L4 */
+
+static drvr_link_t ing_drvr_linktab[NI4BING];
+static isdn_link_t *isdn_linktab[NI4BING];
+
+struct ing_softc {
+ int sc_unit; /* unit number */
+ int sc_state; /* state of the interface */
+ call_desc_t *sc_cdp; /* ptr to call descriptor */
+ int sc_updown; /* soft state of interface */
+ struct ifqueue sc_fastq; /* interactive traffic */
+ int sc_dialresp; /* dialresponse */
+ int sc_lastdialresp;/* last dialresponse */
+
+#if I4BINGACCT
+ struct callout_handle sc_callout;
+ int sc_iinb; /* isdn driver # of inbytes */
+ int sc_ioutb; /* isdn driver # of outbytes */
+ int sc_inb; /* # of bytes rx'd */
+ int sc_outb; /* # of bytes tx'd */
+ int sc_linb; /* last # of bytes rx'd */
+ int sc_loutb; /* last # of bytes tx'd */
+ int sc_fn; /* flag, first null acct */
+#endif
+
+ int sc_inpkt; /* incoming packets */
+ int sc_outpkt; /* outgoing packets */
+
+ struct ifqueue xmitq_hipri; /* hi-priority transmit queue */
+ struct ifqueue xmitq; /* transmit queue */
+
+ node_p node; /* back pointer to node */
+ char nodename[NG_NODELEN + 1]; /* store our node name */
+ hook_p debughook;
+ hook_p hook;
+
+ u_int packets_in; /* packets in from downstream */
+ u_int packets_out; /* packets out towards downstream */
+ u_int32_t flags;
+
+} ing_softc[NI4BING];
+
+enum ing_states {
+ ST_IDLE, /* initialized, ready, idle */
+ ST_DIALING, /* dialling out to remote */
+ ST_CONNECTED /* connected to remote */
+};
+
+static void i4bingattach(void *);
+
+PSEUDO_SET(i4bingattach, i4b_ing);
+
+static void ing_init_linktab(int unit);
+static void ing_tx_queue_empty(int unit);
+
+/* ========= NETGRAPH ============= */
+
+#define NG_ING_NODE_TYPE "i4bing" /* node type name */
+#define NGM_ING_COOKIE 947513046 /* node type cookie */
+
+/* Hook names */
+#define NG_ING_HOOK_DEBUG "debug"
+#define NG_ING_HOOK_RAW "rawdata"
+
+/* Netgraph commands understood by this node type */
+enum {
+ NGM_ING_SET_FLAG = 1,
+ NGM_ING_GET_STATUS,
+};
+
+/* This structure is returned by the NGM_ING_GET_STATUS command */
+struct ngingstat {
+ u_int packets_in; /* packets in from downstream */
+ u_int packets_out; /* packets out towards downstream */
+};
+
+/*
+ * This is used to define the 'parse type' for a struct ngingstat, which
+ * is bascially a description of how to convert a binary struct ngingstat
+ * to an ASCII string and back. See ng_parse.h for more info.
+ *
+ * This needs to be kept in sync with the above structure definition
+ */
+#define NG_ING_STATS_TYPE_INFO { \
+ { \
+ { "packets_in", &ng_parse_int32_type }, \
+ { "packets_out", &ng_parse_int32_type }, \
+ { NULL }, \
+ } \
+}
+
+/*
+ * This section contains the netgraph method declarations for the
+ * sample node. These methods define the netgraph 'type'.
+ */
+
+static ng_constructor_t ng_ing_constructor;
+static ng_rcvmsg_t ng_ing_rcvmsg;
+static ng_shutdown_t ng_ing_rmnode;
+static ng_newhook_t ng_ing_newhook;
+static ng_connect_t ng_ing_connect;
+static ng_rcvdata_t ng_ing_rcvdata;
+static ng_disconnect_t ng_ing_disconnect;
+
+/* Parse type for struct ngingstat */
+static const struct
+ ng_parse_struct_info ng_ing_stat_type_info = NG_ING_STATS_TYPE_INFO;
+
+static const struct ng_parse_type ng_ing_stat_type = {
+ &ng_parse_struct_type,
+ &ng_ing_stat_type_info
+};
+
+/* List of commands and how to convert arguments to/from ASCII */
+
+static const struct ng_cmdlist ng_ing_cmdlist[] = {
+ {
+ NGM_ING_COOKIE,
+ NGM_ING_GET_STATUS,
+ "getstatus",
+ NULL,
+ &ng_ing_stat_type,
+ },
+ {
+ NGM_ING_COOKIE,
+ NGM_ING_SET_FLAG,
+ "setflag",
+ &ng_parse_int32_type,
+ NULL
+ },
+ { 0 }
+};
+
+/* Netgraph node type descriptor */
+static struct ng_type typestruct = {
+ NG_VERSION,
+ NG_ING_NODE_TYPE,
+ NULL,
+ ng_ing_constructor,
+ ng_ing_rcvmsg,
+ ng_ing_rmnode,
+ ng_ing_newhook,
+ NULL,
+ ng_ing_connect,
+ ng_ing_rcvdata,
+ ng_ing_rcvdata,
+ ng_ing_disconnect,
+ ng_ing_cmdlist
+};
+
+NETGRAPH_INIT(ing, &typestruct);
+
+/*===========================================================================*
+ * DEVICE DRIVER ROUTINES
+ *===========================================================================*/
+
+/*---------------------------------------------------------------------------*
+ * interface attach routine at kernel boot time
+ *---------------------------------------------------------------------------*/
+static void
+i4bingattach(void *dummy)
+{
+ struct ing_softc *sc = ing_softc;
+ int i;
+ int ret;
+
+ printf("i4bing: %d i4b NetGraph ISDN B-channel device(s) attached\n", NI4BING);
+
+ for(i=0; i < NI4BING; sc++, i++)
+ {
+ sc->sc_unit = i;
+
+ ing_init_linktab(i);
+
+ NDBGL4(L4_DIALST, "setting dial state to ST_IDLE");
+
+ sc->sc_state = ST_IDLE;
+
+ sc->sc_fastq.ifq_maxlen = I4BINGMAXQLEN;
+
+#if I4BINGACCT
+ callout_handle_init(&sc->sc_callout);
+ sc->sc_iinb = 0;
+ sc->sc_ioutb = 0;
+ sc->sc_inb = 0;
+ sc->sc_outb = 0;
+ sc->sc_linb = 0;
+ sc->sc_loutb = 0;
+ sc->sc_fn = 1;
+#endif
+
+ sc->sc_inpkt = 0;
+ sc->sc_outpkt = 0;
+
+ sc->sc_updown = SOFT_ENA; /* soft enabled */
+
+ sc->sc_dialresp = DSTAT_NONE; /* no response */
+ sc->sc_lastdialresp = DSTAT_NONE;
+
+ /* setup a netgraph node */
+
+ if ((ret = ng_make_node_common(&typestruct, &sc->node)))
+ {
+ printf("ing: ng_make_node_common, ret = %d\n!", ret);
+ }
+
+ sc->node->private = sc;
+
+ sc->xmitq.ifq_maxlen = IFQ_MAXLEN;
+ sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN;
+
+ /* name the netgraph node */
+
+ sprintf(sc->nodename, "%s%d", NG_ING_NODE_TYPE, sc->sc_unit);
+
+ if(ng_name_node(sc->node, sc->nodename))
+ {
+ ng_rmnode(sc->node);
+ ng_unref(sc->node);
+ }
+ }
+}
+
+#ifdef I4BINGACCT
+/*---------------------------------------------------------------------------*
+ * accounting timeout routine
+ *---------------------------------------------------------------------------*/
+static void
+ing_timeout(struct ing_softc *sc)
+{
+ bchan_statistics_t bs;
+ int unit = sc->sc_unit;
+
+ /* get # of bytes in and out from the HSCX driver */
+
+ (*isdn_linktab[unit]->bch_stat)
+ (isdn_linktab[unit]->unit, isdn_linktab[unit]->channel, &bs);
+
+ sc->sc_ioutb += bs.outbytes;
+ sc->sc_iinb += bs.inbytes;
+
+ if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
+ {
+ int ri = (sc->sc_iinb - sc->sc_linb)/I4BINGACCTINTVL;
+ int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BINGACCTINTVL;
+
+ if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
+ sc->sc_fn = 0;
+ else
+ sc->sc_fn = 1;
+
+ sc->sc_linb = sc->sc_iinb;
+ sc->sc_loutb = sc->sc_ioutb;
+
+ i4b_l4_accounting(BDRV_ING, unit, ACCT_DURING,
+ sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_ioutb, sc->sc_iinb);
+ }
+
+ sc->sc_callout = timeout((TIMEOUT_FUNC_T)ing_timeout,
+ (void *)sc, I4BINGACCTINTVL*hz);
+}
+#endif /* I4BINGACCT */
+
+#if 0
+/*---------------------------------------------------------------------------*
+ * clear the interface's send queues
+ *---------------------------------------------------------------------------*/
+static void
+ingclearqueue(struct ifqueue *iq)
+{
+ int x;
+ struct mbuf *m;
+
+ for(;;)
+ {
+ x = splimp();
+ IF_DEQUEUE(iq, m);
+ splx(x);
+
+ if(m)
+ m_freem(m);
+ else
+ break;
+ }
+}
+#endif
+
+/*===========================================================================*
+ * ISDN INTERFACE ROUTINES
+ *===========================================================================*/
+
+/*---------------------------------------------------------------------------*
+ * this routine is called from L4 handler at connect time
+ *---------------------------------------------------------------------------*/
+static void
+ing_connect(int unit, void *cdp)
+{
+ struct ing_softc *sc = &ing_softc[unit];
+ int s;
+
+ sc->sc_cdp = (call_desc_t *)cdp;
+
+ s = SPLI4B();
+
+ NDBGL4(L4_DIALST, "ing%d: setting dial state to ST_CONNECTED", unit);
+
+ sc->sc_dialresp = DSTAT_NONE;
+ sc->sc_lastdialresp = DSTAT_NONE;
+
+#if I4BINGACCT
+ sc->sc_iinb = 0;
+ sc->sc_ioutb = 0;
+ sc->sc_inb = 0;
+ sc->sc_outb = 0;
+ sc->sc_linb = 0;
+ sc->sc_loutb = 0;
+ sc->sc_callout = timeout((TIMEOUT_FUNC_T)ing_timeout,
+ (void *)sc, I4BINGACCTINTVL*hz);
+#endif
+
+ sc->sc_state = ST_CONNECTED;
+
+ splx(s);
+}
+
+/*---------------------------------------------------------------------------*
+ * this routine is called from L4 handler at disconnect time
+ *---------------------------------------------------------------------------*/
+static void
+ing_disconnect(int unit, void *cdp)
+{
+ call_desc_t *cd = (call_desc_t *)cdp;
+ struct ing_softc *sc = &ing_softc[unit];
+
+ /* new stuff to check that the active channel is being closed */
+
+ if (cd != sc->sc_cdp)
+ {
+ NDBGL4(L4_INGDBG, "ing%d: channel %d not active",
+ cd->driver_unit, cd->channelid);
+ return;
+ }
+
+#if I4BINGACCT
+ untimeout((TIMEOUT_FUNC_T)ing_timeout,
+ (void *)sc, sc->sc_callout);
+#endif
+
+ i4b_l4_accounting(BDRV_ING, cd->driver_unit, ACCT_FINAL,
+ sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_outb, sc->sc_inb);
+
+ sc->sc_cdp = (call_desc_t *)0;
+
+ NDBGL4(L4_DIALST, "setting dial state to ST_IDLE");
+
+ sc->sc_dialresp = DSTAT_NONE;
+ sc->sc_lastdialresp = DSTAT_NONE;
+
+ sc->sc_state = ST_IDLE;
+}
+
+/*---------------------------------------------------------------------------*
+ * this routine is used to give a feedback from userland daemon
+ * in case of dial problems
+ *---------------------------------------------------------------------------*/
+static void
+ing_dialresponse(int unit, int status, cause_t cause)
+{
+ struct ing_softc *sc = &ing_softc[unit];
+ sc->sc_dialresp = status;
+
+ NDBGL4(L4_INGDBG, "ing%d: last=%d, this=%d",
+ unit, sc->sc_lastdialresp, sc->sc_dialresp);
+
+ if(status != DSTAT_NONE)
+ {
+ NDBGL4(L4_INGDBG, "ing%d: clearing queues", unit);
+/* ingclearqueues(sc); */
+ }
+}
+
+/*---------------------------------------------------------------------------*
+ * interface soft up/down
+ *---------------------------------------------------------------------------*/
+static void
+ing_updown(int unit, int updown)
+{
+ struct ing_softc *sc = &ing_softc[unit];
+ sc->sc_updown = updown;
+}
+
+/*---------------------------------------------------------------------------*
+ * this routine is called from the HSCX interrupt handler
+ * when a new frame (mbuf) has been received and was put on
+ * the rx queue. It is assumed that this routines runs at
+ * pri level splimp() ! Keep it short !
+ *---------------------------------------------------------------------------*/
+static void
+ing_rx_data_rdy(int unit)
+{
+ register struct ing_softc *sc = &ing_softc[unit];
+ register struct mbuf *m;
+
+ if((m = *isdn_linktab[unit]->rx_mbuf) == NULL)
+ return;
+
+#if I4BINGACCT
+ sc->sc_inb += m->m_pkthdr.len;
+#endif
+
+ m->m_pkthdr.rcvif = NULL;
+
+ sc->sc_inpkt++;
+
+ ng_queue_data(sc->hook, m, NULL);
+}
+
+/*---------------------------------------------------------------------------*
+ * this routine is called from the HSCX interrupt handler
+ * when the last frame has been sent out and there is no
+ * further frame (mbuf) in the tx queue.
+ *---------------------------------------------------------------------------*/
+static void
+ing_tx_queue_empty(int unit)
+{
+ register struct ing_softc *sc = &ing_softc[unit];
+ register struct mbuf *m;
+ int x = 0;
+
+ if(sc->sc_state != ST_CONNECTED)
+ return;
+
+ for(;;)
+ {
+ IF_DEQUEUE(&sc->xmitq_hipri, m);
+
+ if(m == NULL)
+ {
+ IF_DEQUEUE(&sc->xmitq, m);
+ if(m == NULL)
+ break;
+ }
+
+#if I4BINGACCT
+ sc->sc_outb += m->m_pkthdr.len;
+#endif
+
+ x = 1;
+
+ if(IF_QFULL(isdn_linktab[unit]->tx_queue))
+ {
+ NDBGL4(L4_INGDBG, "ing%d: tx queue full!", unit);
+ m_freem(m);
+ }
+ else
+ {
+ IF_ENQUEUE(isdn_linktab[unit]->tx_queue, m);
+ }
+ }
+
+ if(x)
+ (*isdn_linktab[unit]->bch_tx_start)(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel);
+}
+
+/*---------------------------------------------------------------------------*
+ * this routine is called from the HSCX interrupt handler
+ * each time a packet is received or transmitted. It should
+ * be used to implement an activity timeout mechanism.
+ *---------------------------------------------------------------------------*/
+static void
+ing_activity(int unit, int rxtx)
+{
+ ing_softc[unit].sc_cdp->last_active_time = SECOND;
+}
+
+/*---------------------------------------------------------------------------*
+ * return this drivers linktab address
+ *---------------------------------------------------------------------------*/
+drvr_link_t *
+ing_ret_linktab(int unit)
+{
+ return(&ing_drvr_linktab[unit]);
+}
+
+/*---------------------------------------------------------------------------*
+ * setup the isdn_linktab for this driver
+ *---------------------------------------------------------------------------*/
+void
+ing_set_linktab(int unit, isdn_link_t *ilt)
+{
+ isdn_linktab[unit] = ilt;
+}
+
+/*---------------------------------------------------------------------------*
+ * initialize this drivers linktab
+ *---------------------------------------------------------------------------*/
+static void
+ing_init_linktab(int unit)
+{
+ ing_drvr_linktab[unit].unit = unit;
+ ing_drvr_linktab[unit].bch_rx_data_ready = ing_rx_data_rdy;
+ ing_drvr_linktab[unit].bch_tx_queue_empty = ing_tx_queue_empty;
+ ing_drvr_linktab[unit].bch_activity = ing_activity;
+ ing_drvr_linktab[unit].line_connected = ing_connect;
+ ing_drvr_linktab[unit].line_disconnected = ing_disconnect;
+ ing_drvr_linktab[unit].dial_response = ing_dialresponse;
+ ing_drvr_linktab[unit].updown_ind = ing_updown;
+}
+
+/*===========================================================================*
+ * NETGRAPH INTERFACE ROUTINES
+ *===========================================================================*/
+
+/*---------------------------------------------------------------------------*
+ * It is not possible or allowable to create a node of this type.
+ * If the hardware exists, it will already have created it.
+ *---------------------------------------------------------------------------*/
+static int
+ng_ing_constructor(node_p *nodep)
+{
+ return(EINVAL);
+}
+
+/*---------------------------------------------------------------------------*
+ * Give our ok for a hook to be added...
+ * Add the hook's private info to the hook structure.
+ *---------------------------------------------------------------------------*/
+static int
+ng_ing_newhook(node_p node, hook_p hook, const char *name)
+{
+ struct ing_softc *sc = node->private;
+
+ /*
+ * check if it's our friend the debug hook
+ */
+ if(strcmp(name, NG_ING_HOOK_DEBUG) == 0)
+ {
+ hook->private = NULL; /* paranoid */
+ sc->debughook = hook;
+ return (0);
+ }
+ /*
+ * Check for raw mode hook.
+ */
+ if(strcmp(name, NG_ING_HOOK_RAW) == 0)
+ {
+ hook->private = sc;
+ sc->hook = hook;
+ return (0);
+ }
+
+ return (EINVAL);
+}
+
+/*---------------------------------------------------------------------------*
+ * Get a netgraph control message.
+ * Check it is one we understand. If needed, send a response.
+ * We could save the address for an async action later, but don't here.
+ * Always free the message.
+ * The response should be in a malloc'd region that the caller can 'free'.
+ * A response is not required.
+ *---------------------------------------------------------------------------*/
+static int
+ng_ing_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
+ struct ng_mesg **rptr)
+{
+ struct ing_softc *sc = node->private;
+
+ struct ng_mesg *resp = NULL;
+ int error = 0;
+
+ if(msg->header.typecookie == NGM_GENERIC_COOKIE)
+ {
+ switch(msg->header.cmd)
+ {
+ case NGM_TEXT_STATUS:
+ {
+ char *arg;
+ char *p;
+ int pos = 0;
+
+ NG_MKRESPONSE(resp, msg, sizeof(struct ng_mesg) + NG_TEXTRESPONSE, M_NOWAIT);
+
+ if (resp == NULL)
+ {
+ error = ENOMEM;
+ break;
+ }
+ arg = (char *) resp->data;
+
+ switch(sc->sc_state)
+ {
+ case ST_IDLE:
+ p = "idle";
+ break;
+ case ST_DIALING:
+ p = "dialing";
+ break;
+ case ST_CONNECTED:
+ p = "connected";
+ break;
+ default:
+ p = "???";
+ break;
+ }
+
+ pos = sprintf(arg, "state = %s (%d)\n", p, sc->sc_state);
+#if I4BINGACCT
+ pos += sprintf(arg + pos, "%d bytes in, %d bytes out\n", sc->sc_inb, sc->sc_outb);
+#endif
+ pos += sprintf(arg + pos, "%d pkts in, %d pkts out\n", sc->sc_inpkt, sc->sc_outpkt);
+
+ resp->header.arglen = pos + 1;
+ break;
+ }
+
+ default:
+ error = EINVAL;
+ break;
+ }
+ }
+ else if(msg->header.typecookie == NGM_ING_COOKIE)
+ {
+ switch (msg->header.cmd)
+ {
+ case NGM_ING_GET_STATUS:
+ {
+ struct ngingstat *stats;
+
+ NG_MKRESPONSE(resp, msg, sizeof(*stats), M_NOWAIT);
+
+ if (!resp)
+ {
+ error = ENOMEM;
+ break;
+ }
+
+ stats = (struct ngingstat *) resp->data;
+ stats->packets_in = sc->packets_in;
+ stats->packets_out = sc->packets_out;
+ break;
+ }
+
+ case NGM_ING_SET_FLAG:
+ if (msg->header.arglen != sizeof(u_int32_t))
+ {
+ error = EINVAL;
+ break;
+ }
+ sc->flags = *((u_int32_t *) msg->data);
+ break;
+
+ default:
+ error = EINVAL; /* unknown command */
+ break;
+ }
+ }
+ else
+ {
+ error = EINVAL; /* unknown cookie type */
+ }
+
+ /* Take care of synchronous response, if any */
+
+ if (rptr)
+ *rptr = resp;
+ else if (resp)
+ FREE(resp, M_NETGRAPH);
+
+ /* Free the message and return */
+
+ FREE(msg, M_NETGRAPH);
+ return(error);
+}
+
+/*---------------------------------------------------------------------------*
+ * get data from another node and transmit it out on a B-channel
+ *---------------------------------------------------------------------------*/
+static int
+ng_ing_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
+{
+ struct ing_softc *sc = hook->node->private;
+ struct ifqueue *xmitq_p;
+ int s;
+
+ if(hook->private == NULL)
+ {
+ NG_FREE_DATA(m, meta);
+ return(ENETDOWN);
+ }
+
+ if(sc->sc_state == ST_IDLE || sc->sc_state == ST_DIALING)
+ {
+ i4b_l4_dialout(BDRV_ING, sc->sc_unit);
+ sc->sc_state = ST_DIALING;
+ }
+
+ sc->sc_outpkt++;
+
+ /*
+ * Now queue the data for when it can be sent
+ */
+
+ if (meta && meta->priority > 0)
+ {
+ xmitq_p = (&sc->xmitq_hipri);
+ }
+ else
+ {
+ xmitq_p = (&sc->xmitq);
+ }
+
+ s = splimp();
+
+ if (IF_QFULL(xmitq_p))
+ {
+ IF_DROP(xmitq_p);
+ splx(s);
+ NG_FREE_DATA(m, meta);
+ return(ENOBUFS);
+ }
+
+ IF_ENQUEUE(xmitq_p, m);
+
+ ing_tx_queue_empty(sc->sc_unit);
+
+ splx(s);
+ return (0);
+}
+
+/*---------------------------------------------------------------------------*
+ * Do local shutdown processing..
+ * If we are a persistant device, we might refuse to go away, and
+ * we'd only remove our links and reset ourself.
+ *---------------------------------------------------------------------------*/
+static int
+ng_ing_rmnode(node_p node)
+{
+ struct ing_softc *sc = node->private;
+
+ node->flags |= NG_INVALID;
+ ng_cutlinks(node);
+
+ sc->packets_in = 0; /* reset stats */
+ sc->packets_out = 0;
+
+ node->flags &= ~NG_INVALID; /* reset invalid flag */
+
+ return (0);
+}
+
+/*---------------------------------------------------------------------------*
+ * This is called once we've already connected a new hook to the other node.
+ *---------------------------------------------------------------------------*/
+static int
+ng_ing_connect(hook_p hook)
+{
+ return (0);
+}
+
+/*
+ * Dook disconnection
+ *
+ * For this type, removal of the last link destroys the node
+ */
+static int
+ng_ing_disconnect(hook_p hook)
+{
+ struct ing_softc *sc = hook->node->private;
+ int s;
+
+ if(hook->private)
+ {
+ s = splimp();
+ splx(s);
+ }
+ else
+ {
+ sc->debughook = NULL;
+ }
+ return (0);
+}
+
+/*===========================================================================*/
+
+#endif /* NI4BING > 0 */
diff --git a/sys/i4b/driver/i4b_ipr.c b/sys/i4b/driver/i4b_ipr.c
index e807412..4e7533f 100644
--- a/sys/i4b/driver/i4b_ipr.c
+++ b/sys/i4b/driver/i4b_ipr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
+ * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,11 +27,11 @@
* i4b_ipr.c - isdn4bsd IP over raw HDLC ISDN network driver
* ---------------------------------------------------------
*
- * $Id: i4b_ipr.c,v 1.55 1999/12/13 21:25:24 hm Exp $
+ * $Id: i4b_ipr.c,v 1.59 2000/08/28 07:24:58 hm Exp $
*
* $FreeBSD$
*
- * last edit-date: [Mon Dec 13 21:38:51 1999]
+ * last edit-date: [Fri Aug 25 20:25:21 2000]
*
*---------------------------------------------------------------------------*
*
@@ -80,6 +80,11 @@
#else
#include <sys/ioctl.h>
#endif
+
+#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
+#include <sys/callout.h>
+#endif
+
#include <sys/kernel.h>
#include <sys/protosw.h>
@@ -193,6 +198,13 @@ struct ipr_softc {
int sc_fn; /* flag, first null acct */
#endif
+#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
+ struct callout sc_callout;
+#endif
+#if defined(__FreeBSD__)
+ struct callout_handle sc_callout;
+#endif
+
#ifdef I4BIPRADJFRXP
int sc_first_pkt; /* flag, first rxd packet */
#endif
@@ -279,7 +291,7 @@ i4biprattach()
{
ipr_init_linktab(i);
- DBGL4(L4_DIALST, "i4biprattach", ("setting dial state to ST_IDLE\n"));
+ NDBGL4(L4_DIALST, "setting dial state to ST_IDLE");
sc->sc_state = ST_IDLE;
@@ -304,6 +316,10 @@ i4biprattach()
sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_SIMPLEX;
#endif
+#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
+ callout_init(&sc->sc_callout);
+#endif
+
sc->sc_if.if_mtu = I4BIPRMTU;
sc->sc_if.if_type = IFT_ISDNBASIC;
sc->sc_if.if_ioctl = i4biprioctl;
@@ -360,7 +376,12 @@ i4biprattach()
sc->sc_dialresp = DSTAT_NONE; /* no response */
sc->sc_lastdialresp = DSTAT_NONE;
+#if defined(__FreeBSD_version) && ((__FreeBSD_version >= 500009) || (410000 <= __FreeBSD_version && __FreeBSD_version < 500000))
+ /* do not call bpfattach in ether_ifattach */
+ ether_ifattach(&sc->sc_if, 0);
+#else
if_attach(&sc->sc_if);
+#endif
#if NBPFILTER > 0 || NBPF > 0
#ifdef __FreeBSD__
@@ -411,7 +432,7 @@ i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
if(!(ifp->if_flags & IFF_UP))
{
- DBGL4(L4_IPRDBG, "i4biproutput", ("ipr%d: interface is DOWN!\n", unit));
+ NDBGL4(L4_IPRDBG, "ipr%d: interface is DOWN!", unit);
m_freem(m);
splx(s);
sc->sc_if.if_oerrors++;
@@ -427,7 +448,7 @@ i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
switch(sc->sc_dialresp)
{
case DSTAT_TFAIL: /* transient failure */
- DBGL4(L4_IPRDBG, "i4biproutput", ("ipr%d: transient dial failure!\n", unit));
+ NDBGL4(L4_IPRDBG, "ipr%d: transient dial failure!", unit);
m_freem(m);
iprclearqueues(sc);
sc->sc_dialresp = DSTAT_NONE;
@@ -437,7 +458,7 @@ i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
break;
case DSTAT_PFAIL: /* permanent failure */
- DBGL4(L4_IPRDBG, "i4biproutput", ("ipr%d: permanent dial failure!\n", unit));
+ NDBGL4(L4_IPRDBG, "ipr%d: permanent dial failure!", unit);
m_freem(m);
iprclearqueues(sc);
sc->sc_dialresp = DSTAT_NONE;
@@ -447,7 +468,7 @@ i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
break;
case DSTAT_INONLY: /* no dialout allowed*/
- DBGL4(L4_IPRDBG, "i4biproutput", ("ipr%d: dialout not allowed failure!\n", unit));
+ NDBGL4(L4_IPRDBG, "ipr%d: dialout not allowed failure!", unit);
m_freem(m);
iprclearqueues(sc);
sc->sc_dialresp = DSTAT_NONE;
@@ -458,8 +479,8 @@ i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
}
#endif
- DBGL4(L4_IPRDBG, "i4biproutput", ("ipr%d: send dial request message!\n", unit));
- DBGL4(L4_DIALST, "i4biproutput", ("ipr%d: setting dial state to ST_DIALING\n", unit));
+ NDBGL4(L4_IPRDBG, "ipr%d: send dial request message!", unit);
+ NDBGL4(L4_DIALST, "ipr%d: setting dial state to ST_DIALING", unit);
i4b_l4_dialout(BDRV_IPR, unit);
sc->sc_state = ST_DIALING;
}
@@ -493,7 +514,7 @@ i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
if(IF_QFULL(ifq))
{
- DBGL4(L4_IPRDBG, "i4biproutput", ("ipr%d: send queue full!\n", unit));
+ NDBGL4(L4_IPRDBG, "ipr%d: send queue full!", unit);
IF_DROP(ifq);
m_freem(m);
splx(s);
@@ -501,7 +522,7 @@ i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
return(ENOBUFS);
}
- DBGL4(L4_IPRDBG, "i4biproutput", ("ipr%d: add packet to send queue!\n", unit));
+ NDBGL4(L4_IPRDBG, "ipr%d: add packet to send queue!", unit);
IF_ENQUEUE(ifq, m);
@@ -747,7 +768,7 @@ ipr_connect(int unit, void *cdp)
s = SPLI4B();
- DBGL4(L4_DIALST, "ipr_connect", ("ipr%d: setting dial state to ST_CONNECTED\n", unit));
+ NDBGL4(L4_DIALST, "ipr%d: setting dial state to ST_CONNECTED", unit);
sc->sc_if.if_flags |= IFF_RUNNING;
sc->sc_state = ST_CONNECTED_W;
@@ -782,7 +803,16 @@ ipr_connect(int unit, void *cdp)
if(sc->sc_cdp->isdntxdelay > 0)
{
- timeout((TIMEOUT_FUNC_T)i4bipr_connect_startio, (void *)sc, sc->sc_cdp->isdntxdelay /* hz*1 */);
+ int delay;
+
+ if (hz == 100) {
+ delay = sc->sc_cdp->isdntxdelay; /* avoid any rounding */
+ } else {
+ delay = sc->sc_cdp->isdntxdelay*hz;
+ delay /= 100;
+ }
+
+ START_TIMER(sc->sc_callout, (TIMEOUT_FUNC_T)i4bipr_connect_startio, (void *)sc, delay);
}
else
{
@@ -809,8 +839,8 @@ ipr_disconnect(int unit, void *cdp)
if (cd != sc->sc_cdp)
{
- DBGL4(L4_IPRDBG, "ipr_disconnect", ("ipr%d: channel %d not active\n",
- cd->driver_unit, cd->channelid));
+ NDBGL4(L4_IPRDBG, "ipr%d: channel %d not active",
+ cd->driver_unit, cd->channelid);
return;
}
@@ -827,7 +857,7 @@ ipr_disconnect(int unit, void *cdp)
sc->sc_cdp = (call_desc_t *)0;
- DBGL4(L4_DIALST, "ipr_disconnect", ("setting dial state to ST_IDLE\n"));
+ NDBGL4(L4_DIALST, "setting dial state to ST_IDLE");
sc->sc_dialresp = DSTAT_NONE;
sc->sc_lastdialresp = DSTAT_NONE;
@@ -846,12 +876,12 @@ ipr_dialresponse(int unit, int status, cause_t cause)
struct ipr_softc *sc = &ipr_softc[unit];
sc->sc_dialresp = status;
- DBGL4(L4_IPRDBG, "ipr_dialresponse", ("ipr%d: last=%d, this=%d\n",
- unit, sc->sc_lastdialresp, sc->sc_dialresp));
+ NDBGL4(L4_IPRDBG, "ipr%d: last=%d, this=%d",
+ unit, sc->sc_lastdialresp, sc->sc_dialresp);
if(status != DSTAT_NONE)
{
- DBGL4(L4_IPRDBG, "ipr_dialresponse", ("ipr%d: clearing queues\n", unit));
+ NDBGL4(L4_IPRDBG, "ipr%d: clearing queues", unit);
iprclearqueues(sc);
}
}
@@ -1045,7 +1075,7 @@ error:
if(IF_QFULL(&ipintrq))
{
- DBGL4(L4_IPRDBG, "ipr_rx_data_rdy", ("ipr%d: ipintrq full!\n", unit));
+ NDBGL4(L4_IPRDBG, "ipr%d: ipintrq full!", unit);
IF_DROP(&ipintrq);
sc->sc_if.if_ierrors++;
@@ -1130,7 +1160,7 @@ ipr_tx_queue_empty(int unit)
if(IF_QFULL(isdn_linktab[unit]->tx_queue))
{
- DBGL4(L4_IPRDBG, "ipr_rx_data_rdy", ("ipr%d: tx queue full!\n", unit));
+ NDBGL4(L4_IPRDBG, "ipr%d: tx queue full!", unit);
m_freem(m);
}
else
diff --git a/sys/i4b/driver/i4b_isppp.c b/sys/i4b/driver/i4b_isppp.c
index a33348c..45ed303 100644
--- a/sys/i4b/driver/i4b_isppp.c
+++ b/sys/i4b/driver/i4b_isppp.c
@@ -1,7 +1,7 @@
/*
* Copyright (c) 1997 Joerg Wunsch. All rights reserved.
*
- * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
+ * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -34,19 +34,33 @@
* the "cx" driver for Cronyx's HDLC-in-hardware device). This driver
* is only the glue between sppp and i4b.
*
- * $Id: i4b_isppp.c,v 1.35 1999/12/13 21:25:24 hm Exp $
+ * $Id: i4b_isppp.c,v 1.44 2000/08/31 07:07:26 hm Exp $
*
* $FreeBSD$
*
- * last edit-date: [Mon Dec 13 21:39:06 1999]
+ * last edit-date: [Thu Aug 31 09:02:27 2000]
*
*---------------------------------------------------------------------------*/
+
+#ifndef __NetBSD__
+#define USE_ISPPP
+#endif
#include "i4bisppp.h"
+#ifndef USE_ISPPP
+
+#ifdef __FreeBSD__
+#include "sppp.h"
+#endif
+
+#ifndef __NetBSD__
#if NI4BISPPP == 0
# error "You need to define `pseudo-device sppp <N>' with options ISPPP"
#endif
+#endif
+
+#endif
#include <sys/param.h>
#include <sys/systm.h>
@@ -71,9 +85,13 @@
#include <net/slcompress.h>
#if defined(__FreeBSD__) || defined(__OpenBSD__)
+#ifndef USE_ISPPP
#include <net/if_sppp.h>
#else
-#include <i4b/sppp/if_sppp.h>
+#include <machine/i4b_isppp.h>
+#endif /* USE_ISPPP */
+#else
+#include <net/if_sppp.h>
#endif
@@ -135,7 +153,7 @@
PDEVSTATIC void i4bispppattach(void *);
PSEUDO_SET(i4bispppattach, i4b_isppp);
#else
-PDEVSTATIC void i4bispppattach __P((void));
+PDEVSTATIC void i4bispppattach(void);
#endif
#define I4BISPPPACCT 1 /* enable accounting messages */
@@ -199,6 +217,7 @@ static void i4bisppp_tlf(struct sppp *sp);
static void i4bisppp_state_changed(struct sppp *sp, int new_state);
static void i4bisppp_negotiation_complete(struct sppp *sp);
static void i4bisppp_watchdog(struct ifnet *ifp);
+time_t i4bisppp_idletime(int unit);
/* initialized by L4 */
@@ -222,7 +241,7 @@ PDEVSTATIC void
#ifdef __FreeBSD__
i4bispppattach(void *dummy)
#else
-i4bispppattach(void)
+i4bispppattach()
#endif
{
struct i4bisppp_softc *sc = i4bisppp_softc;
@@ -253,7 +272,14 @@ i4bispppattach(void)
#endif
sc->sc_if.if_mtu = PP_MTU;
+
+#ifdef __NetBSD__
+ sc->sc_if.if_flags = IFF_SIMPLEX | IFF_POINTOPOINT |
+ IFF_MULTICAST;
+#else
sc->sc_if.if_flags = IFF_SIMPLEX | IFF_POINTOPOINT;
+#endif
+
sc->sc_if.if_type = IFT_ISDNBASIC;
sc->sc_state = ST_IDLE;
@@ -297,8 +323,17 @@ i4bispppattach(void)
sc->sc_if_un.scu_sp.pp_con = i4bisppp_negotiation_complete;
sc->sc_if_un.scu_sp.pp_chg = i4bisppp_state_changed;
+#ifndef USE_ISPPP
sppp_attach(&sc->sc_if);
+#else
+ isppp_attach(&sc->sc_if);
+#endif
+#if defined(__FreeBSD_version) && ((__FreeBSD_version >= 500009) || (410000 <= __FreeBSD_version && __FreeBSD_version < 500000))
+ /* do not call bpfattach in ether_ifattach */
+ ether_ifattach(&sc->sc_if, 0);
+#else
if_attach(&sc->sc_if);
+#endif
#if NBPFILTER > 0 || NBPF > 0
#ifdef __FreeBSD__
@@ -327,7 +362,11 @@ i4bisppp_ioctl(struct ifnet *ifp, IOCTL_CMD_T cmd, caddr_t data)
int error;
+#ifndef USE_ISPPP
error = sppp_ioctl(&sc->sc_if, cmd, data);
+#else
+ error = isppp_ioctl(&sc->sc_if, cmd, data);
+#endif
if (error)
return error;
@@ -356,7 +395,11 @@ i4bisppp_start(struct ifnet *ifp)
/* int s; */
int unit = IFP2UNIT(ifp);
+#ifndef USE_ISPPP
if (sppp_isempty(ifp))
+#else
+ if (isppp_isempty(ifp))
+#endif
return;
if(sc->sc_state != ST_CONNECTED)
@@ -368,7 +411,11 @@ i4bisppp_start(struct ifnet *ifp)
* splx(s);
*/
+#ifndef USE_ISPPP
while ((m = sppp_dequeue(&sc->sc_if)) != NULL)
+#else
+ while ((m = isppp_dequeue(&sc->sc_if)) != NULL)
+#endif
{
#if NBPFILTER > 0 || NBPF > 0
@@ -387,14 +434,15 @@ i4bisppp_start(struct ifnet *ifp)
if(IF_QFULL(isdn_linktab[unit]->tx_queue))
{
- DBGL4(L4_ISPDBG, "i4bisppp_start", ("isp%d, tx queue full!\n", unit));
+ NDBGL4(L4_ISPDBG, "isp%d, tx queue full!", unit);
m_freem(m);
}
else
{
IF_ENQUEUE(isdn_linktab[unit]->tx_queue, m);
-
+#if 0
sc->sc_if.if_obytes += m->m_pkthdr.len;
+#endif
sc->sc_outb += m->m_pkthdr.len;
sc->sc_if.if_opackets++;
}
@@ -554,7 +602,9 @@ i4bisppp_connect(int unit, void *cdp)
#endif
sp->pp_up(sp); /* tell PPP we are ready */
-
+#ifndef __NetBSD__
+ sp->pp_last_sent = sp->pp_last_recv = SECOND;
+#endif
splx(s);
}
@@ -573,7 +623,7 @@ i4bisppp_disconnect(int unit, void *cdp)
/* new stuff to check that the active channel is being closed */
if (cd != sc->sc_cdp)
{
- DBGL4(L4_ISPDBG, "i4bisppp_disconnect", ("isp%d, channel%d not active!\n", unit, cd->channelid));
+ NDBGL4(L4_ISPDBG, "isp%d, channel%d not active!", unit, cd->channelid);
splx(s);
return;
}
@@ -608,17 +658,25 @@ i4bisppp_dialresponse(int unit, int status, cause_t cause)
{
struct i4bisppp_softc *sc = &i4bisppp_softc[unit];
- DBGL4(L4_ISPDBG, "i4bisppp_dialresponse", ("isp%d: status=%d, cause=%d\n", unit, status, cause));
+ NDBGL4(L4_ISPDBG, "isp%d: status=%d, cause=%d", unit, status, cause);
if(status != DSTAT_NONE)
{
struct mbuf *m;
- DBGL4(L4_ISPDBG, "i4bisppp_dialresponse", ("isp%d: clearing queues\n", unit));
+ NDBGL4(L4_ISPDBG, "isp%d: clearing queues", unit);
+#ifndef USE_ISPPP
if(!(sppp_isempty(&sc->sc_if)))
+#else
+ if(!(isppp_isempty(&sc->sc_if)))
+#endif
{
+#ifndef USE_ISPPP
while((m = sppp_dequeue(&sc->sc_if)) != NULL)
+#else
+ while((m = isppp_dequeue(&sc->sc_if)) != NULL)
+#endif
m_freem(m);
}
}
@@ -654,7 +712,9 @@ i4bisppp_rx_data_rdy(int unit)
microtime(&sc->sc_if.if_lastchange);
sc->sc_if.if_ipackets++;
+#if 0
sc->sc_if.if_ibytes += m->m_pkthdr.len;
+#endif
#if I4BISPPPACCT
sc->sc_inb += m->m_pkthdr.len;
@@ -680,7 +740,11 @@ i4bisppp_rx_data_rdy(int unit)
s = splimp();
+#ifndef USE_ISPPP
sppp_input(&sc->sc_if, m);
+#else
+ isppp_input(&sc->sc_if, m);
+#endif
splx(s);
}
@@ -697,6 +761,28 @@ i4bisppp_tx_queue_empty(int unit)
}
/*---------------------------------------------------------------------------*
+ * THIS should be used instead of last_active_time to implement
+ * an activity timeout mechanism.
+ *
+ * Sending back the time difference unneccessarily complicates the
+ * idletime checks in i4b_l4.c. Return the largest time instead.
+ * That way the code in i4b_l4.c needs only minimal changes.
+ *---------------------------------------------------------------------------*/
+time_t
+i4bisppp_idletime(int unit)
+{
+#ifdef __NetBSD__
+ return(i4bisppp_softc[unit].sc_cdp->last_active_time);
+#else
+ struct sppp *sp;
+ sp = (struct sppp *) &i4bisppp_softc[unit];
+
+ return((sp->pp_last_recv < sp->pp_last_sent) ?
+ sp->pp_last_sent : sp->pp_last_recv);
+#endif
+}
+
+/*---------------------------------------------------------------------------*
* this routine is called from the HSCX interrupt handler
* each time a packet is received or transmitted. It should
* be used to implement an activity timeout mechanism.
diff --git a/sys/i4b/driver/i4b_ispppsubr.c b/sys/i4b/driver/i4b_ispppsubr.c
new file mode 100644
index 0000000..a7785e3
--- /dev/null
+++ b/sys/i4b/driver/i4b_ispppsubr.c
@@ -0,0 +1,4612 @@
+/*
+ * Synchronous PPP/Cisco link level subroutines.
+ * Keepalive protocol implemented in both Cisco and PPP modes.
+ *
+ * Copyright (C) 1994-1996 Cronyx Engineering Ltd.
+ * Author: Serge Vakulenko, <vak@cronyx.ru>
+ *
+ * Heavily revamped to conform to RFC 1661.
+ * Copyright (C) 1997, Joerg Wunsch.
+ *
+ * This software is distributed with NO WARRANTIES, not even the implied
+ * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Authors grant any other persons or organisations permission to use
+ * or modify this software as long as this message is kept with the software,
+ * all derivative works or modified versions.
+ *
+ * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997
+ *
+ * From: if_spppsubr.c,v 1.55 1999/03/30 13:28:26 phk Exp
+ *
+ * $Id: i4b_ispppsubr.c,v 1.8 2000/09/01 14:11:51 hm Exp $
+ *
+ * $FreeBSD$
+ */
+
+#define USE_ISPPP
+
+#if defined(__NetBSD__) || (defined(__FreeBSD__) && __FreeBSD__ >= 3)
+#include "opt_inet.h"
+#include "opt_ipx.h"
+#endif
+
+#if defined(__NetBSD__)
+#include "opt_iso.h"
+#include "opt_ns.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sockio.h>
+#include <sys/socket.h>
+#include <sys/syslog.h>
+
+#if defined(__FreeBSD__)
+#if defined (__FreeBSD_version) && __FreeBSD_version <= 400000
+#include <machine/random.h>
+#else
+#include <sys/random.h>
+#endif
+#endif
+
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+
+#if defined (__OpenBSD__)
+#include <sys/md5k.h>
+#else
+#include <sys/md5.h>
+#endif
+
+#include <net/if.h>
+#include <net/netisr.h>
+#include <net/if_types.h>
+#include <net/route.h>
+
+#include <machine/stdarg.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+
+#include <netinet/in.h>
+
+#if !defined (__OpenBSD__)
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#endif
+
+#include <net/slcompress.h>
+
+#if defined (__FreeBSD__) || defined (__OpenBSD__)
+#include <netinet/if_ether.h>
+#else
+#include <net/ethertypes.h>
+#endif
+#else
+#error Huh? sppp without INET?
+#endif
+
+#ifdef IPX
+#include <netipx/ipx.h>
+#include <netipx/ipx_if.h>
+#endif
+
+#ifdef NS
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+
+#ifdef ISO
+#include <netiso/argo_debug.h>
+#include <netiso/iso.h>
+#include <netiso/iso_var.h>
+#include <netiso/iso_snpac.h>
+#endif
+
+#if defined(__FreeBSD__)
+
+#ifndef USE_ISPPP
+#include <net/if_sppp.h>
+#else
+#include <machine/i4b_isppp.h>
+#endif
+
+#else
+#include <i4b/sppp/if_sppp.h>
+#endif
+#if defined(__NetBSD__) || defined (__OpenBSD__)
+#include <machine/cpu.h> /* XXX for softnet */
+#endif
+
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+# define UNTIMEOUT(fun, arg, handle) untimeout(fun, arg, handle)
+# define TIMEOUT(fun, arg1, arg2, handle) handle = timeout(fun, arg1, arg2)
+# define IOCTL_CMD_T u_long
+#else
+# define UNTIMEOUT(fun, arg, handle) untimeout(fun, arg)
+# define TIMEOUT(fun, arg1, arg2, handle) timeout(fun, arg1, arg2)
+#ifdef __FreeBSD__
+# define IOCTL_CMD_T int
+#else
+# define IOCTL_CMD_T u_long
+#endif
+#endif
+
+#if defined(__FreeBSD_version) && (__FreeBSD_version > 300005)
+#define HAS_SNPRINTF
+#endif
+
+#define MAXALIVECNT 3 /* max. alive packets */
+
+/*
+ * Interface flags that can be set in an ifconfig command.
+ *
+ * Setting link0 will make the link passive, i.e. it will be marked
+ * as being administrative openable, but won't be opened to begin
+ * with. Incoming calls will be answered, or subsequent calls with
+ * -link1 will cause the administrative open of the LCP layer.
+ *
+ * Setting link1 will cause the link to auto-dial only as packets
+ * arrive to be sent.
+ *
+ * Setting IFF_DEBUG will syslog the option negotiation and state
+ * transitions at level kern.debug. Note: all logs consistently look
+ * like
+ *
+ * <if-name><unit>: <proto-name> <additional info...>
+ *
+ * with <if-name><unit> being something like "bppp0", and <proto-name>
+ * being one of "lcp", "ipcp", "cisco", "chap", "pap", etc.
+ */
+
+#define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */
+#define IFF_AUTO IFF_LINK1 /* auto-dial on output */
+#define IFF_CISCO IFF_LINK2 /* auto-dial on output */
+
+#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
+#define PPP_UI 0x03 /* Unnumbered Information */
+#define PPP_IP 0x0021 /* Internet Protocol */
+#define PPP_ISO 0x0023 /* ISO OSI Protocol */
+#define PPP_XNS 0x0025 /* Xerox NS Protocol */
+#define PPP_IPX 0x002b /* Novell IPX Protocol */
+#define PPP_VJ_COMP 0x002d /* VJ compressed TCP/IP */
+#define PPP_VJ_UCOMP 0x002f /* VJ uncompressed TCP/IP */
+#define PPP_LCP 0xc021 /* Link Control Protocol */
+#define PPP_PAP 0xc023 /* Password Authentication Protocol */
+#define PPP_CHAP 0xc223 /* Challenge-Handshake Auth Protocol */
+#define PPP_IPCP 0x8021 /* Internet Protocol Control Protocol */
+
+#define CONF_REQ 1 /* PPP configure request */
+#define CONF_ACK 2 /* PPP configure acknowledge */
+#define CONF_NAK 3 /* PPP configure negative ack */
+#define CONF_REJ 4 /* PPP configure reject */
+#define TERM_REQ 5 /* PPP terminate request */
+#define TERM_ACK 6 /* PPP terminate acknowledge */
+#define CODE_REJ 7 /* PPP code reject */
+#define PROTO_REJ 8 /* PPP protocol reject */
+#define ECHO_REQ 9 /* PPP echo request */
+#define ECHO_REPLY 10 /* PPP echo reply */
+#define DISC_REQ 11 /* PPP discard request */
+
+#define LCP_OPT_MRU 1 /* maximum receive unit */
+#define LCP_OPT_ASYNC_MAP 2 /* async control character map */
+#define LCP_OPT_AUTH_PROTO 3 /* authentication protocol */
+#define LCP_OPT_QUAL_PROTO 4 /* quality protocol */
+#define LCP_OPT_MAGIC 5 /* magic number */
+#define LCP_OPT_RESERVED 6 /* reserved */
+#define LCP_OPT_PROTO_COMP 7 /* protocol field compression */
+#define LCP_OPT_ADDR_COMP 8 /* address/control field compression */
+
+#define IPCP_OPT_ADDRESSES 1 /* both IP addresses; deprecated */
+#define IPCP_OPT_COMPRESSION 2 /* IP compression protocol (VJ) */
+#define IPCP_OPT_ADDRESS 3 /* local IP address */
+
+#define IPCP_COMP_VJ 0x2d /* Code for VJ compression */
+
+#define PAP_REQ 1 /* PAP name/password request */
+#define PAP_ACK 2 /* PAP acknowledge */
+#define PAP_NAK 3 /* PAP fail */
+
+#define CHAP_CHALLENGE 1 /* CHAP challenge request */
+#define CHAP_RESPONSE 2 /* CHAP challenge response */
+#define CHAP_SUCCESS 3 /* CHAP response ok */
+#define CHAP_FAILURE 4 /* CHAP response failed */
+
+#define CHAP_MD5 5 /* hash algorithm - MD5 */
+
+#define CISCO_MULTICAST 0x8f /* Cisco multicast address */
+#define CISCO_UNICAST 0x0f /* Cisco unicast address */
+#define CISCO_KEEPALIVE 0x8035 /* Cisco keepalive protocol */
+#define CISCO_ADDR_REQ 0 /* Cisco address request */
+#define CISCO_ADDR_REPLY 1 /* Cisco address reply */
+#define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */
+
+/* states are named and numbered according to RFC 1661 */
+#define STATE_INITIAL 0
+#define STATE_STARTING 1
+#define STATE_CLOSED 2
+#define STATE_STOPPED 3
+#define STATE_CLOSING 4
+#define STATE_STOPPING 5
+#define STATE_REQ_SENT 6
+#define STATE_ACK_RCVD 7
+#define STATE_ACK_SENT 8
+#define STATE_OPENED 9
+
+struct ppp_header {
+ u_char address;
+ u_char control;
+ u_short protocol;
+};
+#define PPP_HEADER_LEN sizeof (struct ppp_header)
+
+struct lcp_header {
+ u_char type;
+ u_char ident;
+ u_short len;
+};
+#define LCP_HEADER_LEN sizeof (struct lcp_header)
+
+struct cisco_packet {
+ u_long type;
+ u_long par1;
+ u_long par2;
+ u_short rel;
+ u_short time0;
+ u_short time1;
+};
+#define CISCO_PACKET_LEN 18
+
+/*
+ * We follow the spelling and capitalization of RFC 1661 here, to make
+ * it easier comparing with the standard. Please refer to this RFC in
+ * case you can't make sense out of these abbreviation; it will also
+ * explain the semantics related to the various events and actions.
+ */
+struct cp {
+ u_short proto; /* PPP control protocol number */
+ u_char protoidx; /* index into state table in struct sppp */
+ u_char flags;
+#define CP_LCP 0x01 /* this is the LCP */
+#define CP_AUTH 0x02 /* this is an authentication protocol */
+#define CP_NCP 0x04 /* this is a NCP */
+#define CP_QUAL 0x08 /* this is a quality reporting protocol */
+ const char *name; /* name of this control protocol */
+ /* event handlers */
+ void (*Up)(struct sppp *sp);
+ void (*Down)(struct sppp *sp);
+ void (*Open)(struct sppp *sp);
+ void (*Close)(struct sppp *sp);
+ void (*TO)(void *sp);
+ int (*RCR)(struct sppp *sp, struct lcp_header *h, int len);
+ void (*RCN_rej)(struct sppp *sp, struct lcp_header *h, int len);
+ void (*RCN_nak)(struct sppp *sp, struct lcp_header *h, int len);
+ /* actions */
+ void (*tlu)(struct sppp *sp);
+ void (*tld)(struct sppp *sp);
+ void (*tls)(struct sppp *sp);
+ void (*tlf)(struct sppp *sp);
+ void (*scr)(struct sppp *sp);
+};
+
+static struct sppp *spppq;
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+static struct callout_handle keepalive_ch;
+#endif
+
+#if defined(__FreeBSD__)
+#define SPP_FMT "%s%d: "
+#define SPP_ARGS(ifp) (ifp)->if_name, (ifp)->if_unit
+#else
+#define SPP_FMT "%s: "
+#define SPP_ARGS(ifp) (ifp)->if_xname
+#endif
+
+/*
+ * The following disgusting hack gets around the problem that IP TOS
+ * can't be set yet. We want to put "interactive" traffic on a high
+ * priority queue. To decide if traffic is interactive, we check that
+ * a) it is TCP and b) one of its ports is telnet, rlogin or ftp control.
+ *
+ * XXX is this really still necessary? - joerg -
+ */
+static u_short interactive_ports[8] = {
+ 0, 513, 0, 0,
+ 0, 21, 0, 23,
+};
+#define INTERACTIVE(p) (interactive_ports[(p) & 7] == (p))
+
+/* almost every function needs these */
+#define STDDCL \
+ struct ifnet *ifp = &sp->pp_if; \
+ int debug = ifp->if_flags & IFF_DEBUG
+
+static int sppp_output(struct ifnet *ifp, struct mbuf *m,
+ struct sockaddr *dst, struct rtentry *rt);
+
+static void sppp_cisco_send(struct sppp *sp, int type, long par1, long par2);
+static void sppp_cisco_input(struct sppp *sp, struct mbuf *m);
+
+static void sppp_cp_input(const struct cp *cp, struct sppp *sp,
+ struct mbuf *m);
+static void sppp_cp_send(struct sppp *sp, u_short proto, u_char type,
+ u_char ident, u_short len, void *data);
+/* static void sppp_cp_timeout(void *arg); */
+static void sppp_cp_change_state(const struct cp *cp, struct sppp *sp,
+ int newstate);
+static void sppp_auth_send(const struct cp *cp,
+ struct sppp *sp, unsigned int type, unsigned int id,
+ ...);
+
+static void sppp_up_event(const struct cp *cp, struct sppp *sp);
+static void sppp_down_event(const struct cp *cp, struct sppp *sp);
+static void sppp_open_event(const struct cp *cp, struct sppp *sp);
+static void sppp_close_event(const struct cp *cp, struct sppp *sp);
+static void sppp_to_event(const struct cp *cp, struct sppp *sp);
+
+static void sppp_null(struct sppp *sp);
+
+static void sppp_lcp_init(struct sppp *sp);
+static void sppp_lcp_up(struct sppp *sp);
+static void sppp_lcp_down(struct sppp *sp);
+static void sppp_lcp_open(struct sppp *sp);
+static void sppp_lcp_close(struct sppp *sp);
+static void sppp_lcp_TO(void *sp);
+static int sppp_lcp_RCR(struct sppp *sp, struct lcp_header *h, int len);
+static void sppp_lcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len);
+static void sppp_lcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len);
+static void sppp_lcp_tlu(struct sppp *sp);
+static void sppp_lcp_tld(struct sppp *sp);
+static void sppp_lcp_tls(struct sppp *sp);
+static void sppp_lcp_tlf(struct sppp *sp);
+static void sppp_lcp_scr(struct sppp *sp);
+static void sppp_lcp_check_and_close(struct sppp *sp);
+static int sppp_ncp_check(struct sppp *sp);
+
+static void sppp_ipcp_init(struct sppp *sp);
+static void sppp_ipcp_up(struct sppp *sp);
+static void sppp_ipcp_down(struct sppp *sp);
+static void sppp_ipcp_open(struct sppp *sp);
+static void sppp_ipcp_close(struct sppp *sp);
+static void sppp_ipcp_TO(void *sp);
+static int sppp_ipcp_RCR(struct sppp *sp, struct lcp_header *h, int len);
+static void sppp_ipcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len);
+static void sppp_ipcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len);
+static void sppp_ipcp_tlu(struct sppp *sp);
+static void sppp_ipcp_tld(struct sppp *sp);
+static void sppp_ipcp_tls(struct sppp *sp);
+static void sppp_ipcp_tlf(struct sppp *sp);
+static void sppp_ipcp_scr(struct sppp *sp);
+
+static void sppp_pap_input(struct sppp *sp, struct mbuf *m);
+static void sppp_pap_init(struct sppp *sp);
+static void sppp_pap_open(struct sppp *sp);
+static void sppp_pap_close(struct sppp *sp);
+static void sppp_pap_TO(void *sp);
+static void sppp_pap_my_TO(void *sp);
+static void sppp_pap_tlu(struct sppp *sp);
+static void sppp_pap_tld(struct sppp *sp);
+static void sppp_pap_scr(struct sppp *sp);
+
+static void sppp_chap_input(struct sppp *sp, struct mbuf *m);
+static void sppp_chap_init(struct sppp *sp);
+static void sppp_chap_open(struct sppp *sp);
+static void sppp_chap_close(struct sppp *sp);
+static void sppp_chap_TO(void *sp);
+static void sppp_chap_tlu(struct sppp *sp);
+static void sppp_chap_tld(struct sppp *sp);
+static void sppp_chap_scr(struct sppp *sp);
+
+static const char *sppp_auth_type_name(u_short proto, u_char type);
+static const char *sppp_cp_type_name(u_char type);
+static const char *sppp_dotted_quad(u_long addr);
+static const char *sppp_ipcp_opt_name(u_char opt);
+static const char *sppp_lcp_opt_name(u_char opt);
+static const char *sppp_phase_name(enum ppp_phase phase);
+static const char *sppp_proto_name(u_short proto);
+static const char *sppp_state_name(int state);
+static int sppp_params(struct sppp *sp, IOCTL_CMD_T cmd, void *data);
+static int sppp_strnlen(u_char *p, int max);
+static void sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst,
+ u_long *srcmask);
+static void sppp_keepalive(void *dummy);
+static void sppp_phase_network(struct sppp *sp);
+static void sppp_print_bytes(const u_char *p, u_short len);
+static void sppp_print_string(const char *p, u_short len);
+static void sppp_qflush(struct ifqueue *ifq);
+static void sppp_set_ip_addr(struct sppp *sp, u_long src);
+
+/* our control protocol descriptors */
+static const struct cp lcp = {
+ PPP_LCP, IDX_LCP, CP_LCP, "lcp",
+ sppp_lcp_up, sppp_lcp_down, sppp_lcp_open, sppp_lcp_close,
+ sppp_lcp_TO, sppp_lcp_RCR, sppp_lcp_RCN_rej, sppp_lcp_RCN_nak,
+ sppp_lcp_tlu, sppp_lcp_tld, sppp_lcp_tls, sppp_lcp_tlf,
+ sppp_lcp_scr
+};
+
+static const struct cp ipcp = {
+ PPP_IPCP, IDX_IPCP, CP_NCP, "ipcp",
+ sppp_ipcp_up, sppp_ipcp_down, sppp_ipcp_open, sppp_ipcp_close,
+ sppp_ipcp_TO, sppp_ipcp_RCR, sppp_ipcp_RCN_rej, sppp_ipcp_RCN_nak,
+ sppp_ipcp_tlu, sppp_ipcp_tld, sppp_ipcp_tls, sppp_ipcp_tlf,
+ sppp_ipcp_scr
+};
+
+static const struct cp pap = {
+ PPP_PAP, IDX_PAP, CP_AUTH, "pap",
+ sppp_null, sppp_null, sppp_pap_open, sppp_pap_close,
+ sppp_pap_TO, 0, 0, 0,
+ sppp_pap_tlu, sppp_pap_tld, sppp_null, sppp_null,
+ sppp_pap_scr
+};
+
+static const struct cp chap = {
+ PPP_CHAP, IDX_CHAP, CP_AUTH, "chap",
+ sppp_null, sppp_null, sppp_chap_open, sppp_chap_close,
+ sppp_chap_TO, 0, 0, 0,
+ sppp_chap_tlu, sppp_chap_tld, sppp_null, sppp_null,
+ sppp_chap_scr
+};
+
+static const struct cp *cps[IDX_COUNT] = {
+ &lcp, /* IDX_LCP */
+ &ipcp, /* IDX_IPCP */
+ &pap, /* IDX_PAP */
+ &chap, /* IDX_CHAP */
+};
+
+
+ /*
+ * Exported functions, comprising our interface to the lower layer.
+ */
+
+/*
+ * Process the received packet.
+ */
+void
+#ifndef USE_ISPPP
+sppp_input(struct ifnet *ifp, struct mbuf *m)
+#else
+isppp_input(struct ifnet *ifp, struct mbuf *m)
+#endif
+{
+ struct ppp_header *h;
+ struct ifqueue *inq = 0;
+ int s;
+ struct sppp *sp = (struct sppp *)ifp;
+ int debug = ifp->if_flags & IFF_DEBUG;
+
+ if (ifp->if_flags & IFF_UP)
+ /* Count received bytes, add FCS and one flag */
+ ifp->if_ibytes += m->m_pkthdr.len + 3;
+
+ if (m->m_pkthdr.len <= PPP_HEADER_LEN) {
+ /* Too small packet, drop it. */
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "input packet is too small, %d bytes\n",
+ SPP_ARGS(ifp), m->m_pkthdr.len);
+ drop:
+ ++ifp->if_ierrors;
+ ++ifp->if_iqdrops;
+ m_freem (m);
+ return;
+ }
+
+ /* Get PPP header. */
+ h = mtod (m, struct ppp_header*);
+ m_adj (m, PPP_HEADER_LEN);
+
+ switch (h->address) {
+ case PPP_ALLSTATIONS:
+ if (h->control != PPP_UI)
+ goto invalid;
+ if (sp->pp_mode == IFF_CISCO) {
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "PPP packet in Cisco mode "
+ "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
+ SPP_ARGS(ifp),
+ h->address, h->control, ntohs(h->protocol));
+ goto drop;
+ }
+ switch (ntohs (h->protocol)) {
+ default:
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "rejecting protocol "
+ "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
+ SPP_ARGS(ifp),
+ h->address, h->control, ntohs(h->protocol));
+
+ if (sp->state[IDX_LCP] == STATE_OPENED)
+ sppp_cp_send (sp, PPP_LCP, PROTO_REJ,
+ ++sp->pp_seq, m->m_pkthdr.len + 2,
+ &h->protocol);
+
+ ++ifp->if_noproto;
+ goto drop;
+ case PPP_LCP:
+ sppp_cp_input(&lcp, sp, m);
+ m_freem (m);
+ return;
+ case PPP_PAP:
+ if (sp->pp_phase >= PHASE_AUTHENTICATE)
+ sppp_pap_input(sp, m);
+ m_freem (m);
+ return;
+ case PPP_CHAP:
+ if (sp->pp_phase >= PHASE_AUTHENTICATE)
+ sppp_chap_input(sp, m);
+ m_freem (m);
+ return;
+#ifdef INET
+ case PPP_IPCP:
+ if (sp->pp_phase == PHASE_NETWORK)
+ sppp_cp_input(&ipcp, sp, m);
+ m_freem (m);
+ return;
+ case PPP_IP:
+ if (sp->state[IDX_IPCP] == STATE_OPENED) {
+ schednetisr (NETISR_IP);
+ inq = &ipintrq;
+ }
+ break;
+#ifdef SPPP_VJ
+ case PPP_VJ_COMP:
+ if (sp->state[IDX_IPCP] == STATE_OPENED) {
+ int len;
+
+ if ((len = sl_uncompress_tcp(
+ (u_char **)&m->m_data, m->m_len,
+ TYPE_COMPRESSED_TCP, &sp->pp_comp)) <= 0)
+ goto drop;
+ m->m_len = m->m_pkthdr.len = len;
+ schednetisr (NETISR_IP);
+ inq = &ipintrq;
+ }
+ break;
+ case PPP_VJ_UCOMP:
+ if (sp->state[IDX_IPCP] == STATE_OPENED) {
+ int len;
+
+ if ((len = sl_uncompress_tcp(
+ (u_char **)&m->m_data, m->m_len,
+ TYPE_UNCOMPRESSED_TCP, &sp->pp_comp)) <= 0)
+ goto drop;
+ m->m_len = m->m_pkthdr.len = len;
+ schednetisr (NETISR_IP);
+ inq = &ipintrq;
+ }
+ break;
+#endif
+#endif
+#ifdef IPX
+ case PPP_IPX:
+ /* IPX IPXCP not implemented yet */
+ if (sp->pp_phase == PHASE_NETWORK) {
+ schednetisr (NETISR_IPX);
+ inq = &ipxintrq;
+ }
+ break;
+#endif
+#ifdef NS
+ case PPP_XNS:
+ /* XNS IDPCP not implemented yet */
+ if (sp->pp_phase == PHASE_NETWORK) {
+ schednetisr (NETISR_NS);
+ inq = &nsintrq;
+ }
+ break;
+#endif
+#ifdef ISO
+ case PPP_ISO:
+ /* OSI NLCP not implemented yet */
+ if (sp->pp_phase == PHASE_NETWORK) {
+ schednetisr (NETISR_ISO);
+ inq = &clnlintrq;
+ }
+ break;
+#endif
+ }
+ break;
+ case CISCO_MULTICAST:
+ case CISCO_UNICAST:
+ /* Don't check the control field here (RFC 1547). */
+ if (sp->pp_mode != IFF_CISCO) {
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "Cisco packet in PPP mode "
+ "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
+ SPP_ARGS(ifp),
+ h->address, h->control, ntohs(h->protocol));
+ goto drop;
+ }
+ switch (ntohs (h->protocol)) {
+ default:
+ ++ifp->if_noproto;
+ goto invalid;
+ case CISCO_KEEPALIVE:
+ sppp_cisco_input ((struct sppp*) ifp, m);
+ m_freem (m);
+ return;
+#ifdef INET
+ case ETHERTYPE_IP:
+ schednetisr (NETISR_IP);
+ inq = &ipintrq;
+ break;
+#endif
+#ifdef IPX
+ case ETHERTYPE_IPX:
+ schednetisr (NETISR_IPX);
+ inq = &ipxintrq;
+ break;
+#endif
+#ifdef NS
+ case ETHERTYPE_NS:
+ schednetisr (NETISR_NS);
+ inq = &nsintrq;
+ break;
+#endif
+ }
+ break;
+ default: /* Invalid PPP packet. */
+ invalid:
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "invalid input packet "
+ "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
+ SPP_ARGS(ifp),
+ h->address, h->control, ntohs(h->protocol));
+ goto drop;
+ }
+
+ if (! (ifp->if_flags & IFF_UP) || ! inq)
+ goto drop;
+
+ /* Check queue. */
+ s = splimp();
+ if (IF_QFULL (inq)) {
+ /* Queue overflow. */
+ IF_DROP(inq);
+ splx(s);
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "protocol queue overflow\n",
+ SPP_ARGS(ifp));
+ goto drop;
+ }
+ IF_ENQUEUE(inq, m);
+ sp->pp_last_recv = time_second;
+ splx(s);
+}
+
+/*
+ * Enqueue transmit packet.
+ */
+static int
+sppp_output(struct ifnet *ifp, struct mbuf *m,
+ struct sockaddr *dst, struct rtentry *rt)
+{
+ struct sppp *sp = (struct sppp*) ifp;
+ struct ppp_header *h;
+ struct ifqueue *ifq;
+ int s, rv = 0;
+ int debug = ifp->if_flags & IFF_DEBUG;
+#ifdef SPPP_VJ
+ int ipproto = PPP_IP;
+#endif
+
+ s = splimp();
+
+ if ((ifp->if_flags & IFF_UP) == 0 ||
+ (ifp->if_flags & (IFF_RUNNING | IFF_AUTO)) == 0) {
+ m_freem (m);
+ splx (s);
+ return (ENETDOWN);
+ }
+
+ if ((ifp->if_flags & (IFF_RUNNING | IFF_AUTO)) == IFF_AUTO) {
+ /*
+ * Interface is not yet running, but auto-dial. Need
+ * to start LCP for it.
+ */
+ ifp->if_flags |= IFF_RUNNING;
+ splx(s);
+ lcp.Open(sp);
+ s = splimp();
+ }
+
+ ifq = &ifp->if_snd;
+
+#ifdef INET
+ if (dst->sa_family == AF_INET) {
+ /* XXX Check mbuf length here? */
+ struct ip *ip = mtod (m, struct ip*);
+ struct tcphdr *tcp = (struct tcphdr*) ((long*)ip + ip->ip_hl);
+
+ /*
+ * When using dynamic local IP address assignment by using
+ * 0.0.0.0 as a local address, the first TCP session will
+ * not connect because the local TCP checksum is computed
+ * using 0.0.0.0 which will later become our real IP address
+ * so the TCP checksum computed at the remote end will
+ * become invalid. So we
+ * - don't let packets with src ip addr 0 thru
+ * - we flag TCP packets with src ip 0 as an error
+ */
+
+ if(ip->ip_src.s_addr == INADDR_ANY) /* -hm */
+ {
+ m_freem(m);
+ splx(s);
+ if(ip->ip_p == IPPROTO_TCP)
+ return(EADDRNOTAVAIL);
+ else
+ return(0);
+ }
+
+ /*
+ * Put low delay, telnet, rlogin and ftp control packets
+ * in front of the queue.
+ */
+ if (IF_QFULL (&sp->pp_fastq))
+ ;
+ else if (ip->ip_tos & IPTOS_LOWDELAY)
+ ifq = &sp->pp_fastq;
+ else if (m->m_len < sizeof *ip + sizeof *tcp)
+ ;
+ else if (ip->ip_p != IPPROTO_TCP)
+ ;
+ else if (INTERACTIVE (ntohs (tcp->th_sport)))
+ ifq = &sp->pp_fastq;
+ else if (INTERACTIVE (ntohs (tcp->th_dport)))
+ ifq = &sp->pp_fastq;
+
+#ifdef SPPP_VJ
+ /*
+ * Do IP Header compression
+ */
+ if (sp->pp_mode != IFF_CISCO &&
+ (sp->ipcp.flags & IPCP_VJ) &&
+ ip->ip_p == IPPROTO_TCP)
+ {
+ switch (sl_compress_tcp(m, ip, &sp->pp_comp,
+ sp->ipcp.compress_cid)) {
+ case TYPE_COMPRESSED_TCP:
+ ipproto = PPP_VJ_COMP;
+ break;
+ case TYPE_UNCOMPRESSED_TCP:
+ ipproto = PPP_VJ_UCOMP;
+ break;
+ case TYPE_IP:
+ ipproto = PPP_IP;
+ break;
+ default:
+ m_freem(m);
+ splx(s);
+ return (EINVAL);
+ }
+ }
+#endif
+ }
+#endif
+
+ /*
+ * Prepend general data packet PPP header. For now, IP only.
+ */
+ M_PREPEND (m, PPP_HEADER_LEN, M_DONTWAIT);
+ if (! m) {
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "no memory for transmit header\n",
+ SPP_ARGS(ifp));
+ ++ifp->if_oerrors;
+ splx (s);
+ return (ENOBUFS);
+ }
+ /*
+ * May want to check size of packet
+ * (albeit due to the implementation it's always enough)
+ */
+ h = mtod (m, struct ppp_header*);
+ if (sp->pp_mode == IFF_CISCO) {
+ h->address = CISCO_UNICAST; /* unicast address */
+ h->control = 0;
+ } else {
+ h->address = PPP_ALLSTATIONS; /* broadcast address */
+ h->control = PPP_UI; /* Unnumbered Info */
+ }
+
+ switch (dst->sa_family) {
+#ifdef INET
+ case AF_INET: /* Internet Protocol */
+ if (sp->pp_mode == IFF_CISCO)
+ h->protocol = htons (ETHERTYPE_IP);
+ else {
+ /*
+ * Don't choke with an ENETDOWN early. It's
+ * possible that we just started dialing out,
+ * so don't drop the packet immediately. If
+ * we notice that we run out of buffer space
+ * below, we will however remember that we are
+ * not ready to carry IP packets, and return
+ * ENETDOWN, as opposed to ENOBUFS.
+ */
+#ifdef SPPP_VJ
+ h->protocol = htons(ipproto);
+#else
+ h->protocol = htons(PPP_IP);
+#endif
+ if (sp->state[IDX_IPCP] != STATE_OPENED)
+ rv = ENETDOWN;
+ }
+ break;
+#endif
+#ifdef NS
+ case AF_NS: /* Xerox NS Protocol */
+ h->protocol = htons (sp->pp_mode == IFF_CISCO ?
+ ETHERTYPE_NS : PPP_XNS);
+ break;
+#endif
+#ifdef IPX
+ case AF_IPX: /* Novell IPX Protocol */
+ h->protocol = htons (sp->pp_mode == IFF_CISCO ?
+ ETHERTYPE_IPX : PPP_IPX);
+ break;
+#endif
+#ifdef ISO
+ case AF_ISO: /* ISO OSI Protocol */
+ if (sp->pp_mode == IFF_CISCO)
+ goto nosupport;
+ h->protocol = htons (PPP_ISO);
+ break;
+nosupport:
+#endif
+ default:
+ m_freem (m);
+ ++ifp->if_oerrors;
+ splx (s);
+ return (EAFNOSUPPORT);
+ }
+
+ /*
+ * Queue message on interface, and start output if interface
+ * not yet active.
+ */
+ if (IF_QFULL (ifq)) {
+ IF_DROP (&ifp->if_snd);
+ m_freem (m);
+ ++ifp->if_oerrors;
+ splx (s);
+ return (rv? rv: ENOBUFS);
+ }
+ IF_ENQUEUE (ifq, m);
+ if (! (ifp->if_flags & IFF_OACTIVE))
+ (*ifp->if_start) (ifp);
+
+ /*
+ * Count output packets and bytes.
+ * The packet length includes header, FCS and 1 flag,
+ * according to RFC 1333.
+ */
+ ifp->if_obytes += m->m_pkthdr.len + 3;
+ sp->pp_last_sent = time_second;
+ splx (s);
+ return (0);
+}
+
+void
+#ifndef USE_ISPPP
+sppp_attach(struct ifnet *ifp)
+#else
+isppp_attach(struct ifnet *ifp)
+#endif
+{
+ struct sppp *sp = (struct sppp*) ifp;
+
+ /* Initialize keepalive handler. */
+ if (! spppq)
+ TIMEOUT(sppp_keepalive, 0, hz * 10, keepalive_ch);
+
+ /* Insert new entry into the keepalive list. */
+ sp->pp_next = spppq;
+ spppq = sp;
+
+ sp->pp_if.if_mtu = PP_MTU;
+ sp->pp_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
+ sp->pp_if.if_type = IFT_PPP;
+ sp->pp_if.if_output = sppp_output;
+
+#if 0
+ sp->pp_flags = PP_KEEPALIVE;
+#endif
+
+ sp->pp_fastq.ifq_maxlen = 32;
+ sp->pp_cpq.ifq_maxlen = 20;
+ sp->pp_loopcnt = 0;
+ sp->pp_alivecnt = 0;
+ sp->pp_seq = 0;
+ sp->pp_rseq = 0;
+ sp->pp_phase = PHASE_DEAD;
+ sp->pp_up = lcp.Up;
+ sp->pp_down = lcp.Down;
+
+#ifdef SPPP_VJ
+ sp->enable_vj = 1;
+#ifdef __FreeBSD__
+ sl_compress_init(&sp->pp_comp, -1);
+#else
+ sl_compress_init(&sp->pp_comp);
+#endif
+#endif
+
+ sp->pp_last_recv = sp->pp_last_sent = time_second;
+ sppp_lcp_init(sp);
+ sppp_ipcp_init(sp);
+ sppp_pap_init(sp);
+ sppp_chap_init(sp);
+}
+
+void
+#ifndef USE_ISPPP
+sppp_detach(struct ifnet *ifp)
+#else
+isppp_detach(struct ifnet *ifp)
+#endif
+{
+ struct sppp **q, *p, *sp = (struct sppp*) ifp;
+ int i;
+
+ /* Remove the entry from the keepalive list. */
+ for (q = &spppq; (p = *q); q = &p->pp_next)
+ if (p == sp) {
+ *q = p->pp_next;
+ break;
+ }
+
+ /* Stop keepalive handler. */
+ if (! spppq)
+ UNTIMEOUT(sppp_keepalive, 0, keepalive_ch);
+
+ for (i = 0; i < IDX_COUNT; i++)
+ UNTIMEOUT((cps[i])->TO, (void *)sp, sp->ch[i]);
+
+ UNTIMEOUT(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch);
+}
+
+/*
+ * Flush the interface output queue.
+ */
+void
+#ifndef USE_ISPPP
+sppp_flush(struct ifnet *ifp)
+#else
+isppp_flush(struct ifnet *ifp)
+#endif
+{
+ struct sppp *sp = (struct sppp*) ifp;
+
+ sppp_qflush (&sp->pp_if.if_snd);
+ sppp_qflush (&sp->pp_fastq);
+ sppp_qflush (&sp->pp_cpq);
+}
+
+/*
+ * Check if the output queue is empty.
+ */
+int
+#ifndef USE_ISPPP
+sppp_isempty(struct ifnet *ifp)
+#else
+isppp_isempty(struct ifnet *ifp)
+#endif
+{
+ struct sppp *sp = (struct sppp*) ifp;
+ int empty, s;
+
+ s = splimp();
+ empty = !sp->pp_fastq.ifq_head && !sp->pp_cpq.ifq_head &&
+ !sp->pp_if.if_snd.ifq_head;
+ splx(s);
+ return (empty);
+}
+
+/*
+ * Get next packet to send.
+ */
+struct mbuf *
+#ifndef USE_ISPPP
+sppp_dequeue(struct ifnet *ifp)
+#else
+isppp_dequeue(struct ifnet *ifp)
+#endif
+{
+ struct sppp *sp = (struct sppp*) ifp;
+ struct mbuf *m;
+ int s;
+
+ s = splimp();
+ /*
+ * Process only the control protocol queue until we have at
+ * least one NCP open.
+ *
+ * Do always serve all three queues in Cisco mode.
+ */
+ IF_DEQUEUE(&sp->pp_cpq, m);
+ if (m == NULL &&
+ (sppp_ncp_check(sp) || sp->pp_mode == IFF_CISCO)) {
+ IF_DEQUEUE(&sp->pp_fastq, m);
+ if (m == NULL)
+ IF_DEQUEUE (&sp->pp_if.if_snd, m);
+ }
+ splx(s);
+ return m;
+}
+
+/*
+ * Pick the next packet, do not remove it from the queue.
+ */
+struct mbuf *
+#ifndef USE_ISPPP
+sppp_pick(struct ifnet *ifp)
+#else
+isppp_pick(struct ifnet *ifp)
+#endif
+{
+ struct sppp *sp = (struct sppp*)ifp;
+ struct mbuf *m;
+ int s;
+
+ s= splimp ();
+
+ m = sp->pp_cpq.ifq_head;
+ if (m == NULL &&
+ (sp->pp_phase == PHASE_NETWORK || sp->pp_mode == IFF_CISCO))
+ if ((m = sp->pp_fastq.ifq_head) == NULL)
+ m = sp->pp_if.if_snd.ifq_head;
+ splx (s);
+ return (m);
+}
+
+/*
+ * Process an ioctl request. Called on low priority level.
+ */
+int
+#ifndef USE_ISPPP
+sppp_ioctl(struct ifnet *ifp, IOCTL_CMD_T cmd, void *data)
+#else
+isppp_ioctl(struct ifnet *ifp, IOCTL_CMD_T cmd, void *data)
+#endif
+{
+ struct ifreq *ifr = (struct ifreq*) data;
+ struct sppp *sp = (struct sppp*) ifp;
+ int s, rv, going_up, going_down, newmode;
+
+ s = splimp();
+ rv = 0;
+ switch (cmd) {
+ case SIOCAIFADDR:
+ case SIOCSIFDSTADDR:
+ break;
+
+ case SIOCSIFADDR:
+ if_up(ifp);
+ /* fall through... */
+
+ case SIOCSIFFLAGS:
+ going_up = ifp->if_flags & IFF_UP &&
+ (ifp->if_flags & IFF_RUNNING) == 0;
+ going_down = (ifp->if_flags & IFF_UP) == 0 &&
+ ifp->if_flags & IFF_RUNNING;
+
+ newmode = ifp->if_flags & IFF_PASSIVE;
+ if (!newmode)
+ newmode = ifp->if_flags & IFF_AUTO;
+ if (!newmode)
+ newmode = ifp->if_flags & IFF_CISCO;
+ ifp->if_flags &= ~(IFF_PASSIVE | IFF_AUTO | IFF_CISCO);
+ ifp->if_flags |= newmode;
+
+ if (newmode != sp->pp_mode) {
+ going_down = 1;
+ if (!going_up)
+ going_up = ifp->if_flags & IFF_RUNNING;
+ }
+
+ if (going_down) {
+ if (sp->pp_mode != IFF_CISCO)
+ lcp.Close(sp);
+ else if (sp->pp_tlf)
+ (sp->pp_tlf)(sp);
+
+#ifndef USE_ISPPP
+ sppp_flush(ifp);
+#else
+ isppp_flush(ifp);
+#endif
+ ifp->if_flags &= ~IFF_RUNNING;
+ sp->pp_mode = newmode;
+ }
+
+ if (going_up) {
+ if (sp->pp_mode != IFF_CISCO)
+ lcp.Close(sp);
+ sp->pp_mode = newmode;
+ if (sp->pp_mode == 0) {
+ ifp->if_flags |= IFF_RUNNING;
+ lcp.Open(sp);
+ }
+ if (sp->pp_mode == IFF_CISCO) {
+ if (sp->pp_tls)
+ (sp->pp_tls)(sp);
+ ifp->if_flags |= IFF_RUNNING;
+ }
+ }
+
+ break;
+
+#ifdef SIOCSIFMTU
+#ifndef ifr_mtu
+#define ifr_mtu ifr_metric
+#endif
+ case SIOCSIFMTU:
+ if (ifr->ifr_mtu < 128 || ifr->ifr_mtu > sp->lcp.their_mru)
+ return (EINVAL);
+ ifp->if_mtu = ifr->ifr_mtu;
+ break;
+#endif
+#ifdef SLIOCSETMTU
+ case SLIOCSETMTU:
+ if (*(short*)data < 128 || *(short*)data > sp->lcp.their_mru)
+ return (EINVAL);
+ ifp->if_mtu = *(short*)data;
+ break;
+#endif
+#ifdef SIOCGIFMTU
+ case SIOCGIFMTU:
+ ifr->ifr_mtu = ifp->if_mtu;
+ break;
+#endif
+#ifdef SLIOCGETMTU
+ case SLIOCGETMTU:
+ *(short*)data = ifp->if_mtu;
+ break;
+#endif
+ case SIOCADDMULTI:
+ case SIOCDELMULTI:
+ break;
+
+ case SIOCGIFGENERIC:
+ case SIOCSIFGENERIC:
+ rv = sppp_params(sp, cmd, data);
+ break;
+
+ default:
+ rv = ENOTTY;
+ }
+ splx(s);
+ return rv;
+}
+
+
+ /*
+ * Cisco framing implementation.
+ */
+
+/*
+ * Handle incoming Cisco keepalive protocol packets.
+ */
+static void
+sppp_cisco_input(struct sppp *sp, struct mbuf *m)
+{
+ STDDCL;
+ struct cisco_packet *h;
+ u_long me, mymask;
+
+ if (m->m_pkthdr.len < CISCO_PACKET_LEN) {
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "cisco invalid packet length: %d bytes\n",
+ SPP_ARGS(ifp), m->m_pkthdr.len);
+ return;
+ }
+ h = mtod (m, struct cisco_packet*);
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "cisco input: %d bytes "
+ "<0x%lx 0x%lx 0x%lx 0x%x 0x%x-0x%x>\n",
+ SPP_ARGS(ifp), m->m_pkthdr.len,
+ (u_long)ntohl (h->type), (u_long)h->par1, (u_long)h->par2, (u_int)h->rel,
+ (u_int)h->time0, (u_int)h->time1);
+ switch (ntohl (h->type)) {
+ default:
+ if (debug)
+ addlog(SPP_FMT "cisco unknown packet type: 0x%lx\n",
+ SPP_ARGS(ifp), (u_long)ntohl (h->type));
+ break;
+ case CISCO_ADDR_REPLY:
+ /* Reply on address request, ignore */
+ break;
+ case CISCO_KEEPALIVE_REQ:
+ sp->pp_alivecnt = 0;
+ sp->pp_rseq = ntohl (h->par1);
+ if (sp->pp_seq == sp->pp_rseq) {
+ /* Local and remote sequence numbers are equal.
+ * Probably, the line is in loopback mode. */
+ if (sp->pp_loopcnt >= MAXALIVECNT) {
+ printf (SPP_FMT "loopback\n",
+ SPP_ARGS(ifp));
+ sp->pp_loopcnt = 0;
+ if (ifp->if_flags & IFF_UP) {
+ if_down (ifp);
+ sppp_qflush (&sp->pp_cpq);
+ }
+ }
+ ++sp->pp_loopcnt;
+
+ /* Generate new local sequence number */
+#if defined(__NetBSD__) || (defined(__FreeBSD__) && __FreeBSD__ >= 3)
+ sp->pp_seq = random();
+#else
+ sp->pp_seq ^= time.tv_sec ^ time.tv_usec;
+#endif
+ break;
+ }
+ sp->pp_loopcnt = 0;
+ if (! (ifp->if_flags & IFF_UP) &&
+ (ifp->if_flags & IFF_RUNNING)) {
+ if_up(ifp);
+ printf (SPP_FMT "up\n", SPP_ARGS(ifp));
+ }
+ break;
+ case CISCO_ADDR_REQ:
+ sppp_get_ip_addrs(sp, &me, 0, &mymask);
+ if (me != 0L)
+ sppp_cisco_send(sp, CISCO_ADDR_REPLY, me, mymask);
+ break;
+ }
+}
+
+/*
+ * Send Cisco keepalive packet.
+ */
+static void
+sppp_cisco_send(struct sppp *sp, int type, long par1, long par2)
+{
+ STDDCL;
+ struct ppp_header *h;
+ struct cisco_packet *ch;
+ struct mbuf *m;
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ struct timeval tv;
+#else
+ u_long t = (time.tv_sec - boottime.tv_sec) * 1000;
+#endif
+
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ getmicrouptime(&tv);
+#endif
+
+ MGETHDR (m, M_DONTWAIT, MT_DATA);
+ if (! m)
+ return;
+ m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + CISCO_PACKET_LEN;
+ m->m_pkthdr.rcvif = 0;
+
+ h = mtod (m, struct ppp_header*);
+ h->address = CISCO_MULTICAST;
+ h->control = 0;
+ h->protocol = htons (CISCO_KEEPALIVE);
+
+ ch = (struct cisco_packet*) (h + 1);
+ ch->type = htonl (type);
+ ch->par1 = htonl (par1);
+ ch->par2 = htonl (par2);
+ ch->rel = -1;
+
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ ch->time0 = htons ((u_short) (tv.tv_sec >> 16));
+ ch->time1 = htons ((u_short) tv.tv_sec);
+#else
+ ch->time0 = htons ((u_short) (t >> 16));
+ ch->time1 = htons ((u_short) t);
+#endif
+
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "cisco output: <0x%lx 0x%lx 0x%lx 0x%x 0x%x-0x%x>\n",
+ SPP_ARGS(ifp), (u_long)ntohl (ch->type), (u_long)ch->par1,
+ (u_long)ch->par2, (u_int)ch->rel, (u_int)ch->time0, (u_int)ch->time1);
+
+ if (IF_QFULL (&sp->pp_cpq)) {
+ IF_DROP (&sp->pp_fastq);
+ IF_DROP (&ifp->if_snd);
+ m_freem (m);
+ } else
+ IF_ENQUEUE (&sp->pp_cpq, m);
+ if (! (ifp->if_flags & IFF_OACTIVE))
+ (*ifp->if_start) (ifp);
+ ifp->if_obytes += m->m_pkthdr.len + 3;
+}
+
+ /*
+ * PPP protocol implementation.
+ */
+
+/*
+ * Send PPP control protocol packet.
+ */
+static void
+sppp_cp_send(struct sppp *sp, u_short proto, u_char type,
+ u_char ident, u_short len, void *data)
+{
+ STDDCL;
+ struct ppp_header *h;
+ struct lcp_header *lh;
+ struct mbuf *m;
+
+ if (len > MHLEN - PPP_HEADER_LEN - LCP_HEADER_LEN)
+ len = MHLEN - PPP_HEADER_LEN - LCP_HEADER_LEN;
+ MGETHDR (m, M_DONTWAIT, MT_DATA);
+ if (! m)
+ return;
+ m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + LCP_HEADER_LEN + len;
+ m->m_pkthdr.rcvif = 0;
+
+ h = mtod (m, struct ppp_header*);
+ h->address = PPP_ALLSTATIONS; /* broadcast address */
+ h->control = PPP_UI; /* Unnumbered Info */
+ h->protocol = htons (proto); /* Link Control Protocol */
+
+ lh = (struct lcp_header*) (h + 1);
+ lh->type = type;
+ lh->ident = ident;
+ lh->len = htons (LCP_HEADER_LEN + len);
+ if (len)
+ bcopy (data, lh+1, len);
+
+ if (debug) {
+ log(LOG_DEBUG, SPP_FMT "%s output <%s id=0x%x len=%d",
+ SPP_ARGS(ifp),
+ sppp_proto_name(proto),
+ sppp_cp_type_name (lh->type), lh->ident,
+ ntohs (lh->len));
+ sppp_print_bytes ((u_char*) (lh+1), len);
+ addlog(">\n");
+ }
+ if (IF_QFULL (&sp->pp_cpq)) {
+ IF_DROP (&sp->pp_fastq);
+ IF_DROP (&ifp->if_snd);
+ m_freem (m);
+ ++ifp->if_oerrors;
+ } else
+ IF_ENQUEUE (&sp->pp_cpq, m);
+ if (! (ifp->if_flags & IFF_OACTIVE))
+ (*ifp->if_start) (ifp);
+ ifp->if_obytes += m->m_pkthdr.len + 3;
+}
+
+/*
+ * Handle incoming PPP control protocol packets.
+ */
+static void
+sppp_cp_input(const struct cp *cp, struct sppp *sp, struct mbuf *m)
+{
+ STDDCL;
+ struct lcp_header *h;
+ int len = m->m_pkthdr.len;
+ int rv;
+ u_char *p;
+
+ if (len < 4) {
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "%s invalid packet length: %d bytes\n",
+ SPP_ARGS(ifp), cp->name, len);
+ return;
+ }
+ h = mtod (m, struct lcp_header*);
+ if (debug) {
+ log(LOG_DEBUG,
+ SPP_FMT "%s input(%s): <%s id=0x%x len=%d",
+ SPP_ARGS(ifp), cp->name,
+ sppp_state_name(sp->state[cp->protoidx]),
+ sppp_cp_type_name (h->type), h->ident, ntohs (h->len));
+ sppp_print_bytes ((u_char*) (h+1), len-4);
+ addlog(">\n");
+ }
+ if (len > ntohs (h->len))
+ len = ntohs (h->len);
+ p = (u_char *)(h + 1);
+ switch (h->type) {
+ case CONF_REQ:
+ if (len < 4) {
+ if (debug)
+ addlog(SPP_FMT "%s invalid conf-req length %d\n",
+ SPP_ARGS(ifp), cp->name,
+ len);
+ ++ifp->if_ierrors;
+ break;
+ }
+ /* handle states where RCR doesn't get a SCA/SCN */
+ switch (sp->state[cp->protoidx]) {
+ case STATE_CLOSING:
+ case STATE_STOPPING:
+ return;
+ case STATE_CLOSED:
+ sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident,
+ 0, 0);
+ return;
+ }
+ rv = (cp->RCR)(sp, h, len);
+ switch (sp->state[cp->protoidx]) {
+ case STATE_OPENED:
+ (cp->tld)(sp);
+ (cp->scr)(sp);
+ /* fall through... */
+ case STATE_ACK_SENT:
+ case STATE_REQ_SENT:
+ sppp_cp_change_state(cp, sp, rv?
+ STATE_ACK_SENT: STATE_REQ_SENT);
+ break;
+ case STATE_STOPPED:
+ sp->rst_counter[cp->protoidx] = sp->lcp.max_configure;
+ (cp->scr)(sp);
+ sppp_cp_change_state(cp, sp, rv?
+ STATE_ACK_SENT: STATE_REQ_SENT);
+ break;
+ case STATE_ACK_RCVD:
+ if (rv) {
+ sppp_cp_change_state(cp, sp, STATE_OPENED);
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "%s tlu\n",
+ SPP_ARGS(ifp),
+ cp->name);
+ (cp->tlu)(sp);
+ } else
+ sppp_cp_change_state(cp, sp, STATE_ACK_RCVD);
+ break;
+ default:
+ printf(SPP_FMT "%s illegal %s in state %s\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_cp_type_name(h->type),
+ sppp_state_name(sp->state[cp->protoidx]));
+ ++ifp->if_ierrors;
+ }
+ break;
+ case CONF_ACK:
+ if (h->ident != sp->confid[cp->protoidx]) {
+ if (debug)
+ addlog(SPP_FMT "%s id mismatch 0x%x != 0x%x\n",
+ SPP_ARGS(ifp), cp->name,
+ h->ident, sp->confid[cp->protoidx]);
+ ++ifp->if_ierrors;
+ break;
+ }
+ switch (sp->state[cp->protoidx]) {
+ case STATE_CLOSED:
+ case STATE_STOPPED:
+ sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0);
+ break;
+ case STATE_CLOSING:
+ case STATE_STOPPING:
+ break;
+ case STATE_REQ_SENT:
+ sp->rst_counter[cp->protoidx] = sp->lcp.max_configure;
+ sppp_cp_change_state(cp, sp, STATE_ACK_RCVD);
+ break;
+ case STATE_OPENED:
+ (cp->tld)(sp);
+ /* fall through */
+ case STATE_ACK_RCVD:
+ (cp->scr)(sp);
+ sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
+ break;
+ case STATE_ACK_SENT:
+ sp->rst_counter[cp->protoidx] = sp->lcp.max_configure;
+ sppp_cp_change_state(cp, sp, STATE_OPENED);
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "%s tlu\n",
+ SPP_ARGS(ifp), cp->name);
+ (cp->tlu)(sp);
+ break;
+ default:
+ printf(SPP_FMT "%s illegal %s in state %s\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_cp_type_name(h->type),
+ sppp_state_name(sp->state[cp->protoidx]));
+ ++ifp->if_ierrors;
+ }
+ break;
+ case CONF_NAK:
+ case CONF_REJ:
+ if (h->ident != sp->confid[cp->protoidx]) {
+ if (debug)
+ addlog(SPP_FMT "%s id mismatch 0x%x != 0x%x\n",
+ SPP_ARGS(ifp), cp->name,
+ h->ident, sp->confid[cp->protoidx]);
+ ++ifp->if_ierrors;
+ break;
+ }
+ if (h->type == CONF_NAK)
+ (cp->RCN_nak)(sp, h, len);
+ else /* CONF_REJ */
+ (cp->RCN_rej)(sp, h, len);
+
+ switch (sp->state[cp->protoidx]) {
+ case STATE_CLOSED:
+ case STATE_STOPPED:
+ sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0);
+ break;
+ case STATE_REQ_SENT:
+ case STATE_ACK_SENT:
+ sp->rst_counter[cp->protoidx] = sp->lcp.max_configure;
+ (cp->scr)(sp);
+ break;
+ case STATE_OPENED:
+ (cp->tld)(sp);
+ /* fall through */
+ case STATE_ACK_RCVD:
+ sppp_cp_change_state(cp, sp, STATE_ACK_SENT);
+ (cp->scr)(sp);
+ break;
+ case STATE_CLOSING:
+ case STATE_STOPPING:
+ break;
+ default:
+ printf(SPP_FMT "%s illegal %s in state %s\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_cp_type_name(h->type),
+ sppp_state_name(sp->state[cp->protoidx]));
+ ++ifp->if_ierrors;
+ }
+ break;
+
+ case TERM_REQ:
+ switch (sp->state[cp->protoidx]) {
+ case STATE_ACK_RCVD:
+ case STATE_ACK_SENT:
+ sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
+ /* fall through */
+ case STATE_CLOSED:
+ case STATE_STOPPED:
+ case STATE_CLOSING:
+ case STATE_STOPPING:
+ case STATE_REQ_SENT:
+ sta:
+ /* Send Terminate-Ack packet. */
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "%s send terminate-ack\n",
+ SPP_ARGS(ifp), cp->name);
+ sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0);
+ break;
+ case STATE_OPENED:
+ (cp->tld)(sp);
+ sp->rst_counter[cp->protoidx] = 0;
+ sppp_cp_change_state(cp, sp, STATE_STOPPING);
+ goto sta;
+ break;
+ default:
+ printf(SPP_FMT "%s illegal %s in state %s\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_cp_type_name(h->type),
+ sppp_state_name(sp->state[cp->protoidx]));
+ ++ifp->if_ierrors;
+ }
+ break;
+ case TERM_ACK:
+ switch (sp->state[cp->protoidx]) {
+ case STATE_CLOSED:
+ case STATE_STOPPED:
+ case STATE_REQ_SENT:
+ case STATE_ACK_SENT:
+ break;
+ case STATE_CLOSING:
+ sppp_cp_change_state(cp, sp, STATE_CLOSED);
+ (cp->tlf)(sp);
+ break;
+ case STATE_STOPPING:
+ sppp_cp_change_state(cp, sp, STATE_STOPPED);
+ (cp->tlf)(sp);
+ break;
+ case STATE_ACK_RCVD:
+ sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
+ break;
+ case STATE_OPENED:
+ (cp->tld)(sp);
+ (cp->scr)(sp);
+ sppp_cp_change_state(cp, sp, STATE_ACK_RCVD);
+ break;
+ default:
+ printf(SPP_FMT "%s illegal %s in state %s\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_cp_type_name(h->type),
+ sppp_state_name(sp->state[cp->protoidx]));
+ ++ifp->if_ierrors;
+ }
+ break;
+ case CODE_REJ:
+ case PROTO_REJ:
+ /* XXX catastrophic rejects (RXJ-) aren't handled yet. */
+ log(LOG_INFO,
+ SPP_FMT "%s: ignoring RXJ (%s) for proto 0x%x, "
+ "danger will robinson\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_cp_type_name(h->type), ntohs(*((u_short *)p)));
+ switch (sp->state[cp->protoidx]) {
+ case STATE_CLOSED:
+ case STATE_STOPPED:
+ case STATE_REQ_SENT:
+ case STATE_ACK_SENT:
+ case STATE_CLOSING:
+ case STATE_STOPPING:
+ case STATE_OPENED:
+ break;
+ case STATE_ACK_RCVD:
+ sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
+ break;
+ default:
+ printf(SPP_FMT "%s illegal %s in state %s\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_cp_type_name(h->type),
+ sppp_state_name(sp->state[cp->protoidx]));
+ ++ifp->if_ierrors;
+ }
+ break;
+ case DISC_REQ:
+ if (cp->proto != PPP_LCP)
+ goto illegal;
+ /* Discard the packet. */
+ break;
+ case ECHO_REQ:
+ if (cp->proto != PPP_LCP)
+ goto illegal;
+ if (sp->state[cp->protoidx] != STATE_OPENED) {
+ if (debug)
+ addlog(SPP_FMT "lcp echo req but lcp closed\n",
+ SPP_ARGS(ifp));
+ ++ifp->if_ierrors;
+ break;
+ }
+ if (len < 8) {
+ if (debug)
+ addlog(SPP_FMT "invalid lcp echo request "
+ "packet length: %d bytes\n",
+ SPP_ARGS(ifp), len);
+ break;
+ }
+
+ if ((sp->lcp.opts & (1 << LCP_OPT_MAGIC)) &&
+ ntohl (*(long*)(h+1)) == sp->lcp.magic) {
+
+ /* Line loopback mode detected. */
+ printf(SPP_FMT "loopback\n", SPP_ARGS(ifp));
+ if_down (ifp);
+ sppp_qflush (&sp->pp_cpq);
+
+ /* Shut down the PPP link. */
+ /* XXX */
+ lcp.Down(sp);
+ lcp.Up(sp);
+ break;
+ }
+ *(long*)(h+1) = htonl (sp->lcp.magic);
+ if (debug)
+ addlog(SPP_FMT "got lcp echo req, sending echo rep\n",
+ SPP_ARGS(ifp));
+ sppp_cp_send (sp, PPP_LCP, ECHO_REPLY, h->ident, len-4, h+1);
+ break;
+ case ECHO_REPLY:
+ if (cp->proto != PPP_LCP)
+ goto illegal;
+ if (h->ident != sp->lcp.echoid) {
+ ++ifp->if_ierrors;
+ break;
+ }
+ if (len < 8) {
+ if (debug)
+ addlog(SPP_FMT "lcp invalid echo reply "
+ "packet length: %d bytes\n",
+ SPP_ARGS(ifp), len);
+ break;
+ }
+ if (debug)
+ addlog(SPP_FMT "lcp got echo rep\n",
+ SPP_ARGS(ifp));
+
+ if (!(sp->lcp.opts & (1 << LCP_OPT_MAGIC)) ||
+ ntohl (*(long*)(h+1)) != sp->lcp.magic)
+ sp->pp_alivecnt = 0;
+ break;
+ default:
+ /* Unknown packet type -- send Code-Reject packet. */
+ illegal:
+ if (debug)
+ addlog(SPP_FMT "%s send code-rej for 0x%x\n",
+ SPP_ARGS(ifp), cp->name, h->type);
+ sppp_cp_send(sp, cp->proto, CODE_REJ, ++sp->pp_seq,
+ m->m_pkthdr.len, h);
+ ++ifp->if_ierrors;
+ }
+}
+
+
+/*
+ * The generic part of all Up/Down/Open/Close/TO event handlers.
+ * Basically, the state transition handling in the automaton.
+ */
+static void
+sppp_up_event(const struct cp *cp, struct sppp *sp)
+{
+ STDDCL;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "%s up(%s)\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_state_name(sp->state[cp->protoidx]));
+
+ switch (sp->state[cp->protoidx]) {
+ case STATE_INITIAL:
+ sppp_cp_change_state(cp, sp, STATE_CLOSED);
+ break;
+ case STATE_STARTING:
+ sp->rst_counter[cp->protoidx] = sp->lcp.max_configure;
+ (cp->scr)(sp);
+ sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
+ break;
+ default:
+ printf(SPP_FMT "%s illegal up in state %s\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_state_name(sp->state[cp->protoidx]));
+ }
+}
+
+static void
+sppp_down_event(const struct cp *cp, struct sppp *sp)
+{
+ STDDCL;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "%s down(%s)\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_state_name(sp->state[cp->protoidx]));
+
+ switch (sp->state[cp->protoidx]) {
+ case STATE_CLOSED:
+ case STATE_CLOSING:
+ sppp_cp_change_state(cp, sp, STATE_INITIAL);
+ break;
+ case STATE_STOPPED:
+ sppp_cp_change_state(cp, sp, STATE_STARTING);
+ (cp->tls)(sp);
+ break;
+ case STATE_STOPPING:
+ case STATE_REQ_SENT:
+ case STATE_ACK_RCVD:
+ case STATE_ACK_SENT:
+ sppp_cp_change_state(cp, sp, STATE_STARTING);
+ break;
+ case STATE_OPENED:
+ (cp->tld)(sp);
+ sppp_cp_change_state(cp, sp, STATE_STARTING);
+ break;
+ default:
+ printf(SPP_FMT "%s illegal down in state %s\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_state_name(sp->state[cp->protoidx]));
+ }
+}
+
+
+static void
+sppp_open_event(const struct cp *cp, struct sppp *sp)
+{
+ STDDCL;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "%s open(%s)\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_state_name(sp->state[cp->protoidx]));
+
+ switch (sp->state[cp->protoidx]) {
+ case STATE_INITIAL:
+ sppp_cp_change_state(cp, sp, STATE_STARTING);
+ (cp->tls)(sp);
+ break;
+ case STATE_STARTING:
+ break;
+ case STATE_CLOSED:
+ sp->rst_counter[cp->protoidx] = sp->lcp.max_configure;
+ (cp->scr)(sp);
+ sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
+ break;
+ case STATE_STOPPED:
+ case STATE_STOPPING:
+ case STATE_REQ_SENT:
+ case STATE_ACK_RCVD:
+ case STATE_ACK_SENT:
+ case STATE_OPENED:
+ break;
+ case STATE_CLOSING:
+ sppp_cp_change_state(cp, sp, STATE_STOPPING);
+ break;
+ }
+}
+
+
+static void
+sppp_close_event(const struct cp *cp, struct sppp *sp)
+{
+ STDDCL;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "%s close(%s)\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_state_name(sp->state[cp->protoidx]));
+
+ switch (sp->state[cp->protoidx]) {
+ case STATE_INITIAL:
+ case STATE_CLOSED:
+ case STATE_CLOSING:
+ break;
+ case STATE_STARTING:
+ sppp_cp_change_state(cp, sp, STATE_INITIAL);
+ (cp->tlf)(sp);
+ break;
+ case STATE_STOPPED:
+ sppp_cp_change_state(cp, sp, STATE_CLOSED);
+ break;
+ case STATE_STOPPING:
+ sppp_cp_change_state(cp, sp, STATE_CLOSING);
+ break;
+ case STATE_OPENED:
+ (cp->tld)(sp);
+ /* fall through */
+ case STATE_REQ_SENT:
+ case STATE_ACK_RCVD:
+ case STATE_ACK_SENT:
+ sp->rst_counter[cp->protoidx] = sp->lcp.max_terminate;
+ sppp_cp_send(sp, cp->proto, TERM_REQ, ++sp->pp_seq, 0, 0);
+ sppp_cp_change_state(cp, sp, STATE_CLOSING);
+ break;
+ }
+}
+
+static void
+sppp_to_event(const struct cp *cp, struct sppp *sp)
+{
+ STDDCL;
+ int s;
+
+ s = splimp();
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "%s TO(%s) rst_counter = %d\n",
+ SPP_ARGS(ifp), cp->name,
+ sppp_state_name(sp->state[cp->protoidx]),
+ sp->rst_counter[cp->protoidx]);
+
+ if (--sp->rst_counter[cp->protoidx] < 0)
+ /* TO- event */
+ switch (sp->state[cp->protoidx]) {
+ case STATE_CLOSING:
+ sppp_cp_change_state(cp, sp, STATE_CLOSED);
+ (cp->tlf)(sp);
+ break;
+ case STATE_STOPPING:
+ sppp_cp_change_state(cp, sp, STATE_STOPPED);
+ (cp->tlf)(sp);
+ break;
+ case STATE_REQ_SENT:
+ case STATE_ACK_RCVD:
+ case STATE_ACK_SENT:
+ sppp_cp_change_state(cp, sp, STATE_STOPPED);
+ (cp->tlf)(sp);
+ break;
+ }
+ else
+ /* TO+ event */
+ switch (sp->state[cp->protoidx]) {
+ case STATE_CLOSING:
+ case STATE_STOPPING:
+ sppp_cp_send(sp, cp->proto, TERM_REQ, ++sp->pp_seq,
+ 0, 0);
+ TIMEOUT(cp->TO, (void *)sp, sp->lcp.timeout,
+ sp->ch[cp->protoidx]);
+ break;
+ case STATE_REQ_SENT:
+ case STATE_ACK_RCVD:
+ (cp->scr)(sp);
+ /* sppp_cp_change_state() will restart the timer */
+ sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
+ break;
+ case STATE_ACK_SENT:
+ (cp->scr)(sp);
+ TIMEOUT(cp->TO, (void *)sp, sp->lcp.timeout,
+ sp->ch[cp->protoidx]);
+ break;
+ }
+
+ splx(s);
+}
+
+/*
+ * Change the state of a control protocol in the state automaton.
+ * Takes care of starting/stopping the restart timer.
+ */
+void
+sppp_cp_change_state(const struct cp *cp, struct sppp *sp, int newstate)
+{
+ sp->state[cp->protoidx] = newstate;
+ UNTIMEOUT(cp->TO, (void *)sp, sp->ch[cp->protoidx]);
+
+ switch (newstate) {
+ case STATE_INITIAL:
+ case STATE_STARTING:
+ case STATE_CLOSED:
+ case STATE_STOPPED:
+ case STATE_OPENED:
+ break;
+ case STATE_CLOSING:
+ case STATE_STOPPING:
+ case STATE_REQ_SENT:
+ case STATE_ACK_RCVD:
+ case STATE_ACK_SENT:
+ TIMEOUT(cp->TO, (void *)sp, sp->lcp.timeout,
+ sp->ch[cp->protoidx]);
+ break;
+ }
+}
+ /*
+ *--------------------------------------------------------------------------*
+ * *
+ * The LCP implementation. *
+ * *
+ *--------------------------------------------------------------------------*
+ */
+static void
+sppp_lcp_init(struct sppp *sp)
+{
+ sp->lcp.opts = (1 << LCP_OPT_MAGIC);
+ sp->lcp.magic = 0;
+ sp->state[IDX_LCP] = STATE_INITIAL;
+ sp->fail_counter[IDX_LCP] = 0;
+ sp->lcp.protos = 0;
+ sp->lcp.mru = sp->lcp.their_mru = PP_MTU;
+
+ /* Note that these values are relevant for all control protocols */
+ sp->lcp.timeout = 3 * hz;
+
+ sp->lcp.max_terminate = 2;
+ sp->lcp.max_configure = 10;
+ sp->lcp.max_failure = 10;
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ callout_handle_init(&sp->ch[IDX_LCP]);
+#endif
+}
+
+static void
+sppp_lcp_up(struct sppp *sp)
+{
+ STDDCL;
+
+ /*
+ * If this interface is passive or dial-on-demand, and we are
+ * still in Initial state, it means we've got an incoming
+ * call. Activate the interface.
+ */
+ if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) != 0) {
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "Up event", SPP_ARGS(ifp));
+ ifp->if_flags |= IFF_RUNNING;
+ if (sp->state[IDX_LCP] == STATE_INITIAL) {
+ if (debug)
+ addlog("(incoming call)\n");
+ sp->pp_flags |= PP_CALLIN;
+ lcp.Open(sp);
+ } else if (debug)
+ addlog("\n");
+ }
+
+ sppp_up_event(&lcp, sp);
+}
+
+static void
+sppp_lcp_down(struct sppp *sp)
+{
+ STDDCL;
+
+ sppp_down_event(&lcp, sp);
+
+ /*
+ * If this is neither a dial-on-demand nor a passive
+ * interface, simulate an ``ifconfig down'' action, so the
+ * administrator can force a redial by another ``ifconfig
+ * up''. XXX For leased line operation, should we immediately
+ * try to reopen the connection here?
+ */
+ if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) == 0) {
+ log(LOG_INFO,
+ SPP_FMT "Down event, taking interface down.\n",
+ SPP_ARGS(ifp));
+ if_down(ifp);
+ } else {
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "Down event (carrier loss)\n",
+ SPP_ARGS(ifp));
+ }
+ sp->pp_flags &= ~PP_CALLIN;
+ if (sp->state[IDX_LCP] != STATE_INITIAL)
+ lcp.Close(sp);
+ ifp->if_flags &= ~IFF_RUNNING;
+}
+
+static void
+sppp_lcp_open(struct sppp *sp)
+{
+ /*
+ * If we are authenticator, negotiate LCP_AUTH
+ */
+ if (sp->hisauth.proto != 0)
+ sp->lcp.opts |= (1 << LCP_OPT_AUTH_PROTO);
+ else
+ sp->lcp.opts &= ~(1 << LCP_OPT_AUTH_PROTO);
+ sp->pp_flags &= ~PP_NEEDAUTH;
+ sppp_open_event(&lcp, sp);
+}
+
+static void
+sppp_lcp_close(struct sppp *sp)
+{
+ sppp_close_event(&lcp, sp);
+}
+
+static void
+sppp_lcp_TO(void *cookie)
+{
+ sppp_to_event(&lcp, (struct sppp *)cookie);
+}
+
+/*
+ * Analyze a configure request. Return true if it was agreeable, and
+ * caused action sca, false if it has been rejected or nak'ed, and
+ * caused action scn. (The return value is used to make the state
+ * transition decision in the state automaton.)
+ */
+static int
+sppp_lcp_RCR(struct sppp *sp, struct lcp_header *h, int len)
+{
+ STDDCL;
+ u_char *buf, *r, *p;
+ int origlen, rlen;
+ u_long nmagic;
+ u_short authproto;
+
+ len -= 4;
+ origlen = len;
+ buf = r = malloc (len, M_TEMP, M_NOWAIT);
+ if (! buf)
+ return (0);
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "lcp parse opts: ",
+ SPP_ARGS(ifp));
+
+ /* pass 1: check for things that need to be rejected */
+ p = (void*) (h+1);
+ for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) {
+ if (debug)
+ addlog(" %s ", sppp_lcp_opt_name(*p));
+ switch (*p) {
+ case LCP_OPT_MAGIC:
+ /* Magic number. */
+ /* fall through, both are same length */
+ case LCP_OPT_ASYNC_MAP:
+ /* Async control character map. */
+ if (len >= 6 || p[1] == 6)
+ continue;
+ if (debug)
+ addlog("[invalid] ");
+ break;
+ case LCP_OPT_MRU:
+ /* Maximum receive unit. */
+ if (len >= 4 && p[1] == 4)
+ continue;
+ if (debug)
+ addlog("[invalid] ");
+ break;
+ case LCP_OPT_AUTH_PROTO:
+ if (len < 4) {
+ if (debug)
+ addlog("[invalid] ");
+ break;
+ }
+ authproto = (p[2] << 8) + p[3];
+ if (authproto == PPP_CHAP && p[1] != 5) {
+ if (debug)
+ addlog("[invalid chap len] ");
+ break;
+ }
+ if (sp->myauth.proto == 0) {
+ /* we are not configured to do auth */
+ if (debug)
+ addlog("[not configured] ");
+ break;
+ }
+ /*
+ * Remote want us to authenticate, remember this,
+ * so we stay in PHASE_AUTHENTICATE after LCP got
+ * up.
+ */
+ sp->pp_flags |= PP_NEEDAUTH;
+ continue;
+ default:
+ /* Others not supported. */
+ if (debug)
+ addlog("[rej] ");
+ break;
+ }
+ /* Add the option to rejected list. */
+ bcopy (p, r, p[1]);
+ r += p[1];
+ rlen += p[1];
+ }
+ if (rlen) {
+ if (debug)
+ addlog(" send conf-rej\n");
+ sppp_cp_send (sp, PPP_LCP, CONF_REJ, h->ident, rlen, buf);
+ return 0;
+ } else if (debug)
+ addlog("\n");
+
+ /*
+ * pass 2: check for option values that are unacceptable and
+ * thus require to be nak'ed.
+ */
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "lcp parse opt values: ",
+ SPP_ARGS(ifp));
+
+ p = (void*) (h+1);
+ len = origlen;
+ for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) {
+ if (debug)
+ addlog(" %s ", sppp_lcp_opt_name(*p));
+ switch (*p) {
+ case LCP_OPT_MAGIC:
+ /* Magic number -- extract. */
+ nmagic = (u_long)p[2] << 24 |
+ (u_long)p[3] << 16 | p[4] << 8 | p[5];
+ if (nmagic != sp->lcp.magic) {
+ if (debug)
+ addlog("0x%lx ", nmagic);
+ continue;
+ }
+ /*
+ * Local and remote magics equal -- loopback?
+ */
+ if (sp->pp_loopcnt >= MAXALIVECNT*5) {
+ printf (SPP_FMT "loopback\n",
+ SPP_ARGS(ifp));
+ sp->pp_loopcnt = 0;
+ if (ifp->if_flags & IFF_UP) {
+ if_down(ifp);
+ sppp_qflush(&sp->pp_cpq);
+ /* XXX ? */
+ lcp.Down(sp);
+ lcp.Up(sp);
+ }
+ } else if (debug)
+ addlog("[glitch] ");
+ ++sp->pp_loopcnt;
+ /*
+ * We negate our magic here, and NAK it. If
+ * we see it later in an NAK packet, we
+ * suggest a new one.
+ */
+ nmagic = ~sp->lcp.magic;
+ /* Gonna NAK it. */
+ p[2] = nmagic >> 24;
+ p[3] = nmagic >> 16;
+ p[4] = nmagic >> 8;
+ p[5] = nmagic;
+ break;
+
+ case LCP_OPT_ASYNC_MAP:
+#ifdef NOTDEF
+ /* Async control character map -- check to be zero. */
+ if (! p[2] && ! p[3] && ! p[4] && ! p[5]) {
+ if (debug)
+ addlog("[empty] ");
+ continue;
+ }
+ if (debug)
+ addlog("[non-empty] ");
+ from Armin Gruner:
+
+ Anyway, if I remove the "p[2] = p[3] = p[4] = p[5] = 0;",
+ the driver sends back the original async map request with a
+ NAK, and the errors in the Win95 ppp log go away.
+
+ /* suggest a zero one */
+ p[2] = p[3] = p[4] = p[5] = 0;
+ break;
+#endif
+ continue; /* Stefan Bethke :-) told me */
+ /* to continue .... */
+
+ case LCP_OPT_MRU:
+ /*
+ * Maximum receive unit. Always agreeable,
+ * but ignored by now.
+ */
+ sp->lcp.their_mru = p[2] * 256 + p[3];
+ if (debug)
+ addlog("%lu ", sp->lcp.their_mru);
+ continue;
+
+ case LCP_OPT_AUTH_PROTO:
+ authproto = (p[2] << 8) + p[3];
+ if (sp->myauth.proto != authproto) {
+ /* not agreed, nak */
+ if (debug)
+ addlog("[mine %s != his %s] ",
+ sppp_proto_name(sp->hisauth.proto),
+ sppp_proto_name(authproto));
+ p[2] = sp->myauth.proto >> 8;
+ p[3] = sp->myauth.proto;
+ break;
+ }
+ if (authproto == PPP_CHAP && p[4] != CHAP_MD5) {
+ if (debug)
+ addlog("[chap not MD5] ");
+ p[4] = CHAP_MD5;
+ break;
+ }
+ continue;
+ }
+ /* Add the option to nak'ed list. */
+ bcopy (p, r, p[1]);
+ r += p[1];
+ rlen += p[1];
+ }
+ if (rlen) {
+ if (++sp->fail_counter[IDX_LCP] >= sp->lcp.max_failure) {
+ if (debug)
+ addlog(" max_failure (%d) exceeded, "
+ "send conf-rej\n",
+ sp->lcp.max_failure);
+ sppp_cp_send(sp, PPP_LCP, CONF_REJ, h->ident, rlen, buf);
+ } else {
+ if (debug)
+ addlog(" send conf-nak\n");
+ sppp_cp_send (sp, PPP_LCP, CONF_NAK, h->ident, rlen, buf);
+ }
+ return 0;
+ } else {
+ if (debug)
+ addlog(" send conf-ack\n");
+ sp->fail_counter[IDX_LCP] = 0;
+ sp->pp_loopcnt = 0;
+ sppp_cp_send (sp, PPP_LCP, CONF_ACK,
+ h->ident, origlen, h+1);
+ }
+
+ free (buf, M_TEMP);
+ return (rlen == 0);
+}
+
+/*
+ * Analyze the LCP Configure-Reject option list, and adjust our
+ * negotiation.
+ */
+static void
+sppp_lcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len)
+{
+ STDDCL;
+ u_char *buf, *p;
+
+ len -= 4;
+ buf = malloc (len, M_TEMP, M_NOWAIT);
+ if (!buf)
+ return;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "lcp rej opts: ",
+ SPP_ARGS(ifp));
+
+ p = (void*) (h+1);
+ for (; len > 1 && p[1]; len -= p[1], p += p[1]) {
+ if (debug)
+ addlog(" %s ", sppp_lcp_opt_name(*p));
+ switch (*p) {
+ case LCP_OPT_MAGIC:
+ /* Magic number -- can't use it, use 0 */
+ sp->lcp.opts &= ~(1 << LCP_OPT_MAGIC);
+ sp->lcp.magic = 0;
+ break;
+ case LCP_OPT_MRU:
+ /*
+ * Should not be rejected anyway, since we only
+ * negotiate a MRU if explicitly requested by
+ * peer.
+ */
+ sp->lcp.opts &= ~(1 << LCP_OPT_MRU);
+ break;
+ case LCP_OPT_AUTH_PROTO:
+ /*
+ * Peer doesn't want to authenticate himself,
+ * deny unless this is a dialout call, and
+ * AUTHFLAG_NOCALLOUT is set.
+ */
+ if ((sp->pp_flags & PP_CALLIN) == 0 &&
+ (sp->hisauth.flags & AUTHFLAG_NOCALLOUT) != 0) {
+ if (debug)
+ addlog("[don't insist on auth "
+ "for callout]");
+ sp->lcp.opts &= ~(1 << LCP_OPT_AUTH_PROTO);
+ break;
+ }
+ if (debug)
+ addlog("[access denied]\n");
+ lcp.Close(sp);
+ break;
+ }
+ }
+ if (debug)
+ addlog("\n");
+ free (buf, M_TEMP);
+ return;
+}
+
+/*
+ * Analyze the LCP Configure-NAK option list, and adjust our
+ * negotiation.
+ */
+static void
+sppp_lcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len)
+{
+ STDDCL;
+ u_char *buf, *p;
+ u_long magic;
+
+ len -= 4;
+ buf = malloc (len, M_TEMP, M_NOWAIT);
+ if (!buf)
+ return;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "lcp nak opts: ",
+ SPP_ARGS(ifp));
+
+ p = (void*) (h+1);
+ for (; len > 1 && p[1]; len -= p[1], p += p[1]) {
+ if (debug)
+ addlog(" %s ", sppp_lcp_opt_name(*p));
+ switch (*p) {
+ case LCP_OPT_MAGIC:
+ /* Magic number -- renegotiate */
+ if ((sp->lcp.opts & (1 << LCP_OPT_MAGIC)) &&
+ len >= 6 && p[1] == 6) {
+ magic = (u_long)p[2] << 24 |
+ (u_long)p[3] << 16 | p[4] << 8 | p[5];
+ /*
+ * If the remote magic is our negated one,
+ * this looks like a loopback problem.
+ * Suggest a new magic to make sure.
+ */
+ if (magic == ~sp->lcp.magic) {
+ if (debug)
+ addlog("magic glitch ");
+#if defined(__NetBSD__) || (defined(__FreeBSD__) && __FreeBSD__ >= 3)
+ sp->lcp.magic = random();
+#else
+ sp->lcp.magic = time.tv_sec + time.tv_usec;
+#endif
+ } else {
+ sp->lcp.magic = magic;
+ if (debug)
+ addlog("%lu ", magic);
+ }
+ }
+ break;
+ case LCP_OPT_MRU:
+ /*
+ * Peer wants to advise us to negotiate an MRU.
+ * Agree on it if it's reasonable, or use
+ * default otherwise.
+ */
+ if (len >= 4 && p[1] == 4) {
+ u_int mru = p[2] * 256 + p[3];
+ if (debug)
+ addlog("%d ", mru);
+ if (mru < PP_MTU || mru > PP_MAX_MRU)
+ mru = PP_MTU;
+ sp->lcp.mru = mru;
+ sp->lcp.opts |= (1 << LCP_OPT_MRU);
+ }
+ break;
+ case LCP_OPT_AUTH_PROTO:
+ /*
+ * Peer doesn't like our authentication method,
+ * deny.
+ */
+ if (debug)
+ addlog("[access denied]\n");
+ lcp.Close(sp);
+ break;
+ }
+ }
+ if (debug)
+ addlog("\n");
+ free (buf, M_TEMP);
+ return;
+}
+
+static void
+sppp_lcp_tlu(struct sppp *sp)
+{
+ STDDCL;
+ int i;
+ u_long mask;
+
+ /* XXX ? */
+ if (! (ifp->if_flags & IFF_UP) &&
+ (ifp->if_flags & IFF_RUNNING)) {
+ /* Coming out of loopback mode. */
+ if_up(ifp);
+ printf (SPP_FMT "up\n", SPP_ARGS(ifp));
+ }
+
+ for (i = 0; i < IDX_COUNT; i++)
+ if ((cps[i])->flags & CP_QUAL)
+ (cps[i])->Open(sp);
+
+ if ((sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0 ||
+ (sp->pp_flags & PP_NEEDAUTH) != 0)
+ sp->pp_phase = PHASE_AUTHENTICATE;
+ else
+ sp->pp_phase = PHASE_NETWORK;
+
+ if(debug)
+ log(LOG_DEBUG, SPP_FMT "phase %s\n", SPP_ARGS(ifp),
+ sppp_phase_name(sp->pp_phase));
+
+ /*
+ * Open all authentication protocols. This is even required
+ * if we already proceeded to network phase, since it might be
+ * that remote wants us to authenticate, so we might have to
+ * send a PAP request. Undesired authentication protocols
+ * don't do anything when they get an Open event.
+ */
+ for (i = 0; i < IDX_COUNT; i++)
+ if ((cps[i])->flags & CP_AUTH)
+ (cps[i])->Open(sp);
+
+ if (sp->pp_phase == PHASE_NETWORK) {
+ /* Notify all NCPs. */
+ for (i = 0; i < IDX_COUNT; i++)
+ if ((cps[i])->flags & CP_NCP)
+ (cps[i])->Open(sp);
+ }
+
+ /* Send Up events to all started protos. */
+ for (i = 0, mask = 1; i < IDX_COUNT; i++, mask <<= 1)
+ if (sp->lcp.protos & mask && ((cps[i])->flags & CP_LCP) == 0)
+ (cps[i])->Up(sp);
+
+ /* notify low-level driver of state change */
+ if (sp->pp_chg)
+ sp->pp_chg(sp, (int)sp->pp_phase);
+
+ if (sp->pp_phase == PHASE_NETWORK)
+ /* if no NCP is starting, close down */
+ sppp_lcp_check_and_close(sp);
+}
+
+static void
+sppp_lcp_tld(struct sppp *sp)
+{
+ STDDCL;
+ int i;
+ u_long mask;
+
+ sp->pp_phase = PHASE_TERMINATE;
+
+ if(debug)
+ log(LOG_DEBUG, SPP_FMT "phase %s\n", SPP_ARGS(ifp),
+ sppp_phase_name(sp->pp_phase));
+
+ /*
+ * Take upper layers down. We send the Down event first and
+ * the Close second to prevent the upper layers from sending
+ * ``a flurry of terminate-request packets'', as the RFC
+ * describes it.
+ */
+ for (i = 0, mask = 1; i < IDX_COUNT; i++, mask <<= 1)
+ if (sp->lcp.protos & mask && ((cps[i])->flags & CP_LCP) == 0) {
+ (cps[i])->Down(sp);
+ (cps[i])->Close(sp);
+ }
+}
+
+static void
+sppp_lcp_tls(struct sppp *sp)
+{
+ STDDCL;
+
+ sp->pp_phase = PHASE_ESTABLISH;
+
+ if(debug)
+ log(LOG_DEBUG, SPP_FMT "phase %s\n", SPP_ARGS(ifp),
+ sppp_phase_name(sp->pp_phase));
+
+ /* Notify lower layer if desired. */
+ if (sp->pp_tls)
+ (sp->pp_tls)(sp);
+ else
+ (sp->pp_up)(sp);
+}
+
+static void
+sppp_lcp_tlf(struct sppp *sp)
+{
+ STDDCL;
+
+ sp->pp_phase = PHASE_DEAD;
+
+ if(debug)
+ log(LOG_DEBUG, SPP_FMT "phase %s\n", SPP_ARGS(ifp),
+ sppp_phase_name(sp->pp_phase));
+
+ /* Notify lower layer if desired. */
+ if (sp->pp_tlf)
+ (sp->pp_tlf)(sp);
+ else
+ (sp->pp_down)(sp);
+}
+
+static void
+sppp_lcp_scr(struct sppp *sp)
+{
+ char opt[6 /* magicnum */ + 4 /* mru */ + 5 /* chap */];
+ int i = 0;
+ u_short authproto;
+
+ if (sp->lcp.opts & (1 << LCP_OPT_MAGIC)) {
+ if (! sp->lcp.magic)
+#if defined(__NetBSD__) || (defined(__FreeBSD__) && __FreeBSD__ >= 3)
+ sp->lcp.magic = random();
+#else
+ sp->lcp.magic = time.tv_sec + time.tv_usec;
+#endif
+ opt[i++] = LCP_OPT_MAGIC;
+ opt[i++] = 6;
+ opt[i++] = sp->lcp.magic >> 24;
+ opt[i++] = sp->lcp.magic >> 16;
+ opt[i++] = sp->lcp.magic >> 8;
+ opt[i++] = sp->lcp.magic;
+ }
+
+ if (sp->lcp.opts & (1 << LCP_OPT_MRU)) {
+ opt[i++] = LCP_OPT_MRU;
+ opt[i++] = 4;
+ opt[i++] = sp->lcp.mru >> 8;
+ opt[i++] = sp->lcp.mru;
+ }
+
+ if (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) {
+ authproto = sp->hisauth.proto;
+ opt[i++] = LCP_OPT_AUTH_PROTO;
+ opt[i++] = authproto == PPP_CHAP? 5: 4;
+ opt[i++] = authproto >> 8;
+ opt[i++] = authproto;
+ if (authproto == PPP_CHAP)
+ opt[i++] = CHAP_MD5;
+ }
+
+ sp->confid[IDX_LCP] = ++sp->pp_seq;
+ sppp_cp_send (sp, PPP_LCP, CONF_REQ, sp->confid[IDX_LCP], i, &opt);
+}
+
+/*
+ * Check the open NCPs, return true if at least one NCP is open.
+ */
+static int
+sppp_ncp_check(struct sppp *sp)
+{
+ int i, mask;
+
+ for (i = 0, mask = 1; i < IDX_COUNT; i++, mask <<= 1)
+ if (sp->lcp.protos & mask && (cps[i])->flags & CP_NCP)
+ return 1;
+ return 0;
+}
+
+/*
+ * Re-check the open NCPs and see if we should terminate the link.
+ * Called by the NCPs during their tlf action handling.
+ */
+static void
+sppp_lcp_check_and_close(struct sppp *sp)
+{
+
+ if (sp->pp_phase < PHASE_NETWORK)
+ /* don't bother, we are already going down */
+ return;
+
+ if (sppp_ncp_check(sp))
+ return;
+
+ lcp.Close(sp);
+}
+ /*
+ *--------------------------------------------------------------------------*
+ * *
+ * The IPCP implementation. *
+ * *
+ *--------------------------------------------------------------------------*
+ */
+
+static void
+sppp_ipcp_init(struct sppp *sp)
+{
+ sp->ipcp.opts = 0;
+ sp->ipcp.flags = 0;
+ sp->state[IDX_IPCP] = STATE_INITIAL;
+ sp->fail_counter[IDX_IPCP] = 0;
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ callout_handle_init(&sp->ch[IDX_IPCP]);
+#endif
+}
+
+static void
+sppp_ipcp_up(struct sppp *sp)
+{
+ sppp_up_event(&ipcp, sp);
+}
+
+static void
+sppp_ipcp_down(struct sppp *sp)
+{
+ sppp_down_event(&ipcp, sp);
+}
+
+static void
+sppp_ipcp_open(struct sppp *sp)
+{
+ STDDCL;
+ u_long myaddr, hisaddr;
+
+#ifdef SPPP_VJ
+ if(sp->enable_vj)
+ {
+ sp->ipcp.flags &= ~(IPCP_HISADDR_SEEN | IPCP_MYADDR_SEEN |
+ IPCP_MYADDR_DYN | IPCP_VJ);
+ }
+ else
+ {
+ sp->ipcp.flags &= ~(IPCP_HISADDR_SEEN | IPCP_MYADDR_SEEN |
+ IPCP_MYADDR_DYN);
+ }
+#else
+ sp->ipcp.flags &= ~(IPCP_HISADDR_SEEN|IPCP_MYADDR_SEEN|IPCP_MYADDR_DYN);
+#endif
+
+ sppp_get_ip_addrs(sp, &myaddr, &hisaddr, 0);
+ /*
+ * If we don't have his address, this probably means our
+ * interface doesn't want to talk IP at all. (This could
+ * be the case if somebody wants to speak only IPX, for
+ * example.) Don't open IPCP in this case.
+ */
+ if (hisaddr == 0L) {
+ /* XXX this message should go away */
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "ipcp_open(): no IP interface\n",
+ SPP_ARGS(ifp));
+ return;
+ }
+
+#ifdef SPPP_VJ
+ if(sp->enable_vj)
+ sp->ipcp.opts |= (1 << IPCP_OPT_COMPRESSION);
+
+ sp->ipcp.max_state = MAX_STATES - 1;
+ sp->ipcp.compress_cid = 1;
+#endif
+
+ if (myaddr == 0L) {
+ /*
+ * I don't have an assigned address, so i need to
+ * negotiate my address.
+ */
+ sp->ipcp.flags |= IPCP_MYADDR_DYN;
+ sp->ipcp.opts |= (1 << IPCP_OPT_ADDRESS);
+ } else
+ sp->ipcp.flags |= IPCP_MYADDR_SEEN;
+ sppp_open_event(&ipcp, sp);
+}
+
+static void
+sppp_ipcp_close(struct sppp *sp)
+{
+ sppp_close_event(&ipcp, sp);
+ if (sp->ipcp.flags & IPCP_MYADDR_DYN)
+ /*
+ * My address was dynamic, clear it again.
+ */
+ sppp_set_ip_addr(sp, 0L);
+}
+
+static void
+sppp_ipcp_TO(void *cookie)
+{
+ sppp_to_event(&ipcp, (struct sppp *)cookie);
+}
+
+/*
+ * Analyze a configure request. Return true if it was agreeable, and
+ * caused action sca, false if it has been rejected or nak'ed, and
+ * caused action scn. (The return value is used to make the state
+ * transition decision in the state automaton.)
+ */
+static int
+sppp_ipcp_RCR(struct sppp *sp, struct lcp_header *h, int len)
+{
+ u_char *buf, *r, *p;
+ struct ifnet *ifp = &sp->pp_if;
+ int rlen, origlen, debug = ifp->if_flags & IFF_DEBUG;
+ u_long hisaddr, desiredaddr;
+ int gotmyaddr = 0;
+#ifdef SPPP_VJ
+ int desiredcomp;
+#endif
+
+ len -= 4;
+ origlen = len;
+ /*
+ * Make sure to allocate a buf that can at least hold a
+ * conf-nak with an `address' option. We might need it below.
+ */
+ buf = r = malloc ((len < 6? 6: len), M_TEMP, M_NOWAIT);
+ if (! buf)
+ return (0);
+
+ /* pass 1: see if we can recognize them */
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "ipcp parse opts: ",
+ SPP_ARGS(ifp));
+ p = (void*) (h+1);
+ for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) {
+ if (debug)
+ addlog(" %s ", sppp_ipcp_opt_name(*p));
+ switch (*p) {
+
+#ifdef SPPP_VJ
+ case IPCP_OPT_COMPRESSION:
+ if(sp->enable_vj)
+ {
+ if (len >= 6 && p[1] == 6) {
+ /* correctly formed compress option */
+ continue;
+ }
+ if (debug)
+ addlog("[invalid] ");
+ }
+ break;
+#endif
+
+ case IPCP_OPT_ADDRESS:
+ if (len >= 6 && p[1] == 6) {
+ /* correctly formed address option */
+ continue;
+ }
+ if (debug)
+ addlog("[invalid] ");
+ break;
+ default:
+ /* Others not supported. */
+ if (debug)
+ addlog("[rej] ");
+ break;
+ }
+ /* Add the option to rejected list. */
+ bcopy (p, r, p[1]);
+ r += p[1];
+ rlen += p[1];
+ }
+ if (rlen) {
+ if (debug)
+ addlog(" send conf-rej\n");
+ sppp_cp_send (sp, PPP_IPCP, CONF_REJ, h->ident, rlen, buf);
+ return 0;
+ } else if (debug)
+ addlog("\n");
+
+ /* pass 2: parse option values */
+ sppp_get_ip_addrs(sp, 0, &hisaddr, 0);
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "ipcp parse opt values: ",
+ SPP_ARGS(ifp));
+ p = (void*) (h+1);
+ len = origlen;
+ for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) {
+ if (debug)
+ addlog(" %s ", sppp_ipcp_opt_name(*p));
+ switch (*p) {
+
+#ifdef SPPP_VJ
+ case IPCP_OPT_COMPRESSION:
+ desiredcomp = p[2] << 8 | p[3];
+
+ /* We only support VJ */
+ if (desiredcomp == IPCP_COMP_VJ)
+ {
+ if(sp->enable_vj)
+ {
+ if (debug)
+ addlog("VJ [ack] ");
+ sp->ipcp.flags |= IPCP_VJ;
+#ifdef __FreeBSD__
+ sl_compress_init(&sp->pp_comp, p[4]);
+#else
+ sl_compress_setup(&sp->pp_comp, p[4]);
+#endif
+ sp->ipcp.max_state = p[4];
+ sp->ipcp.compress_cid = p[5];
+ continue;
+ }
+ else
+ {
+ if (debug)
+ addlog("%#04x [VJ disabled] ", desiredcomp);
+ p[2] = IPCP_COMP_VJ >> 8;
+ p[3] = IPCP_COMP_VJ;
+ break;
+ }
+ }
+ if (debug)
+ addlog("%#04x [not supported] ", desiredcomp);
+ p[2] = IPCP_COMP_VJ >> 8;
+ p[3] = IPCP_COMP_VJ;
+ break;
+#endif
+
+ case IPCP_OPT_ADDRESS:
+ /* This is the address he wants in his end */
+ desiredaddr = p[2] << 24 | p[3] << 16 |
+ p[4] << 8 | p[5];
+
+ if (desiredaddr == hisaddr ||
+ (hisaddr == 1 && desiredaddr != 0)) {
+ /*
+ * Peer's address is same as our value,
+ * or we have set it to 0.0.0.1 to
+ * indicate that we do not really care,
+ * this is agreeable. Gonna conf-ack
+ * it.
+ */
+ if (debug)
+ addlog("%s [ack] ",
+ sppp_dotted_quad(hisaddr));
+ /* record that we've seen it already */
+ sp->ipcp.flags |= IPCP_HISADDR_SEEN;
+ continue;
+ }
+ /*
+ * The address wasn't agreeable. This is either
+ * he sent us 0.0.0.0, asking to assign him an
+ * address, or he send us another address not
+ * matching our value. Either case, we gonna
+ * conf-nak it with our value.
+ * XXX: we should "rej" if hisaddr == 0
+ */
+ if (debug) {
+ if (desiredaddr == 0)
+ addlog("[addr requested] ");
+ else
+ addlog("%s [not agreed] ",
+ sppp_dotted_quad(desiredaddr));
+ }
+ p[2] = hisaddr >> 24;
+ p[3] = hisaddr >> 16;
+ p[4] = hisaddr >> 8;
+ p[5] = hisaddr;
+ break;
+ }
+
+ /* Add the option to nak'ed list. */
+ bcopy (p, r, p[1]);
+ r += p[1];
+ rlen += p[1];
+ }
+
+ /*
+ * If we are about to conf-ack the request, but haven't seen
+ * his address so far, gonna conf-nak it instead, with the
+ * `address' option present and our idea of his address being
+ * filled in there, to request negotiation of both addresses.
+ *
+ * XXX This can result in an endless req - nak loop if peer
+ * doesn't want to send us his address. Q: What should we do
+ * about it? XXX A: implement the max-failure counter.
+ */
+ if (rlen == 0 && !(sp->ipcp.flags & IPCP_HISADDR_SEEN) && !gotmyaddr) {
+ buf[0] = IPCP_OPT_ADDRESS;
+ buf[1] = 6;
+ buf[2] = hisaddr >> 24;
+ buf[3] = hisaddr >> 16;
+ buf[4] = hisaddr >> 8;
+ buf[5] = hisaddr;
+ rlen = 6;
+ if (debug)
+ addlog("still need hisaddr ");
+ }
+
+ if (rlen) {
+ if (debug)
+ addlog(" send conf-nak\n");
+ sppp_cp_send (sp, PPP_IPCP, CONF_NAK, h->ident, rlen, buf);
+ } else {
+ if (debug)
+ addlog(" send conf-ack\n");
+ sppp_cp_send (sp, PPP_IPCP, CONF_ACK,
+ h->ident, origlen, h+1);
+ }
+
+ free (buf, M_TEMP);
+ return (rlen == 0);
+}
+
+/*
+ * Analyze the IPCP Configure-Reject option list, and adjust our
+ * negotiation.
+ */
+static void
+sppp_ipcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len)
+{
+ u_char *buf, *p;
+ struct ifnet *ifp = &sp->pp_if;
+ int debug = ifp->if_flags & IFF_DEBUG;
+
+ len -= 4;
+ buf = malloc (len, M_TEMP, M_NOWAIT);
+ if (!buf)
+ return;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "ipcp rej opts: ",
+ SPP_ARGS(ifp));
+
+ p = (void*) (h+1);
+ for (; len > 1 && p[1]; len -= p[1], p += p[1]) {
+ if (debug)
+ addlog(" %s ", sppp_ipcp_opt_name(*p));
+ switch (*p) {
+#ifdef SPPP_VJ
+ case IPCP_OPT_COMPRESSION:
+ sp->ipcp.opts &= ~(1 << IPCP_OPT_COMPRESSION);
+ break;
+#endif
+ case IPCP_OPT_ADDRESS:
+ /*
+ * Peer doesn't grok address option. This is
+ * bad. XXX Should we better give up here?
+ * XXX We could try old "addresses" option...
+ */
+ sp->ipcp.opts &= ~(1 << IPCP_OPT_ADDRESS);
+ break;
+
+#ifdef NOTYET
+ case IPCP_OPT_COMPRESS:
+ sp->ipcp.opts &= ~(1 << IPCP_OPT_COMPRESS);
+ break;
+#endif
+ }
+ }
+ if (debug)
+ addlog("\n");
+ free (buf, M_TEMP);
+ return;
+}
+
+/*
+ * Analyze the IPCP Configure-NAK option list, and adjust our
+ * negotiation.
+ */
+static void
+sppp_ipcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len)
+{
+ u_char *buf, *p;
+ struct ifnet *ifp = &sp->pp_if;
+ int debug = ifp->if_flags & IFF_DEBUG;
+ u_long wantaddr;
+#ifdef SPPP_VJ
+ int desiredcomp;
+#endif
+
+ len -= 4;
+ buf = malloc (len, M_TEMP, M_NOWAIT);
+ if (!buf)
+ return;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "ipcp nak opts: ",
+ SPP_ARGS(ifp));
+
+ p = (void*) (h+1);
+ for (; len > 1 && p[1]; len -= p[1], p += p[1]) {
+ if (debug)
+ addlog(" %s ", sppp_ipcp_opt_name(*p));
+ switch (*p) {
+#ifdef SPPP_VJ
+ case IPCP_OPT_COMPRESSION:
+ if (len >= 6 && p[1] == 6) {
+ desiredcomp = p[2] << 8 | p[3];
+ if (debug)
+ addlog("[wantcomp %#04x] ",
+ desiredcomp);
+ if (desiredcomp == IPCP_COMP_VJ && sp->enable_vj) {
+#ifdef __FreeBSD__
+ sl_compress_init(&sp->pp_comp, p[4]);
+#else
+ sl_compress_setup(&sp->pp_comp, p[4]);
+#endif
+ sp->ipcp.max_state = p[4];
+ sp->ipcp.compress_cid = p[5];
+ addlog("[agree] ");
+ } else
+ sp->ipcp.opts &=
+ ~(1 << IPCP_OPT_COMPRESSION);
+ }
+ break;
+#endif
+ case IPCP_OPT_ADDRESS:
+ /*
+ * Peer doesn't like our local IP address. See
+ * if we can do something for him. We'll drop
+ * him our address then.
+ */
+ if (len >= 6 && p[1] == 6) {
+ wantaddr = p[2] << 24 | p[3] << 16 |
+ p[4] << 8 | p[5];
+ sp->ipcp.opts |= (1 << IPCP_OPT_ADDRESS);
+ if (debug)
+ addlog("[wantaddr %s] ",
+ sppp_dotted_quad(wantaddr));
+ /*
+ * When doing dynamic address assignment,
+ * we accept his offer. Otherwise, we
+ * ignore it and thus continue to negotiate
+ * our already existing value.
+ * XXX: Bogus, if he said no once, he'll
+ * just say no again, might as well die.
+ */
+ if (sp->ipcp.flags & IPCP_MYADDR_DYN) {
+ sppp_set_ip_addr(sp, wantaddr);
+ if (debug)
+ addlog("[agree] ");
+ sp->ipcp.flags |= IPCP_MYADDR_SEEN;
+ }
+ }
+ break;
+#ifdef NOTYET
+ case IPCP_OPT_COMPRESS:
+ /*
+ * Peer wants different compression parameters.
+ */
+ break;
+#endif
+ }
+ }
+ if (debug)
+ addlog("\n");
+ free (buf, M_TEMP);
+ return;
+}
+
+static void
+sppp_ipcp_tlu(struct sppp *sp)
+{
+ /* we are up - notify isdn daemon */
+ if (sp->pp_con)
+ sp->pp_con(sp);
+}
+
+static void
+sppp_ipcp_tld(struct sppp *sp)
+{
+}
+
+static void
+sppp_ipcp_tls(struct sppp *sp)
+{
+ /* indicate to LCP that it must stay alive */
+ sp->lcp.protos |= (1 << IDX_IPCP);
+}
+
+static void
+sppp_ipcp_tlf(struct sppp *sp)
+{
+ /* we no longer need LCP */
+ sp->lcp.protos &= ~(1 << IDX_IPCP);
+ sppp_lcp_check_and_close(sp);
+}
+
+static void
+sppp_ipcp_scr(struct sppp *sp)
+{
+ char opt[6 /* compression */ + 6 /* address */];
+ u_long ouraddr;
+ int i = 0;
+
+#ifdef SPPP_VJ
+ if (sp->ipcp.opts & (1 << IPCP_OPT_COMPRESSION)) {
+ opt[i++] = IPCP_OPT_COMPRESSION;
+ opt[i++] = 6;
+ opt[i++] = IPCP_COMP_VJ >> 8;
+ opt[i++] = IPCP_COMP_VJ;
+ opt[i++] = sp->ipcp.max_state;
+ opt[i++] = sp->ipcp.compress_cid;
+ }
+#endif
+
+ if (sp->ipcp.opts & (1 << IPCP_OPT_ADDRESS)) {
+ sppp_get_ip_addrs(sp, &ouraddr, 0, 0);
+ opt[i++] = IPCP_OPT_ADDRESS;
+ opt[i++] = 6;
+ opt[i++] = ouraddr >> 24;
+ opt[i++] = ouraddr >> 16;
+ opt[i++] = ouraddr >> 8;
+ opt[i++] = ouraddr;
+ }
+
+ sp->confid[IDX_IPCP] = ++sp->pp_seq;
+ sppp_cp_send(sp, PPP_IPCP, CONF_REQ, sp->confid[IDX_IPCP], i, &opt);
+}
+
+
+ /*
+ *--------------------------------------------------------------------------*
+ * *
+ * The CHAP implementation. *
+ * *
+ *--------------------------------------------------------------------------*
+ */
+
+/*
+ * The authentication protocols don't employ a full-fledged state machine as
+ * the control protocols do, since they do have Open and Close events, but
+ * not Up and Down, nor are they explicitly terminated. Also, use of the
+ * authentication protocols may be different in both directions (this makes
+ * sense, think of a machine that never accepts incoming calls but only
+ * calls out, it doesn't require the called party to authenticate itself).
+ *
+ * Our state machine for the local authentication protocol (we are requesting
+ * the peer to authenticate) looks like:
+ *
+ * RCA-
+ * +--------------------------------------------+
+ * V scn,tld|
+ * +--------+ Close +---------+ RCA+
+ * | |<----------------------------------| |------+
+ * +--->| Closed | TO* | Opened | sca |
+ * | | |-----+ +-------| |<-----+
+ * | +--------+ irc | | +---------+
+ * | ^ | | ^
+ * | | | | |
+ * | | | | |
+ * | TO-| | | |
+ * | |tld TO+ V | |
+ * | | +------->+ | |
+ * | | | | | |
+ * | +--------+ V | |
+ * | | |<----+<--------------------+ |
+ * | | Req- | scr |
+ * | | Sent | |
+ * | | | |
+ * | +--------+ |
+ * | RCA- | | RCA+ |
+ * +------+ +------------------------------------------+
+ * scn,tld sca,irc,ict,tlu
+ *
+ *
+ * with:
+ *
+ * Open: LCP reached authentication phase
+ * Close: LCP reached terminate phase
+ *
+ * RCA+: received reply (pap-req, chap-response), acceptable
+ * RCN: received reply (pap-req, chap-response), not acceptable
+ * TO+: timeout with restart counter >= 0
+ * TO-: timeout with restart counter < 0
+ * TO*: reschedule timeout for CHAP
+ *
+ * scr: send request packet (none for PAP, chap-challenge)
+ * sca: send ack packet (pap-ack, chap-success)
+ * scn: send nak packet (pap-nak, chap-failure)
+ * ict: initialize re-challenge timer (CHAP only)
+ *
+ * tlu: this-layer-up, LCP reaches network phase
+ * tld: this-layer-down, LCP enters terminate phase
+ *
+ * Note that in CHAP mode, after sending a new challenge, while the state
+ * automaton falls back into Req-Sent state, it doesn't signal a tld
+ * event to LCP, so LCP remains in network phase. Only after not getting
+ * any response (or after getting an unacceptable response), CHAP closes,
+ * causing LCP to enter terminate phase.
+ *
+ * With PAP, there is no initial request that can be sent. The peer is
+ * expected to send one based on the successful negotiation of PAP as
+ * the authentication protocol during the LCP option negotiation.
+ *
+ * Incoming authentication protocol requests (remote requests
+ * authentication, we are peer) don't employ a state machine at all,
+ * they are simply answered. Some peers [Ascend P50 firmware rev
+ * 4.50] react allergically when sending IPCP requests while they are
+ * still in authentication phase (thereby violating the standard that
+ * demands that these NCP packets are to be discarded), so we keep
+ * track of the peer demanding us to authenticate, and only proceed to
+ * phase network once we've seen a positive acknowledge for the
+ * authentication.
+ */
+
+/*
+ * Handle incoming CHAP packets.
+ */
+void
+sppp_chap_input(struct sppp *sp, struct mbuf *m)
+{
+ STDDCL;
+ struct lcp_header *h;
+ int len, x;
+ u_char *value, *name, digest[AUTHKEYLEN], dsize;
+ int value_len, name_len;
+ MD5_CTX ctx;
+
+ len = m->m_pkthdr.len;
+ if (len < 4) {
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "chap invalid packet length: %d bytes\n",
+ SPP_ARGS(ifp), len);
+ return;
+ }
+ h = mtod (m, struct lcp_header*);
+ if (len > ntohs (h->len))
+ len = ntohs (h->len);
+
+ switch (h->type) {
+ /* challenge, failure and success are his authproto */
+ case CHAP_CHALLENGE:
+ value = 1 + (u_char*)(h+1);
+ value_len = value[-1];
+ name = value + value_len;
+ name_len = len - value_len - 5;
+ if (name_len < 0) {
+ if (debug) {
+ log(LOG_DEBUG,
+ SPP_FMT "chap corrupted challenge "
+ "<%s id=0x%x len=%d",
+ SPP_ARGS(ifp),
+ sppp_auth_type_name(PPP_CHAP, h->type),
+ h->ident, ntohs(h->len));
+ sppp_print_bytes((u_char*) (h+1), len-4);
+ addlog(">\n");
+ }
+ break;
+ }
+
+ if (debug) {
+ log(LOG_DEBUG,
+ SPP_FMT "chap input <%s id=0x%x len=%d name=",
+ SPP_ARGS(ifp),
+ sppp_auth_type_name(PPP_CHAP, h->type), h->ident,
+ ntohs(h->len));
+ sppp_print_string((char*) name, name_len);
+ addlog(" value-size=%d value=", value_len);
+ sppp_print_bytes(value, value_len);
+ addlog(">\n");
+ }
+
+ /* Compute reply value. */
+ MD5Init(&ctx);
+ MD5Update(&ctx, &h->ident, 1);
+ MD5Update(&ctx, sp->myauth.secret,
+ sppp_strnlen(sp->myauth.secret, AUTHKEYLEN));
+ MD5Update(&ctx, value, value_len);
+ MD5Final(digest, &ctx);
+ dsize = sizeof digest;
+
+ sppp_auth_send(&chap, sp, CHAP_RESPONSE, h->ident,
+ sizeof dsize, (const char *)&dsize,
+ sizeof digest, digest,
+ (size_t)sppp_strnlen(sp->myauth.name, AUTHNAMELEN),
+ sp->myauth.name,
+ 0);
+ break;
+
+ case CHAP_SUCCESS:
+ if (debug) {
+ log(LOG_DEBUG, SPP_FMT "chap success",
+ SPP_ARGS(ifp));
+ if (len > 4) {
+ addlog(": ");
+ sppp_print_string((char*)(h + 1), len - 4);
+ }
+ addlog("\n");
+ }
+ x = splimp();
+ sp->pp_flags &= ~PP_NEEDAUTH;
+ if (sp->myauth.proto == PPP_CHAP &&
+ (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) &&
+ (sp->lcp.protos & (1 << IDX_CHAP)) == 0) {
+ /*
+ * We are authenticator for CHAP but didn't
+ * complete yet. Leave it to tlu to proceed
+ * to network phase.
+ */
+ splx(x);
+ break;
+ }
+ splx(x);
+ sppp_phase_network(sp);
+ break;
+
+ case CHAP_FAILURE:
+ if (debug) {
+ log(LOG_INFO, SPP_FMT "chap failure",
+ SPP_ARGS(ifp));
+ if (len > 4) {
+ addlog(": ");
+ sppp_print_string((char*)(h + 1), len - 4);
+ }
+ addlog("\n");
+ } else
+ log(LOG_INFO, SPP_FMT "chap failure\n",
+ SPP_ARGS(ifp));
+ /* await LCP shutdown by authenticator */
+ break;
+
+ /* response is my authproto */
+ case CHAP_RESPONSE:
+ value = 1 + (u_char*)(h+1);
+ value_len = value[-1];
+ name = value + value_len;
+ name_len = len - value_len - 5;
+ if (name_len < 0) {
+ if (debug) {
+ log(LOG_DEBUG,
+ SPP_FMT "chap corrupted response "
+ "<%s id=0x%x len=%d",
+ SPP_ARGS(ifp),
+ sppp_auth_type_name(PPP_CHAP, h->type),
+ h->ident, ntohs(h->len));
+ sppp_print_bytes((u_char*)(h+1), len-4);
+ addlog(">\n");
+ }
+ break;
+ }
+ if (h->ident != sp->confid[IDX_CHAP]) {
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "chap dropping response for old ID "
+ "(got %d, expected %d)\n",
+ SPP_ARGS(ifp),
+ h->ident, sp->confid[IDX_CHAP]);
+ break;
+ }
+ if (name_len != sppp_strnlen(sp->hisauth.name, AUTHNAMELEN)
+ || bcmp(name, sp->hisauth.name, name_len) != 0) {
+ log(LOG_INFO, SPP_FMT "chap response, his name ",
+ SPP_ARGS(ifp));
+ sppp_print_string(name, name_len);
+ addlog(" != expected ");
+ sppp_print_string(sp->hisauth.name,
+ sppp_strnlen(sp->hisauth.name, AUTHNAMELEN));
+ addlog("\n");
+ }
+ if (debug) {
+ log(LOG_DEBUG, SPP_FMT "chap input(%s) "
+ "<%s id=0x%x len=%d name=",
+ SPP_ARGS(ifp),
+ sppp_state_name(sp->state[IDX_CHAP]),
+ sppp_auth_type_name(PPP_CHAP, h->type),
+ h->ident, ntohs (h->len));
+ sppp_print_string((char*)name, name_len);
+ addlog(" value-size=%d value=", value_len);
+ sppp_print_bytes(value, value_len);
+ addlog(">\n");
+ }
+ if (value_len != AUTHKEYLEN) {
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "chap bad hash value length: "
+ "%d bytes, should be %d\n",
+ SPP_ARGS(ifp), value_len,
+ AUTHKEYLEN);
+ break;
+ }
+
+ MD5Init(&ctx);
+ MD5Update(&ctx, &h->ident, 1);
+ MD5Update(&ctx, sp->hisauth.secret,
+ sppp_strnlen(sp->hisauth.secret, AUTHKEYLEN));
+ MD5Update(&ctx, sp->myauth.challenge, AUTHKEYLEN);
+ MD5Final(digest, &ctx);
+
+#define FAILMSG "Failed..."
+#define SUCCMSG "Welcome!"
+
+ if (value_len != sizeof digest ||
+ bcmp(digest, value, value_len) != 0) {
+ /* action scn, tld */
+ sppp_auth_send(&chap, sp, CHAP_FAILURE, h->ident,
+ sizeof(FAILMSG) - 1, (u_char *)FAILMSG,
+ 0);
+ chap.tld(sp);
+ break;
+ }
+ /* action sca, perhaps tlu */
+ if (sp->state[IDX_CHAP] == STATE_REQ_SENT ||
+ sp->state[IDX_CHAP] == STATE_OPENED)
+ sppp_auth_send(&chap, sp, CHAP_SUCCESS, h->ident,
+ sizeof(SUCCMSG) - 1, (u_char *)SUCCMSG,
+ 0);
+ if (sp->state[IDX_CHAP] == STATE_REQ_SENT) {
+ sppp_cp_change_state(&chap, sp, STATE_OPENED);
+ chap.tlu(sp);
+ }
+ break;
+
+ default:
+ /* Unknown CHAP packet type -- ignore. */
+ if (debug) {
+ log(LOG_DEBUG, SPP_FMT "chap unknown input(%s) "
+ "<0x%x id=0x%xh len=%d",
+ SPP_ARGS(ifp),
+ sppp_state_name(sp->state[IDX_CHAP]),
+ h->type, h->ident, ntohs(h->len));
+ sppp_print_bytes((u_char*)(h+1), len-4);
+ addlog(">\n");
+ }
+ break;
+
+ }
+}
+
+static void
+sppp_chap_init(struct sppp *sp)
+{
+ /* Chap doesn't have STATE_INITIAL at all. */
+ sp->state[IDX_CHAP] = STATE_CLOSED;
+ sp->fail_counter[IDX_CHAP] = 0;
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ callout_handle_init(&sp->ch[IDX_CHAP]);
+#endif
+}
+
+static void
+sppp_chap_open(struct sppp *sp)
+{
+ if (sp->myauth.proto == PPP_CHAP &&
+ (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0) {
+ /* we are authenticator for CHAP, start it */
+ chap.scr(sp);
+ sp->rst_counter[IDX_CHAP] = sp->lcp.max_configure;
+ sppp_cp_change_state(&chap, sp, STATE_REQ_SENT);
+ }
+ /* nothing to be done if we are peer, await a challenge */
+}
+
+static void
+sppp_chap_close(struct sppp *sp)
+{
+ if (sp->state[IDX_CHAP] != STATE_CLOSED)
+ sppp_cp_change_state(&chap, sp, STATE_CLOSED);
+}
+
+static void
+sppp_chap_TO(void *cookie)
+{
+ struct sppp *sp = (struct sppp *)cookie;
+ STDDCL;
+ int s;
+
+ s = splimp();
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "chap TO(%s) rst_counter = %d\n",
+ SPP_ARGS(ifp),
+ sppp_state_name(sp->state[IDX_CHAP]),
+ sp->rst_counter[IDX_CHAP]);
+
+ if (--sp->rst_counter[IDX_CHAP] < 0)
+ /* TO- event */
+ switch (sp->state[IDX_CHAP]) {
+ case STATE_REQ_SENT:
+ chap.tld(sp);
+ sppp_cp_change_state(&chap, sp, STATE_CLOSED);
+ break;
+ }
+ else
+ /* TO+ (or TO*) event */
+ switch (sp->state[IDX_CHAP]) {
+ case STATE_OPENED:
+ /* TO* event */
+ sp->rst_counter[IDX_CHAP] = sp->lcp.max_configure;
+ /* fall through */
+ case STATE_REQ_SENT:
+ chap.scr(sp);
+ /* sppp_cp_change_state() will restart the timer */
+ sppp_cp_change_state(&chap, sp, STATE_REQ_SENT);
+ break;
+ }
+
+ splx(s);
+}
+
+static void
+sppp_chap_tlu(struct sppp *sp)
+{
+ STDDCL;
+ int i, x;
+
+ i = 0;
+ sp->rst_counter[IDX_CHAP] = sp->lcp.max_configure;
+
+ /*
+ * Some broken CHAP implementations (Conware CoNet, firmware
+ * 4.0.?) don't want to re-authenticate their CHAP once the
+ * initial challenge-response exchange has taken place.
+ * Provide for an option to avoid rechallenges.
+ */
+ if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0) {
+ /*
+ * Compute the re-challenge timeout. This will yield
+ * a number between 300 and 810 seconds.
+ */
+ i = 300 + ((unsigned)(random() & 0xff00) >> 7);
+ TIMEOUT(chap.TO, (void *)sp, i * hz, sp->ch[IDX_CHAP]);
+ }
+
+ if (debug) {
+ log(LOG_DEBUG,
+ SPP_FMT "chap %s, ",
+ SPP_ARGS(ifp),
+ sp->pp_phase == PHASE_NETWORK? "reconfirmed": "tlu");
+ if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0)
+ addlog("next re-challenge in %d seconds\n", i);
+ else
+ addlog("re-challenging supressed\n");
+ }
+
+ x = splimp();
+ /* indicate to LCP that we need to be closed down */
+ sp->lcp.protos |= (1 << IDX_CHAP);
+
+ if (sp->pp_flags & PP_NEEDAUTH) {
+ /*
+ * Remote is authenticator, but his auth proto didn't
+ * complete yet. Defer the transition to network
+ * phase.
+ */
+ splx(x);
+ return;
+ }
+ splx(x);
+
+ /*
+ * If we are already in phase network, we are done here. This
+ * is the case if this is a dummy tlu event after a re-challenge.
+ */
+ if (sp->pp_phase != PHASE_NETWORK)
+ sppp_phase_network(sp);
+}
+
+static void
+sppp_chap_tld(struct sppp *sp)
+{
+ STDDCL;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "chap tld\n", SPP_ARGS(ifp));
+ UNTIMEOUT(chap.TO, (void *)sp, sp->ch[IDX_CHAP]);
+ sp->lcp.protos &= ~(1 << IDX_CHAP);
+
+ lcp.Close(sp);
+}
+
+static void
+sppp_chap_scr(struct sppp *sp)
+{
+#if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
+ struct timeval tv;
+#endif
+ u_long *ch, seed;
+ u_char clen;
+
+ /* Compute random challenge. */
+ ch = (u_long *)sp->myauth.challenge;
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+
+#ifdef RANDOMDEV
+ read_random(&seed, sizeof seed);
+#else
+ seed = (u_long)random();
+#endif /* RANDOMDEV */
+
+#else
+ microtime(&tv);
+ seed = tv.tv_sec ^ tv.tv_usec;
+#endif
+ ch[0] = seed ^ random();
+ ch[1] = seed ^ random();
+ ch[2] = seed ^ random();
+ ch[3] = seed ^ random();
+ clen = AUTHKEYLEN;
+
+ sp->confid[IDX_CHAP] = ++sp->pp_seq;
+
+ sppp_auth_send(&chap, sp, CHAP_CHALLENGE, sp->confid[IDX_CHAP],
+ sizeof clen, (const char *)&clen,
+ (size_t)AUTHKEYLEN, sp->myauth.challenge,
+ (size_t)sppp_strnlen(sp->myauth.name, AUTHNAMELEN),
+ sp->myauth.name,
+ 0);
+}
+ /*
+ *--------------------------------------------------------------------------*
+ * *
+ * The PAP implementation. *
+ * *
+ *--------------------------------------------------------------------------*
+ */
+/*
+ * For PAP, we need to keep a little state also if we are the peer, not the
+ * authenticator. This is since we don't get a request to authenticate, but
+ * have to repeatedly authenticate ourself until we got a response (or the
+ * retry counter is expired).
+ */
+
+/*
+ * Handle incoming PAP packets. */
+static void
+sppp_pap_input(struct sppp *sp, struct mbuf *m)
+{
+ STDDCL;
+ struct lcp_header *h;
+ int len, x;
+ u_char *name, *passwd, mlen;
+ int name_len, passwd_len;
+
+ len = m->m_pkthdr.len;
+ if (len < 5) {
+ if (debug)
+ log(LOG_DEBUG,
+ SPP_FMT "pap invalid packet length: %d bytes\n",
+ SPP_ARGS(ifp), len);
+ return;
+ }
+ h = mtod (m, struct lcp_header*);
+ if (len > ntohs (h->len))
+ len = ntohs (h->len);
+ switch (h->type) {
+ /* PAP request is my authproto */
+ case PAP_REQ:
+ name = 1 + (u_char*)(h+1);
+ name_len = name[-1];
+ passwd = name + name_len + 1;
+ if (name_len > len - 6 ||
+ (passwd_len = passwd[-1]) > len - 6 - name_len) {
+ if (debug) {
+ log(LOG_DEBUG, SPP_FMT "pap corrupted input "
+ "<%s id=0x%x len=%d",
+ SPP_ARGS(ifp),
+ sppp_auth_type_name(PPP_PAP, h->type),
+ h->ident, ntohs(h->len));
+ sppp_print_bytes((u_char*)(h+1), len-4);
+ addlog(">\n");
+ }
+ break;
+ }
+ if (debug) {
+ log(LOG_DEBUG, SPP_FMT "pap input(%s) "
+ "<%s id=0x%x len=%d name=",
+ SPP_ARGS(ifp),
+ sppp_state_name(sp->state[IDX_PAP]),
+ sppp_auth_type_name(PPP_PAP, h->type),
+ h->ident, ntohs(h->len));
+ sppp_print_string((char*)name, name_len);
+ addlog(" passwd=");
+ sppp_print_string((char*)passwd, passwd_len);
+ addlog(">\n");
+ }
+ if (name_len > AUTHNAMELEN ||
+ passwd_len > AUTHKEYLEN ||
+ bcmp(name, sp->hisauth.name, name_len) != 0 ||
+ bcmp(passwd, sp->hisauth.secret, passwd_len) != 0) {
+ /* action scn, tld */
+ mlen = sizeof(FAILMSG) - 1;
+ sppp_auth_send(&pap, sp, PAP_NAK, h->ident,
+ sizeof mlen, (const char *)&mlen,
+ sizeof(FAILMSG) - 1, (u_char *)FAILMSG,
+ 0);
+ pap.tld(sp);
+ break;
+ }
+ /* action sca, perhaps tlu */
+ if (sp->state[IDX_PAP] == STATE_REQ_SENT ||
+ sp->state[IDX_PAP] == STATE_OPENED) {
+ mlen = sizeof(SUCCMSG) - 1;
+ sppp_auth_send(&pap, sp, PAP_ACK, h->ident,
+ sizeof mlen, (const char *)&mlen,
+ sizeof(SUCCMSG) - 1, (u_char *)SUCCMSG,
+ 0);
+ }
+ if (sp->state[IDX_PAP] == STATE_REQ_SENT) {
+ sppp_cp_change_state(&pap, sp, STATE_OPENED);
+ pap.tlu(sp);
+ }
+ break;
+
+ /* ack and nak are his authproto */
+ case PAP_ACK:
+ UNTIMEOUT(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch);
+ if (debug) {
+ log(LOG_DEBUG, SPP_FMT "pap success",
+ SPP_ARGS(ifp));
+ name_len = *((char *)h);
+ if (len > 5 && name_len) {
+ addlog(": ");
+ sppp_print_string((char*)(h+1), name_len);
+ }
+ addlog("\n");
+ }
+ x = splimp();
+ sp->pp_flags &= ~PP_NEEDAUTH;
+ if (sp->myauth.proto == PPP_PAP &&
+ (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) &&
+ (sp->lcp.protos & (1 << IDX_PAP)) == 0) {
+ /*
+ * We are authenticator for PAP but didn't
+ * complete yet. Leave it to tlu to proceed
+ * to network phase.
+ */
+ splx(x);
+ break;
+ }
+ splx(x);
+ sppp_phase_network(sp);
+ break;
+
+ case PAP_NAK:
+ UNTIMEOUT(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch);
+ if (debug) {
+ log(LOG_INFO, SPP_FMT "pap failure",
+ SPP_ARGS(ifp));
+ name_len = *((char *)h);
+ if (len > 5 && name_len) {
+ addlog(": ");
+ sppp_print_string((char*)(h+1), name_len);
+ }
+ addlog("\n");
+ } else
+ log(LOG_INFO, SPP_FMT "pap failure\n",
+ SPP_ARGS(ifp));
+ /* await LCP shutdown by authenticator */
+ break;
+
+ default:
+ /* Unknown PAP packet type -- ignore. */
+ if (debug) {
+ log(LOG_DEBUG, SPP_FMT "pap corrupted input "
+ "<0x%x id=0x%x len=%d",
+ SPP_ARGS(ifp),
+ h->type, h->ident, ntohs(h->len));
+ sppp_print_bytes((u_char*)(h+1), len-4);
+ addlog(">\n");
+ }
+ break;
+
+ }
+}
+
+static void
+sppp_pap_init(struct sppp *sp)
+{
+ /* PAP doesn't have STATE_INITIAL at all. */
+ sp->state[IDX_PAP] = STATE_CLOSED;
+ sp->fail_counter[IDX_PAP] = 0;
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ callout_handle_init(&sp->ch[IDX_PAP]);
+ callout_handle_init(&sp->pap_my_to_ch);
+#endif
+}
+
+static void
+sppp_pap_open(struct sppp *sp)
+{
+ if (sp->hisauth.proto == PPP_PAP &&
+ (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0) {
+ /* we are authenticator for PAP, start our timer */
+ sp->rst_counter[IDX_PAP] = sp->lcp.max_configure;
+ sppp_cp_change_state(&pap, sp, STATE_REQ_SENT);
+ }
+ if (sp->myauth.proto == PPP_PAP) {
+ /* we are peer, send a request, and start a timer */
+ pap.scr(sp);
+ TIMEOUT(sppp_pap_my_TO, (void *)sp, sp->lcp.timeout,
+ sp->pap_my_to_ch);
+ }
+}
+
+static void
+sppp_pap_close(struct sppp *sp)
+{
+ if (sp->state[IDX_PAP] != STATE_CLOSED)
+ sppp_cp_change_state(&pap, sp, STATE_CLOSED);
+}
+
+/*
+ * That's the timeout routine if we are authenticator. Since the
+ * authenticator is basically passive in PAP, we can't do much here.
+ */
+static void
+sppp_pap_TO(void *cookie)
+{
+ struct sppp *sp = (struct sppp *)cookie;
+ STDDCL;
+ int s;
+
+ s = splimp();
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "pap TO(%s) rst_counter = %d\n",
+ SPP_ARGS(ifp),
+ sppp_state_name(sp->state[IDX_PAP]),
+ sp->rst_counter[IDX_PAP]);
+
+ if (--sp->rst_counter[IDX_PAP] < 0)
+ /* TO- event */
+ switch (sp->state[IDX_PAP]) {
+ case STATE_REQ_SENT:
+ pap.tld(sp);
+ sppp_cp_change_state(&pap, sp, STATE_CLOSED);
+ break;
+ }
+ else
+ /* TO+ event, not very much we could do */
+ switch (sp->state[IDX_PAP]) {
+ case STATE_REQ_SENT:
+ /* sppp_cp_change_state() will restart the timer */
+ sppp_cp_change_state(&pap, sp, STATE_REQ_SENT);
+ break;
+ }
+
+ splx(s);
+}
+
+/*
+ * That's the timeout handler if we are peer. Since the peer is active,
+ * we need to retransmit our PAP request since it is apparently lost.
+ * XXX We should impose a max counter.
+ */
+static void
+sppp_pap_my_TO(void *cookie)
+{
+ struct sppp *sp = (struct sppp *)cookie;
+ STDDCL;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "pap peer TO\n",
+ SPP_ARGS(ifp));
+
+ pap.scr(sp);
+}
+
+static void
+sppp_pap_tlu(struct sppp *sp)
+{
+ STDDCL;
+ int x;
+
+ sp->rst_counter[IDX_PAP] = sp->lcp.max_configure;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "%s tlu\n",
+ SPP_ARGS(ifp), pap.name);
+
+ x = splimp();
+ /* indicate to LCP that we need to be closed down */
+ sp->lcp.protos |= (1 << IDX_PAP);
+
+ if (sp->pp_flags & PP_NEEDAUTH) {
+ /*
+ * Remote is authenticator, but his auth proto didn't
+ * complete yet. Defer the transition to network
+ * phase.
+ */
+ splx(x);
+ return;
+ }
+ splx(x);
+ sppp_phase_network(sp);
+}
+
+static void
+sppp_pap_tld(struct sppp *sp)
+{
+ STDDCL;
+
+ if (debug)
+ log(LOG_DEBUG, SPP_FMT "pap tld\n", SPP_ARGS(ifp));
+ UNTIMEOUT(pap.TO, (void *)sp, sp->ch[IDX_PAP]);
+ UNTIMEOUT(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch);
+ sp->lcp.protos &= ~(1 << IDX_PAP);
+
+ lcp.Close(sp);
+}
+
+static void
+sppp_pap_scr(struct sppp *sp)
+{
+ u_char idlen, pwdlen;
+
+ sp->confid[IDX_PAP] = ++sp->pp_seq;
+ pwdlen = sppp_strnlen(sp->myauth.secret, AUTHKEYLEN);
+ idlen = sppp_strnlen(sp->myauth.name, AUTHNAMELEN);
+
+ sppp_auth_send(&pap, sp, PAP_REQ, sp->confid[IDX_PAP],
+ sizeof idlen, (const char *)&idlen,
+ (size_t)idlen, sp->myauth.name,
+ sizeof pwdlen, (const char *)&pwdlen,
+ (size_t)pwdlen, sp->myauth.secret,
+ 0);
+}
+ /*
+ * Random miscellaneous functions.
+ */
+
+/*
+ * Send a PAP or CHAP proto packet.
+ *
+ * Varadic function, each of the elements for the ellipsis is of type
+ * ``size_t mlen, const u_char *msg''. Processing will stop iff
+ * mlen == 0.
+ * NOTE: never declare variadic functions with types subject to type
+ * promotion (i.e. u_char). This is asking for big trouble depending
+ * on the architecture you are on...
+ */
+
+static void
+sppp_auth_send(const struct cp *cp, struct sppp *sp,
+ unsigned int type, unsigned int id,
+ ...)
+{
+ STDDCL;
+ struct ppp_header *h;
+ struct lcp_header *lh;
+ struct mbuf *m;
+ u_char *p;
+ int len;
+ unsigned int mlen;
+ const char *msg;
+ va_list ap;
+
+ MGETHDR (m, M_DONTWAIT, MT_DATA);
+ if (! m)
+ return;
+ m->m_pkthdr.rcvif = 0;
+
+ h = mtod (m, struct ppp_header*);
+ h->address = PPP_ALLSTATIONS; /* broadcast address */
+ h->control = PPP_UI; /* Unnumbered Info */
+ h->protocol = htons(cp->proto);
+
+ lh = (struct lcp_header*)(h + 1);
+ lh->type = type;
+ lh->ident = id;
+ p = (u_char*) (lh+1);
+
+ va_start(ap, id);
+ len = 0;
+
+ while ((mlen = (unsigned int)va_arg(ap, size_t)) != 0) {
+ msg = va_arg(ap, const char *);
+ len += mlen;
+ if (len > MHLEN - PPP_HEADER_LEN - LCP_HEADER_LEN) {
+ va_end(ap);
+ m_freem(m);
+ return;
+ }
+
+ bcopy(msg, p, mlen);
+ p += mlen;
+ }
+ va_end(ap);
+
+ m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + LCP_HEADER_LEN + len;
+ lh->len = htons (LCP_HEADER_LEN + len);
+
+ if (debug) {
+ log(LOG_DEBUG, SPP_FMT "%s output <%s id=0x%x len=%d",
+ SPP_ARGS(ifp), cp->name,
+ sppp_auth_type_name(cp->proto, lh->type),
+ lh->ident, ntohs(lh->len));
+ sppp_print_bytes((u_char*) (lh+1), len);
+ addlog(">\n");
+ }
+ if (IF_QFULL (&sp->pp_cpq)) {
+ IF_DROP (&sp->pp_fastq);
+ IF_DROP (&ifp->if_snd);
+ m_freem (m);
+ ++ifp->if_oerrors;
+ } else
+ IF_ENQUEUE (&sp->pp_cpq, m);
+ if (! (ifp->if_flags & IFF_OACTIVE))
+ (*ifp->if_start) (ifp);
+ ifp->if_obytes += m->m_pkthdr.len + 3;
+}
+
+/*
+ * Flush interface queue.
+ */
+static void
+sppp_qflush(struct ifqueue *ifq)
+{
+ struct mbuf *m, *n;
+
+ n = ifq->ifq_head;
+ while ((m = n)) {
+ n = m->m_act;
+ m_freem (m);
+ }
+ ifq->ifq_head = 0;
+ ifq->ifq_tail = 0;
+ ifq->ifq_len = 0;
+}
+
+/*
+ * Send keepalive packets, every 10 seconds.
+ */
+static void
+sppp_keepalive(void *dummy)
+{
+ struct sppp *sp;
+ int s;
+
+ s = splimp();
+ for (sp=spppq; sp; sp=sp->pp_next) {
+ struct ifnet *ifp = &sp->pp_if;
+
+ /* Keepalive mode disabled or channel down? */
+ if (! (sp->pp_flags & PP_KEEPALIVE) ||
+ ! (ifp->if_flags & IFF_RUNNING))
+ continue;
+
+ /* No keepalive in PPP mode if LCP not opened yet. */
+ if (sp->pp_mode != IFF_CISCO &&
+ sp->pp_phase < PHASE_AUTHENTICATE)
+ continue;
+
+ if (sp->pp_alivecnt == MAXALIVECNT) {
+ /* No keepalive packets got. Stop the interface. */
+ printf (SPP_FMT "down\n", SPP_ARGS(ifp));
+ if_down (ifp);
+ sppp_qflush (&sp->pp_cpq);
+ if (sp->pp_mode != IFF_CISCO) {
+ /* XXX */
+ /* Shut down the PPP link. */
+ lcp.Down(sp);
+ /* Initiate negotiation. XXX */
+ lcp.Up(sp);
+ }
+ }
+ if (sp->pp_alivecnt <= MAXALIVECNT)
+ ++sp->pp_alivecnt;
+ if (sp->pp_mode == IFF_CISCO)
+ sppp_cisco_send (sp, CISCO_KEEPALIVE_REQ, ++sp->pp_seq,
+ sp->pp_rseq);
+ else if (sp->pp_phase >= PHASE_AUTHENTICATE) {
+ long nmagic = htonl (sp->lcp.magic);
+ sp->lcp.echoid = ++sp->pp_seq;
+ sppp_cp_send (sp, PPP_LCP, ECHO_REQ,
+ sp->lcp.echoid, 4, &nmagic);
+ }
+ }
+ splx(s);
+ TIMEOUT(sppp_keepalive, 0, hz * 10, keepalive_ch);
+}
+
+/*
+ * Get both IP addresses.
+ */
+static void
+sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst, u_long *srcmask)
+{
+ struct ifnet *ifp = &sp->pp_if;
+ struct ifaddr *ifa;
+ struct sockaddr_in *si, *sm;
+ u_long ssrc, ddst;
+
+ sm = NULL;
+ ssrc = ddst = 0L;
+ /*
+ * Pick the first AF_INET address from the list,
+ * aliases don't make any sense on a p2p link anyway.
+ */
+ si = 0;
+
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
+#elif defined(__NetBSD__) || defined (__OpenBSD__)
+ for (ifa = ifp->if_addrlist.tqh_first;
+ ifa;
+ ifa = ifa->ifa_list.tqe_next)
+#else
+ for (ifa = ifp->if_addrlist;
+ ifa;
+ ifa = ifa->ifa_next)
+#endif
+ if (ifa->ifa_addr->sa_family == AF_INET) {
+ si = (struct sockaddr_in *)ifa->ifa_addr;
+ sm = (struct sockaddr_in *)ifa->ifa_netmask;
+ if (si)
+ break;
+ }
+ if (ifa) {
+ if (si && si->sin_addr.s_addr) {
+ ssrc = si->sin_addr.s_addr;
+ if (srcmask)
+ *srcmask = ntohl(sm->sin_addr.s_addr);
+ }
+
+ si = (struct sockaddr_in *)ifa->ifa_dstaddr;
+ if (si && si->sin_addr.s_addr)
+ ddst = si->sin_addr.s_addr;
+ }
+
+ if (dst) *dst = ntohl(ddst);
+ if (src) *src = ntohl(ssrc);
+}
+
+/*
+ * Set my IP address. Must be called at splimp.
+ */
+static void
+sppp_set_ip_addr(struct sppp *sp, u_long src)
+{
+ STDDCL;
+ struct ifaddr *ifa;
+ struct sockaddr_in *si;
+
+ /*
+ * Pick the first AF_INET address from the list,
+ * aliases don't make any sense on a p2p link anyway.
+ */
+ si = 0;
+
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
+#elif defined(__NetBSD__) || defined (__OpenBSD__)
+ for (ifa = ifp->if_addrlist.tqh_first;
+ ifa;
+ ifa = ifa->ifa_list.tqe_next)
+#else
+ for (ifa = ifp->if_addrlist;
+ ifa;
+ ifa = ifa->ifa_next)
+#endif
+ {
+ if (ifa->ifa_addr->sa_family == AF_INET)
+ {
+ si = (struct sockaddr_in *)ifa->ifa_addr;
+ if (si)
+ break;
+ }
+ }
+
+ if (ifa && si)
+ {
+ int error;
+#if __NetBSD_Version__ >= 103080000
+ struct sockaddr_in new_sin = *si;
+
+ new_sin.sin_addr.s_addr = htonl(src);
+ error = in_ifinit(ifp, ifatoia(ifa), &new_sin, 1);
+ if(debug && error)
+ {
+ log(LOG_DEBUG, SPP_FMT "sppp_set_ip_addr: in_ifinit "
+ " failed, error=%d\n", SPP_ARGS(ifp), error);
+ }
+#else
+ /* delete old route */
+ error = rtinit(ifa, (int)RTM_DELETE, RTF_HOST);
+ if(debug && error)
+ {
+ log(LOG_DEBUG, SPP_FMT "sppp_set_ip_addr: rtinit DEL failed, error=%d\n",
+ SPP_ARGS(ifp), error);
+ }
+
+ /* set new address */
+ si->sin_addr.s_addr = htonl(src);
+
+ /* add new route */
+ error = rtinit(ifa, (int)RTM_ADD, RTF_HOST);
+ if (debug && error)
+ {
+ log(LOG_DEBUG, SPP_FMT "sppp_set_ip_addr: rtinit ADD failed, error=%d",
+ SPP_ARGS(ifp), error);
+ }
+#endif
+ }
+}
+
+static int
+sppp_params(struct sppp *sp, IOCTL_CMD_T cmd, void *data)
+{
+ struct ifreq *ifr = (struct ifreq *)data;
+ int ret;
+ struct spppreq *sppprp;
+
+ if((sppprp = (struct spppreq *)malloc(sizeof(struct spppreq),
+ M_TEMP, M_WAITOK)) == NULL)
+ {
+ printf("i4bsppp, sppp_params: malloc failed!\n");
+ return EFAULT;
+ }
+
+ /*
+ * ifr->ifr_data is supposed to point to a struct spppreq.
+ */
+ if (copyin((caddr_t)ifr->ifr_data, sppprp, sizeof(struct spppreq)) != 0)
+ {
+ free(sppprp, M_TEMP);
+ return EFAULT;
+ }
+
+ switch (sppprp->cmd) {
+ case SPPPIOGDEFS:
+ if (cmd != SIOCGIFGENERIC)
+ {
+ free(sppprp, M_TEMP);
+ return EINVAL;
+ }
+ /*
+ * We copy over the entire current state, but clean
+ * out some of the stuff we don't wanna pass up.
+ * Remember, SIOCGIFGENERIC is unprotected, and can be
+ * called by any user. No need to ever get PAP or
+ * CHAP secrets back to userland anyway.
+ */
+ bcopy(sp, &sppprp->defs, sizeof(struct sppp));
+ bzero(sppprp->defs.myauth.secret, AUTHKEYLEN);
+ bzero(sppprp->defs.myauth.challenge, AUTHKEYLEN);
+ bzero(sppprp->defs.hisauth.secret, AUTHKEYLEN);
+ bzero(sppprp->defs.hisauth.challenge, AUTHKEYLEN);
+ ret = copyout(sppprp, (caddr_t)ifr->ifr_data, sizeof(struct spppreq));
+ free(sppprp, M_TEMP);
+ return(ret);
+
+ case SPPPIOSDEFS:
+ if (cmd != SIOCSIFGENERIC)
+ {
+ free(sppprp, M_TEMP);
+ return EINVAL;
+ }
+ /*
+ * We have a very specific idea of which fields we allow
+ * being passed back from userland, so to not clobber our
+ * current state. For one, we only allow setting
+ * anything if LCP is in dead phase. Once the LCP
+ * negotiations started, the authentication settings must
+ * not be changed again. (The administrator can force an
+ * ifconfig down in order to get LCP back into dead
+ * phase.)
+ *
+ * Also, we only allow for authentication parameters to be
+ * specified.
+ *
+ * XXX Should allow to set or clear pp_flags.
+ *
+ * Finally, if the respective authentication protocol to
+ * be used is set differently than 0, but the secret is
+ * passed as all zeros, we don't trash the existing secret.
+ * This allows an administrator to change the system name
+ * only without clobbering the secret (which he didn't get
+ * back in a previous SPPPIOGDEFS call). However, the
+ * secrets are cleared if the authentication protocol is
+ * reset to 0.
+ */
+ if (!((sp->pp_phase == PHASE_DEAD) ||
+ (sp->pp_phase == PHASE_ESTABLISH)))
+ {
+ free(sppprp, M_TEMP);
+ return EBUSY;
+ }
+
+ if ((sppprp->defs.myauth.proto != 0 && sppprp->defs.myauth.proto != PPP_PAP &&
+ sppprp->defs.myauth.proto != PPP_CHAP) ||
+ (sppprp->defs.hisauth.proto != 0 && sppprp->defs.hisauth.proto != PPP_PAP &&
+ sppprp->defs.hisauth.proto != PPP_CHAP))
+ {
+ free(sppprp, M_TEMP);
+ return EINVAL;
+ }
+
+ if (sppprp->defs.myauth.proto == 0)
+ /* resetting myauth */
+ bzero(&sp->myauth, sizeof sp->myauth);
+ else {
+ /* setting/changing myauth */
+ sp->myauth.proto = sppprp->defs.myauth.proto;
+ bcopy(sppprp->defs.myauth.name, sp->myauth.name, AUTHNAMELEN);
+ if (sppprp->defs.myauth.secret[0] != '\0')
+ bcopy(sppprp->defs.myauth.secret, sp->myauth.secret,
+ AUTHKEYLEN);
+ }
+ if (sppprp->defs.hisauth.proto == 0)
+ /* resetting hisauth */
+ bzero(&sp->hisauth, sizeof sp->hisauth);
+ else {
+ /* setting/changing hisauth */
+ sp->hisauth.proto = sppprp->defs.hisauth.proto;
+ sp->hisauth.flags = sppprp->defs.hisauth.flags;
+ bcopy(sppprp->defs.hisauth.name, sp->hisauth.name, AUTHNAMELEN);
+ if (sppprp->defs.hisauth.secret[0] != '\0')
+ bcopy(sppprp->defs.hisauth.secret, sp->hisauth.secret,
+ AUTHKEYLEN);
+ }
+ if (sppprp->defs.lcp.timeout != 0) {
+ /* Set the LCP timeout */
+ sp->lcp.timeout = sppprp->defs.lcp.timeout;
+ }
+
+ /* Set enable VJ compression */
+ sp->enable_vj = sppprp->defs.enable_vj;
+
+ break;
+
+ default:
+ free(sppprp, M_TEMP);
+ return EINVAL;
+ }
+ free(sppprp, M_TEMP);
+ return 0;
+}
+
+static void
+sppp_phase_network(struct sppp *sp)
+{
+ STDDCL;
+ int i;
+ u_long mask;
+
+ sp->pp_phase = PHASE_NETWORK;
+
+ if(debug)
+ log(LOG_DEBUG, SPP_FMT "phase %s\n", SPP_ARGS(ifp),
+ sppp_phase_name(sp->pp_phase));
+
+ /* Notify NCPs now. */
+ for (i = 0; i < IDX_COUNT; i++)
+ if ((cps[i])->flags & CP_NCP)
+ (cps[i])->Open(sp);
+
+ /* Send Up events to all NCPs. */
+ for (i = 0, mask = 1; i < IDX_COUNT; i++, mask <<= 1)
+ if (sp->lcp.protos & mask && ((cps[i])->flags & CP_NCP))
+ (cps[i])->Up(sp);
+
+ /* if no NCP is starting, all this was in vain, close down */
+ sppp_lcp_check_and_close(sp);
+}
+
+
+static const char *
+sppp_cp_type_name(u_char type)
+{
+ static char buf[12];
+ switch (type) {
+ case CONF_REQ: return "conf-req";
+ case CONF_ACK: return "conf-ack";
+ case CONF_NAK: return "conf-nak";
+ case CONF_REJ: return "conf-rej";
+ case TERM_REQ: return "term-req";
+ case TERM_ACK: return "term-ack";
+ case CODE_REJ: return "code-rej";
+ case PROTO_REJ: return "proto-rej";
+ case ECHO_REQ: return "echo-req";
+ case ECHO_REPLY: return "echo-reply";
+ case DISC_REQ: return "discard-req";
+ }
+#ifdef HAS_SNPRINTF
+ snprintf (buf, sizeof(buf), "cp/0x%x", type);
+#else
+ sprintf (buf, "cp/0x%x", type);
+#endif
+ return buf;
+}
+
+static const char *
+sppp_auth_type_name(u_short proto, u_char type)
+{
+ static char buf[12];
+ switch (proto) {
+ case PPP_CHAP:
+ switch (type) {
+ case CHAP_CHALLENGE: return "challenge";
+ case CHAP_RESPONSE: return "response";
+ case CHAP_SUCCESS: return "success";
+ case CHAP_FAILURE: return "failure";
+ }
+ case PPP_PAP:
+ switch (type) {
+ case PAP_REQ: return "req";
+ case PAP_ACK: return "ack";
+ case PAP_NAK: return "nak";
+ }
+ }
+#ifdef HAS_SNPRINTF
+ snprintf (buf, sizeof(buf), "auth/0x%x", type);
+#else
+ sprintf (buf, "auth/0x%x", type);
+#endif
+ return buf;
+}
+
+static const char *
+sppp_lcp_opt_name(u_char opt)
+{
+ static char buf[12];
+ switch (opt) {
+ case LCP_OPT_MRU: return "mru";
+ case LCP_OPT_ASYNC_MAP: return "async-map";
+ case LCP_OPT_AUTH_PROTO: return "auth-proto";
+ case LCP_OPT_QUAL_PROTO: return "qual-proto";
+ case LCP_OPT_MAGIC: return "magic";
+ case LCP_OPT_PROTO_COMP: return "proto-comp";
+ case LCP_OPT_ADDR_COMP: return "addr-comp";
+ }
+#ifdef HAS_SNPRINTF
+ snprintf (buf, sizeof(buf), "lcp/0x%x", opt);
+#else
+ sprintf (buf, "lcp/0x%x", opt);
+#endif
+ return buf;
+}
+
+static const char *
+sppp_ipcp_opt_name(u_char opt)
+{
+ static char buf[12];
+ switch (opt) {
+ case IPCP_OPT_ADDRESSES: return "addresses";
+ case IPCP_OPT_COMPRESSION: return "compression";
+ case IPCP_OPT_ADDRESS: return "address";
+ }
+#ifdef HAS_SNPRINTF
+ snprintf (buf, sizeof(buf), "ipcp/0x%x", opt);
+#else
+ sprintf (buf, "ipcp/0x%x", opt);
+#endif
+ return buf;
+}
+
+static const char *
+sppp_state_name(int state)
+{
+ switch (state) {
+ case STATE_INITIAL: return "initial";
+ case STATE_STARTING: return "starting";
+ case STATE_CLOSED: return "closed";
+ case STATE_STOPPED: return "stopped";
+ case STATE_CLOSING: return "closing";
+ case STATE_STOPPING: return "stopping";
+ case STATE_REQ_SENT: return "req-sent";
+ case STATE_ACK_RCVD: return "ack-rcvd";
+ case STATE_ACK_SENT: return "ack-sent";
+ case STATE_OPENED: return "opened";
+ }
+ return "illegal";
+}
+
+static const char *
+sppp_phase_name(enum ppp_phase phase)
+{
+ switch (phase) {
+ case PHASE_DEAD: return "dead";
+ case PHASE_ESTABLISH: return "establish";
+ case PHASE_TERMINATE: return "terminate";
+ case PHASE_AUTHENTICATE: return "authenticate";
+ case PHASE_NETWORK: return "network";
+ }
+ return "illegal";
+}
+
+static const char *
+sppp_proto_name(u_short proto)
+{
+ static char buf[12];
+ switch (proto) {
+ case PPP_LCP: return "lcp";
+ case PPP_IPCP: return "ipcp";
+ case PPP_PAP: return "pap";
+ case PPP_CHAP: return "chap";
+ }
+#ifdef HAS_SNPRINTF
+ snprintf(buf, sizeof(buf), "proto/0x%x", (unsigned)proto);
+#else
+ sprintf(buf, "proto/0x%x", (unsigned)proto);
+#endif
+ return buf;
+}
+
+static void
+sppp_print_bytes(const u_char *p, u_short len)
+{
+#if defined(__FreeBSD_version) && (__FreeBSD_version > 300005)
+ if (len)
+ addlog(" %*D", len, p, "-");
+#else
+ if (!len)
+ return;
+
+ addlog("%x", *p++);
+ while (--len)
+ addlog("-%x", *p++);
+#endif
+}
+
+static void
+sppp_print_string(const char *p, u_short len)
+{
+ u_char c;
+
+ while (len-- > 0) {
+ c = *p++;
+ /*
+ * Print only ASCII chars directly. RFC 1994 recommends
+ * using only them, but we don't rely on it. */
+ if (c < ' ' || c > '~')
+ addlog("\\x%x", c);
+ else
+ addlog("%c", c);
+ }
+}
+
+static const char *
+sppp_dotted_quad(u_long addr)
+{
+ static char s[16];
+ sprintf(s, "%d.%d.%d.%d",
+ (int)((addr >> 24) & 0xff),
+ (int)((addr >> 16) & 0xff),
+ (int)((addr >> 8) & 0xff),
+ (int)(addr & 0xff));
+ return s;
+}
+
+static int
+sppp_strnlen(u_char *p, int max)
+{
+ int len;
+
+ for (len = 0; len < max && *p; ++p)
+ ++len;
+ return len;
+}
+
+/* a dummy, used to drop uninteresting events */
+static void
+sppp_null(struct sppp *unused)
+{
+ /* do just nothing */
+}
diff --git a/sys/i4b/driver/i4b_rbch.c b/sys/i4b/driver/i4b_rbch.c
index d4c9225..53af7bc 100644
--- a/sys/i4b/driver/i4b_rbch.c
+++ b/sys/i4b/driver/i4b_rbch.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
+ * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,11 +27,11 @@
* i4b_rbch.c - device driver for raw B channel data
* ---------------------------------------------------
*
- * $Id: i4b_rbch.c,v 1.48 1999/12/13 21:25:24 hm Exp $
+ * $Id: i4b_rbch.c,v 1.52 2000/10/06 08:37:43 hm Exp $
*
* $FreeBSD$
*
- * last edit-date: [Mon Dec 13 21:39:15 1999]
+ * last edit-date: [Mon Oct 2 10:13:09 2000]
*
*---------------------------------------------------------------------------*/
@@ -51,14 +51,29 @@
#include <sys/proc.h>
#include <sys/tty.h>
+#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
+#include <sys/callout.h>
+#endif
+
#if defined (__NetBSD__) || defined (__OpenBSD__)
extern cc_t ttydefchars;
#define termioschars(t) memcpy((t)->c_cc, &ttydefchars, sizeof((t)->c_cc))
#endif
+#ifdef __FreeBSD__
+
+#if defined(__FreeBSD__) && __FreeBSD__ == 3
+#include "opt_devfs.h"
+#endif
+
+#ifdef DEVFS
+#include <sys/devfsext.h>
+#endif
+
+#endif /* __FreeBSD__ */
+
#ifdef __NetBSD__
#include <sys/filio.h>
-#define bootverbose 0
#endif
#ifdef __FreeBSD__
@@ -79,8 +94,6 @@ extern cc_t ttydefchars;
#ifdef __bsdi__
#include <sys/device.h>
-/* XXX FIXME */
-int bootverbose = 0;
#endif
#ifdef OS_USES_POLL
@@ -125,12 +138,19 @@ static struct rbch_softc {
struct selinfo selp; /* select / poll */
#if defined(__FreeBSD__) && __FreeBSD__ == 3
+#ifdef DEVFS
+ void *devfs_token; /* device filesystem */
+#endif
#endif
#if I4BRBCHACCT
#if defined(__FreeBSD__)
struct callout_handle sc_callout;
#endif
+#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
+ struct callout sc_callout;
+#endif
+
int sc_iinb; /* isdn driver # of inbytes */
int sc_ioutb; /* isdn driver # of outbytes */
int sc_linb; /* last # of bytes rx'd */
@@ -283,6 +303,12 @@ i4brbchattach()
#if defined(__FreeBSD__)
#if __FreeBSD__ == 3
+#ifdef DEVFS
+ rbch_softc[i].devfs_token =
+ devfs_add_devswf(&i4brbch_cdevsw, i, DV_CHR,
+ UID_ROOT, GID_WHEEL, 0600,
+ "i4brbch%d", i);
+#endif
#else
make_dev(&i4brbch_cdevsw, i,
@@ -294,6 +320,9 @@ i4brbchattach()
#if defined(__FreeBSD__)
callout_handle_init(&rbch_softc[i].sc_callout);
#endif
+#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
+ callout_init(&rbch_softc[i].sc_callout);
+#endif
rbch_softc[i].sc_fn = 1;
#endif
rbch_softc[i].sc_unit = i;
@@ -313,7 +342,7 @@ i4brbchopen(dev_t dev, int flag, int fmt, struct proc *p)
{
int unit = minor(dev);
- if(unit > NI4BRBCH)
+ if(unit >= NI4BRBCH)
return(ENXIO);
if(rbch_softc[unit].sc_devstate & ST_ISOPEN)
@@ -325,7 +354,7 @@ i4brbchopen(dev_t dev, int flag, int fmt, struct proc *p)
rbch_softc[unit].sc_devstate |= ST_ISOPEN;
- DBGL4(L4_RBCHDBG, "i4brbchopen", ("unit %d, open\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, open", unit);
return(0);
}
@@ -346,7 +375,7 @@ i4brbchclose(dev_t dev, int flag, int fmt, struct proc *p)
rbch_clrq(unit);
- DBGL4(L4_RBCHDBG, "i4brbclose", ("unit %d, closed\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, closed", unit);
return(0);
}
@@ -365,38 +394,45 @@ i4brbchread(dev_t dev, struct uio *uio, int ioflag)
CRIT_VAR;
- DBGL4(L4_RBCHDBG, "i4brbchread", ("unit %d, enter read\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, enter read", unit);
+ CRIT_BEG;
if(!(sc->sc_devstate & ST_ISOPEN))
{
- DBGL4(L4_RBCHDBG, "i4brbchread", ("unit %d, read while not open\n", unit));
+ CRIT_END;
+ NDBGL4(L4_RBCHDBG, "unit %d, read while not open", unit);
return(EIO);
}
if((sc->sc_devstate & ST_NOBLOCK))
{
- if(!(sc->sc_devstate & ST_CONNECTED))
+ if(!(sc->sc_devstate & ST_CONNECTED)) {
+ CRIT_END;
return(EWOULDBLOCK);
+ }
if(sc->sc_bprot == BPROT_RHDLC)
iqp = &sc->sc_hdlcq;
else
iqp = isdn_linktab[unit]->rx_queue;
- if(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN))
+ if(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN)) {
+ CRIT_END;
return(EWOULDBLOCK);
}
+ }
else
{
while(!(sc->sc_devstate & ST_CONNECTED))
{
- DBGL4(L4_RBCHDBG, "i4brbchread", ("unit %d, wait read init\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, wait read init", unit);
if((error = tsleep((caddr_t) &rbch_softc[unit],
TTIPRI | PCATCH,
"rrrbch", 0 )) != 0)
{
- DBGL4(L4_RBCHDBG, "i4brbchread", ("unit %d, error %d tsleep\n", unit, error));
+ CRIT_END;
+ NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep", unit, error);
return(error);
}
}
@@ -408,28 +444,25 @@ i4brbchread(dev_t dev, struct uio *uio, int ioflag)
while(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN))
{
- CRIT_BEG;
sc->sc_devstate |= ST_RDWAITDATA;
- CRIT_END;
- DBGL4(L4_RBCHDBG, "i4brbchread", ("unit %d, wait read data\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, wait read data", unit);
if((error = tsleep((caddr_t) &isdn_linktab[unit]->rx_queue,
TTIPRI | PCATCH,
"rrbch", 0 )) != 0)
{
- DBGL4(L4_RBCHDBG, "i4brbchread", ("unit %d, error %d tsleep read\n", unit, error));
+ CRIT_END;
+ NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep read", unit, error);
sc->sc_devstate &= ~ST_RDWAITDATA;
return(error);
}
}
}
- CRIT_BEG;
-
IF_DEQUEUE(iqp, m);
- DBGL4(L4_RBCHDBG, "i4brbchread", ("unit %d, read %d bytes\n", unit, m->m_len));
+ NDBGL4(L4_RBCHDBG, "unit %d, read %d bytes", unit, m->m_len);
if(m && m->m_len)
{
@@ -437,7 +470,7 @@ i4brbchread(dev_t dev, struct uio *uio, int ioflag)
}
else
{
- DBGL4(L4_RBCHDBG, "i4brbchread", ("unit %d, error %d uiomove\n", unit, error));
+ NDBGL4(L4_RBCHDBG, "unit %d, error %d uiomove", unit, error);
error = EIO;
}
@@ -462,40 +495,50 @@ i4brbchwrite(dev_t dev, struct uio * uio, int ioflag)
CRIT_VAR;
- DBGL4(L4_RBCHDBG, "i4brbchwrite", ("unit %d, write\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, write", unit);
+ CRIT_BEG;
if(!(sc->sc_devstate & ST_ISOPEN))
{
- DBGL4(L4_RBCHDBG, "i4brbchwrite", ("unit %d, write while not open\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, write while not open", unit);
+ CRIT_END;
return(EIO);
}
if((sc->sc_devstate & ST_NOBLOCK))
{
- if(!(sc->sc_devstate & ST_CONNECTED))
+ if(!(sc->sc_devstate & ST_CONNECTED)) {
+ CRIT_END;
return(EWOULDBLOCK);
- if(IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN))
+ }
+ if(IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN)) {
+ CRIT_END;
return(EWOULDBLOCK);
}
+ }
else
{
while(!(sc->sc_devstate & ST_CONNECTED))
{
- DBGL4(L4_RBCHDBG, "i4brbchwrite", ("unit %d, write wait init\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, write wait init", unit);
error = tsleep((caddr_t) &rbch_softc[unit],
TTIPRI | PCATCH,
"wrrbch", 0 );
- if(error == ERESTART)
+ if(error == ERESTART) {
+ CRIT_END;
return (ERESTART);
+ }
else if(error == EINTR)
{
- DBGL4(L4_RBCHDBG, "i4brbchwrite", ("unit %d, EINTR during wait init\n", unit));
+ CRIT_END;
+ NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait init", unit);
return(EINTR);
}
else if(error)
{
- DBGL4(L4_RBCHDBG, "i4brbchwrite", ("unit %d, error %d tsleep init\n", unit, error));
+ CRIT_END;
+ NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep init", unit, error);
return(error);
}
tsleep((caddr_t) &rbch_softc[unit], TTIPRI | PCATCH, "xrbch", (hz*1));
@@ -503,11 +546,9 @@ i4brbchwrite(dev_t dev, struct uio * uio, int ioflag)
while(IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN))
{
- CRIT_BEG;
sc->sc_devstate |= ST_WRWAITEMPTY;
- CRIT_END;
- DBGL4(L4_RBCHDBG, "i4brbchwrite", ("unit %d, write queue full\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, write queue full", unit);
if ((error = tsleep((caddr_t) &isdn_linktab[unit]->tx_queue,
TTIPRI | PCATCH,
@@ -515,27 +556,28 @@ i4brbchwrite(dev_t dev, struct uio * uio, int ioflag)
sc->sc_devstate &= ~ST_WRWAITEMPTY;
if(error == ERESTART)
{
+ CRIT_END;
return(ERESTART);
}
else if(error == EINTR)
{
- DBGL4(L4_RBCHDBG, "i4brbchwrite", ("unit %d, EINTR during wait write\n", unit));
+ CRIT_END;
+ NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait write", unit);
return(error);
}
else if(error)
{
- DBGL4(L4_RBCHDBG, "i4brbchwrite", ("unit %d, error %d tsleep write\n", unit, error));
+ CRIT_END;
+ NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep write", unit, error);
return(error);
}
}
}
}
- CRIT_BEG;
-
if(!(sc->sc_devstate & ST_ISOPEN))
{
- DBGL4(L4_RBCHDBG, "i4brbchwrite", ("unit %d, not open anymore\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
CRIT_END;
return(EIO);
}
@@ -544,7 +586,7 @@ i4brbchwrite(dev_t dev, struct uio * uio, int ioflag)
{
m->m_len = min(BCH_MAX_DATALEN, uio->uio_resid);
- DBGL4(L4_RBCHDBG, "i4brbchwrite", ("unit %d, write %d bytes\n", unit, m->m_len));
+ NDBGL4(L4_RBCHDBG, "unit %d, write %d bytes", unit, m->m_len);
error = uiomove(m->m_data, m->m_len, uio);
@@ -580,23 +622,23 @@ i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct proc *p)
case FIOASYNC: /* Set async mode */
if (*(int *)data)
{
- DBGL4(L4_RBCHDBG, "i4brbchioctl", ("unit %d, setting async mode\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, setting async mode", unit);
}
else
{
- DBGL4(L4_RBCHDBG, "i4brbchioctl", ("unit %d, clearing async mode\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, clearing async mode", unit);
}
break;
case FIONBIO:
if (*(int *)data)
{
- DBGL4(L4_RBCHDBG, "i4brbchioctl", ("unit %d, setting non-blocking mode\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, setting non-blocking mode", unit);
sc->sc_devstate |= ST_NOBLOCK;
}
else
{
- DBGL4(L4_RBCHDBG, "i4brbchioctl", ("unit %d, clearing non-blocking mode\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, clearing non-blocking mode", unit);
sc->sc_devstate &= ~ST_NOBLOCK;
}
break;
@@ -604,7 +646,7 @@ i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct proc *p)
case TIOCCDTR: /* Clear DTR */
if(sc->sc_devstate & ST_CONNECTED)
{
- DBGL4(L4_RBCHDBG, "i4brbchioctl", ("unit %d, disconnecting for DTR down\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, disconnecting for DTR down", unit);
i4b_l4_drvrdisc(BDRV_RBCH, unit);
}
break;
@@ -617,7 +659,7 @@ i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct proc *p)
;
if (l)
{
- DBGL4(L4_RBCHDBG, "i4brbchioctl", ("unit %d, attempting dialout to %s\n", unit, (char *)data));
+ NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout to %s", unit, (char *)data);
i4b_l4_dialoutnumber(BDRV_RBCH, unit, l, (char *)data);
break;
}
@@ -625,7 +667,7 @@ i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct proc *p)
}
case TIOCSDTR: /* Set DTR */
- DBGL4(L4_RBCHDBG, "i4brbchioctl", ("unit %d, attempting dialout (DTR)\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout (DTR)", unit);
i4b_l4_dialout(BDRV_RBCH, unit);
break;
@@ -655,7 +697,7 @@ i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct proc *p)
}
default: /* Unknown stuff */
- DBGL4(L4_RBCHDBG, "i4brbchioctl", ("unit %d, ioctl, unknown cmd %lx\n", unit, (u_long)cmd));
+ NDBGL4(L4_RBCHDBG, "unit %d, ioctl, unknown cmd %lx", unit, (u_long)cmd);
error = EINVAL;
break;
}
@@ -737,7 +779,7 @@ i4brbchselect(dev_t dev, int rw, struct proc *p)
if(!(sc->sc_devstate & ST_ISOPEN))
{
splx(s);
- DBGL4(L4_RBCHDBG, "i4brbchselect", ("unit %d, not open anymore\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
return(1);
}
@@ -814,11 +856,7 @@ rbch_timeout(struct rbch_softc *sc)
i4b_l4_accounting(BDRV_RBCH, unit, ACCT_DURING,
sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_ioutb, sc->sc_iinb);
}
-#if defined(__FreeBSD__)
- sc->sc_callout =
-#endif
- timeout((TIMEOUT_FUNC_T)rbch_timeout,
- (void *)sc, I4BRBCHACCTINTVL*hz);
+ START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
}
#endif /* I4BRBCHACCT */
@@ -845,16 +883,12 @@ rbch_connect(int unit, void *cdp)
sc->sc_linb = 0;
sc->sc_loutb = 0;
-#if defined(__FreeBSD__)
- sc->sc_callout =
-#endif
- timeout((TIMEOUT_FUNC_T)rbch_timeout,
- (void *)sc, I4BRBCHACCTINTVL*hz);
+ START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
}
#endif
if(!(sc->sc_devstate & ST_CONNECTED))
{
- DBGL4(L4_RBCHDBG, "rbch_connect", ("unit %d, wakeup\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
sc->sc_devstate |= ST_CONNECTED;
sc->sc_cd = cdp;
wakeup((caddr_t)sc);
@@ -874,14 +908,14 @@ rbch_disconnect(int unit, void *cdp)
if(cd != sc->sc_cd)
{
- DBGL4(L4_RBCHDBG, "rbch_disconnect", ("rbch%d: channel %d not active\n",
- cd->driver_unit, cd->channelid));
+ NDBGL4(L4_RBCHDBG, "rbch%d: channel %d not active",
+ cd->driver_unit, cd->channelid);
return;
}
CRIT_BEG;
- DBGL4(L4_RBCHDBG, "rbch_disconnect", ("unit %d, disconnect\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, disconnect", unit);
sc->sc_devstate &= ~ST_CONNECTED;
@@ -891,13 +925,7 @@ rbch_disconnect(int unit, void *cdp)
i4b_l4_accounting(BDRV_RBCH, unit, ACCT_FINAL,
sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_ioutb, sc->sc_iinb);
-#if defined(__FreeBSD__)
- untimeout((TIMEOUT_FUNC_T)rbch_timeout,
- (void *)sc, sc->sc_callout);
-#else
- untimeout((TIMEOUT_FUNC_T)rbch_timeout, (void *)sc);
-#endif
-
+ STOP_TIMER(sc->sc_callout, rbch_timeout, sc);
#endif
CRIT_END;
}
@@ -937,7 +965,7 @@ rbch_rx_data_rdy(int unit)
if(IF_QFULL(&(rbch_softc[unit].sc_hdlcq)))
{
- DBGL4(L4_RBCHDBG, "rbch_rx_data_rdy", ("unit %d: hdlc rx queue full!\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
m_freem(m);
}
else
@@ -948,13 +976,13 @@ rbch_rx_data_rdy(int unit)
if(rbch_softc[unit].sc_devstate & ST_RDWAITDATA)
{
- DBGL4(L4_RBCHDBG, "rbch_rx_data_rdy", ("unit %d, wakeup\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
rbch_softc[unit].sc_devstate &= ~ST_RDWAITDATA;
wakeup((caddr_t) &isdn_linktab[unit]->rx_queue);
}
else
{
- DBGL4(L4_RBCHDBG, "rbch_rx_data_rdy", ("unit %d, NO wakeup\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
}
selwakeup(&rbch_softc[unit].selp);
}
@@ -969,13 +997,13 @@ rbch_tx_queue_empty(int unit)
{
if(rbch_softc[unit].sc_devstate & ST_WRWAITEMPTY)
{
- DBGL4(L4_RBCHDBG, "rbch_tx_queue_empty", ("unit %d, wakeup\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
rbch_softc[unit].sc_devstate &= ~ST_WRWAITEMPTY;
wakeup((caddr_t) &isdn_linktab[unit]->tx_queue);
}
else
{
- DBGL4(L4_RBCHDBG, "rbch_tx_queue_empty", ("unit %d, NO wakeup\n", unit));
+ NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
}
selwakeup(&rbch_softc[unit].selp);
}
diff --git a/sys/i4b/driver/i4b_tel.c b/sys/i4b/driver/i4b_tel.c
index a236d37..0a1c423 100644
--- a/sys/i4b/driver/i4b_tel.c
+++ b/sys/i4b/driver/i4b_tel.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
+ * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,11 +27,11 @@
* i4b_tel.c - device driver for ISDN telephony
* --------------------------------------------
*
- * $Id: i4b_tel.c,v 1.47 1999/12/13 21:25:24 hm Exp $
+ * $Id: i4b_tel.c,v 1.51 2000/10/06 08:37:43 hm Exp $
*
* $FreeBSD$
*
- * last edit-date: [Mon Dec 13 21:39:26 1999]
+ * last edit-date: [Mon Oct 2 10:06:32 2000]
*
*---------------------------------------------------------------------------*/
@@ -61,6 +61,18 @@
#include <sys/proc.h>
#include <sys/tty.h>
+#ifdef __FreeBSD__
+
+#if defined(__FreeBSD__) && __FreeBSD__ == 3
+#include "opt_devfs.h"
+#endif
+
+#ifdef DEVFS
+#include <sys/devfsext.h>
+#endif
+
+#endif /* __FreeBSD__ */
+
#ifdef __bsdi__
#include <sys/device.h>
#endif
@@ -122,11 +134,19 @@ typedef struct {
#define ST_ISOPEN 0x02 /* userland opened */
#define ST_RDWAITDATA 0x04 /* userland read waiting */
#define ST_WRWAITEMPTY 0x08 /* userland write waiting */
+#define ST_TONE 0x10 /* tone generator */
struct selinfo selp; /* select / poll */
#if defined(__FreeBSD__) && __FreeBSD__ == 3
+#ifdef DEVFS
+ void *devfs_token; /* token for DEVFS */
#endif
+#endif
+ struct i4b_tel_tones tones;
+ int toneidx;
+ int toneomega;
+ int tonefreq;
} tel_sc_t;
@@ -139,11 +159,13 @@ static void tel_tx_queue_empty(int unit);
static void tel_init_linktab(int unit);
static void tel_connect(int unit, void *cdp);
static void tel_disconnect(int unit, void *cdp);
+static void tel_tone(tel_sc_t *sc);
/* audio format conversion tables */
static unsigned char a2u_tab[];
static unsigned char u2a_tab[];
static unsigned char bitreverse[];
+static u_char sinetab[];
#ifndef __FreeBSD__
#define PDEVSTATIC /* - not static - */
@@ -262,14 +284,14 @@ struct devsw i4btelsw =
int
i4btelmatch(struct device *parent, struct cfdata *cf, void *aux)
{
- DBGL4(L4_TELDBG, "i4btelmatch", ("aux=0x%x\n", aux));
+ NDBGL4(L4_TELDBG, "aux=0x%x", aux);
return 1;
}
void
dummy_i4btelattach(struct device *parent, struct device *self, void *aux)
{
- DBGL4(L4_TELDBG, "dummy_i4btelattach", ("aux=0x%x\n", aux));
+ NDBGL4(L4_TELDBG, "aux=0x%x", aux);
}
#endif /* __bsdi__ */
@@ -303,6 +325,13 @@ i4btelattach()
#if defined(__FreeBSD__)
#if __FreeBSD__ == 3
+#ifdef DEVFS
+
+/* XXX */ tel_sc[i][j].devfs_token
+ = devfs_add_devswf(&i4btel_cdevsw, i, DV_CHR,
+ UID_ROOT, GID_WHEEL, 0600,
+ "i4btel%d", i);
+#endif
#else
switch(j)
@@ -337,7 +366,7 @@ i4btelopen(dev_t dev, int flag, int fmt, struct proc *p)
tel_sc_t *sc;
- if(unit > NI4BTEL)
+ if(unit >= NI4BTEL)
return(ENXIO);
sc = &tel_sc[unit][func];
@@ -365,12 +394,15 @@ i4btelclose(dev_t dev, int flag, int fmt, struct proc *p)
int func = FUNC(dev);
tel_sc_t *sc;
int error = 0;
+ int x;
if(unit > NI4BTEL)
return(ENXIO);
sc = &tel_sc[unit][func];
+ x = splimp();
+ sc->devstate &= ~ST_TONE;
if((func == FUNCTEL) &&
(sc->isdn_linktab != NULL && sc->isdn_linktab->tx_queue != NULL))
{
@@ -388,6 +420,8 @@ i4btelclose(dev_t dev, int flag, int fmt, struct proc *p)
}
sc->devstate &= ~ST_ISOPEN;
+ splx(x);
+ wakeup((caddr_t) &sc->tones);
return(error);
}
@@ -471,6 +505,37 @@ i4btelioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
mvr->step = STEP;
break;
}
+ case I4B_TEL_TONES:
+ {
+ struct i4b_tel_tones *tt;
+
+ tt = (struct i4b_tel_tones *)data;
+ s = splimp();
+ while ((sc->devstate & ST_TONE) &&
+ sc->tones.duration[sc->toneidx] != 0) {
+ if((error = tsleep((caddr_t) &sc->tones,
+ TTIPRI | PCATCH, "rtone", 0 )) != 0) {
+ splx(s);
+ return(error);
+ }
+ }
+ if(!(sc->devstate & ST_ISOPEN)) {
+ splx(s);
+ return (EIO);
+ }
+ if(!(sc->devstate & ST_CONNECTED)) {
+ splx(s);
+ return (EIO);
+ }
+
+ sc->tones = *tt;
+ sc->toneidx = 0;
+ sc->tonefreq = tt->frequency[0];
+ sc->devstate |= ST_TONE;
+ splx(s);
+ tel_tone(sc);
+ break;
+ }
default:
error = ENOTTY;
@@ -509,34 +574,37 @@ i4btelread(dev_t dev, struct uio *uio, int ioflag)
if(func == FUNCTEL)
{
+ s = splimp();
while(IF_QEMPTY(sc->isdn_linktab->rx_queue) &&
(sc->devstate & ST_ISOPEN) &&
(sc->devstate & ST_CONNECTED))
{
sc->devstate |= ST_RDWAITDATA;
- DBGL4(L4_TELDBG, "i4btelread", ("i4btel%d, queue empty!\n", unit));
+ NDBGL4(L4_TELDBG, "i4btel%d, queue empty!", unit);
if((error = tsleep((caddr_t) &sc->isdn_linktab->rx_queue,
TTIPRI | PCATCH,
"rtel", 0 )) != 0)
{
sc->devstate &= ~ST_RDWAITDATA;
+ splx(s);
return(error);
}
}
if(!(sc->devstate & ST_ISOPEN))
{
+ splx(s);
return(EIO);
}
if(!(sc->devstate & ST_CONNECTED))
{
+ splx(s);
return(EIO);
}
- s = splimp();
IF_DEQUEUE(sc->isdn_linktab->rx_queue, m);
@@ -555,11 +623,11 @@ i4btelread(dev_t dev, struct uio *uio, int ioflag)
}
error = uiomove(m->m_data, m->m_len, uio);
- DBGL4(L4_TELDBG, "i4btelread", ("i4btel%d, mbuf (%d bytes), uiomove %d!\n", unit, m->m_len, error));
+ NDBGL4(L4_TELDBG, "i4btel%d, mbuf (%d bytes), uiomove %d!", unit, m->m_len, error);
}
else
{
- DBGL4(L4_TELDBG, "i4btelread", ("i4btel%d, empty mbuf from queue!\n", unit));
+ NDBGL4(L4_TELDBG, "i4btel%d, empty mbuf from queue!", unit);
error = EIO;
}
@@ -570,6 +638,7 @@ i4btelread(dev_t dev, struct uio *uio, int ioflag)
}
else if(func == FUNCDIAL)
{
+ s = splimp();
while((sc->result == 0) && (sc->devstate & ST_ISOPEN))
{
sc->devstate |= ST_RDWAITDATA;
@@ -579,17 +648,17 @@ i4btelread(dev_t dev, struct uio *uio, int ioflag)
"rtel1", 0 )) != 0)
{
sc->devstate &= ~ST_RDWAITDATA;
+ splx(s);
return(error);
}
}
if(!(sc->devstate & ST_ISOPEN))
{
+ splx(s);
return(EIO);
}
- s = splimp();
-
if(sc->result != 0)
{
error = uiomove(&sc->result, 1, uio);
@@ -625,9 +694,14 @@ i4btelwrite(dev_t dev, struct uio * uio, int ioflag)
if(func == FUNCTEL)
{
- if(!(sc->devstate & ST_CONNECTED))
+ s = splimp();
+
+ if(!(sc->devstate & ST_CONNECTED)) {
+ splx(s);
return(EIO);
+ }
+ sc->devstate &= ~ST_TONE;
while((IF_QFULL(sc->isdn_linktab->tx_queue)) &&
(sc->devstate & ST_ISOPEN))
{
@@ -637,22 +711,23 @@ i4btelwrite(dev_t dev, struct uio * uio, int ioflag)
TTIPRI | PCATCH, "wtel", 0)) != 0)
{
sc->devstate &= ~ST_WRWAITEMPTY;
+ splx(s);
return(error);
}
}
if(!(sc->devstate & ST_ISOPEN))
{
+ splx(s);
return(EIO);
}
if(!(sc->devstate & ST_CONNECTED))
{
+ splx(s);
return(EIO);
}
- s = splimp();
-
if((m = i4b_Bgetmbuf(BCH_MAX_DATALEN)) != NULL)
{
register int i;
@@ -687,7 +762,7 @@ i4btelwrite(dev_t dev, struct uio * uio, int ioflag)
}
else if(func == FUNCDIAL)
{
-#define CMDBUFSIZ 80
+#define CMDBUFSIZ 80
char cmdbuf[CMDBUFSIZ];
int len = min(CMDBUFSIZ-1, uio->uio_resid);
@@ -710,6 +785,57 @@ i4btelwrite(dev_t dev, struct uio * uio, int ioflag)
return(error);
}
+/*---------------------------------------------------------------------------*
+ *
+ *---------------------------------------------------------------------------*/
+#define NTONESAMP 32
+static void
+tel_tone(tel_sc_t *sc)
+{
+ struct mbuf *m;
+ u_char *p;
+ int i;
+
+ if((m = i4b_Bgetmbuf(NTONESAMP)) == NULL) {
+ printf("no mbuf in tel_tone\n");
+ return;
+ }
+ p = m->m_data;
+ m->m_len = 0;
+ for (i = 0; i < NTONESAMP && (sc->devstate & ST_TONE); i++) {
+
+ if (sc->tones.duration[sc->toneidx] > 0) {
+ if (--sc->tones.duration[sc->toneidx] == 0) {
+ sc->toneidx++;
+ if (sc->toneidx == I4B_TEL_MAXTONES) {
+ sc->devstate &= ~ST_TONE;
+ sc->toneomega = 0;
+ sc->tonefreq = 0;
+ } else if (sc->tones.frequency[sc->toneidx] == 0 &&
+ sc->tones.duration[sc->toneidx] == 0) {
+ sc->devstate &= ~ST_TONE;
+ sc->toneomega = 0;
+ sc->tonefreq = 0;
+ } else {
+ sc->tonefreq = sc->tones.frequency[sc->toneidx];
+ }
+ if (sc->tones.duration[sc->toneidx] == 0) {
+ wakeup((caddr_t) &sc->tones);
+ }
+ }
+ }
+
+ sc->toneomega += sc->tonefreq;
+ if (sc->toneomega >= 8000)
+ sc->toneomega -= 8000;
+ *p++ = bitreverse[sinetab[sc->toneomega]];
+ m->m_len++;
+ }
+ IF_ENQUEUE(sc->isdn_linktab->tx_queue, m);
+ (*sc->isdn_linktab->bch_tx_start)(sc->isdn_linktab->unit, sc->isdn_linktab->channel);
+}
+
+
#ifdef OS_USES_POLL
/*---------------------------------------------------------------------------*
* device driver poll
@@ -728,7 +854,7 @@ i4btelpoll(dev_t dev, int events, struct proc *p)
if(!(sc->devstate & ST_ISOPEN))
{
- DBGL4(L4_TELDBG, "i4btelpoll", ("i4btel%d, !ST_ISOPEN\n", unit));
+ NDBGL4(L4_TELDBG, "i4btel%d, !ST_ISOPEN", unit);
splx(s);
return(0);
}
@@ -745,7 +871,7 @@ i4btelpoll(dev_t dev, int events, struct proc *p)
(sc->isdn_linktab != NULL) &&
(!IF_QFULL(sc->isdn_linktab->tx_queue)))
{
- DBGL4(L4_TELDBG, "i4btelpoll", ("i4btel%d, POLLOUT\n", unit));
+ NDBGL4(L4_TELDBG, "i4btel%d, POLLOUT", unit);
revents |= (events & (POLLOUT|POLLWRNORM));
}
@@ -756,13 +882,13 @@ i4btelpoll(dev_t dev, int events, struct proc *p)
(sc->isdn_linktab != NULL) &&
(!IF_QEMPTY(sc->isdn_linktab->rx_queue)))
{
- DBGL4(L4_TELDBG, "i4btelpoll", ("i4btel%d, POLLIN\n", unit));
+ NDBGL4(L4_TELDBG, "i4btel%d, POLLIN", unit);
revents |= (events & (POLLIN|POLLRDNORM));
}
if(revents == 0)
{
- DBGL4(L4_TELDBG, "i4btelpoll", ("i4btel%d, selrecord\n", unit));
+ NDBGL4(L4_TELDBG, "i4btel%d, selrecord", unit);
selrecord(p, &sc->selp);
}
}
@@ -770,20 +896,20 @@ i4btelpoll(dev_t dev, int events, struct proc *p)
{
if(events & (POLLOUT|POLLWRNORM))
{
- DBGL4(L4_TELDBG, "i4btelpoll", ("i4bteld%d, POLLOUT\n", unit));
+ NDBGL4(L4_TELDBG, "i4bteld%d, POLLOUT", unit);
revents |= (events & (POLLOUT|POLLWRNORM));
}
if(events & (POLLIN|POLLRDNORM))
{
- DBGL4(L4_TELDBG, "i4btelpoll", ("i4bteld%d, POLLIN, result = %d\n", unit, sc->result));
+ NDBGL4(L4_TELDBG, "i4bteld%d, POLLIN, result = %d", unit, sc->result);
if(sc->result != 0)
revents |= (events & (POLLIN|POLLRDNORM));
}
if(revents == 0)
{
- DBGL4(L4_TELDBG, "i4btelpoll", ("i4bteld%d, selrecord\n", unit));
+ NDBGL4(L4_TELDBG, "i4bteld%d, selrecord", unit);
selrecord(p, &sc->selp);
}
}
@@ -809,7 +935,7 @@ i4btelsel(dev_t dev, int rw, struct proc *p)
if (!(sc->devstate & ST_ISOPEN))
{
- DBGL4(L4_TELDBG, "i4btelsel", ("i4btel%d, !ST_ISOPEN\n", unit));
+ NDBGL4(L4_TELDBG, "i4btel%d, !ST_ISOPEN", unit);
splx(s);
return(0);
}
@@ -827,7 +953,7 @@ i4btelsel(dev_t dev, int rw, struct proc *p)
{
if (!IF_QEMPTY(sc->isdn_linktab->rx_queue))
{
- DBGL4(L4_TELDBG, "i4btelsel", ("i4btel%d, FREAD\n", unit));
+ NDBGL4(L4_TELDBG, "i4btel%d, FREAD", unit);
splx(s);
return 1;
}
@@ -836,7 +962,7 @@ i4btelsel(dev_t dev, int rw, struct proc *p)
{
if (!IF_QFULL(sc->isdn_linktab->tx_queue))
{
- DBGL4(L4_TELDBG, "i4btelsel", ("i4btel%d, FWRITE\n", unit));
+ NDBGL4(L4_TELDBG, "i4btel%d, FWRITE", unit);
splx(s);
return 1;
}
@@ -846,14 +972,14 @@ i4btelsel(dev_t dev, int rw, struct proc *p)
{
if (rw == FWRITE)
{
- DBGL4(L4_TELDBG, "i4btelsel", ("i4bteld%d, FWRITE\n", unit));
+ NDBGL4(L4_TELDBG, "i4bteld%d, FWRITE", unit);
splx(s);
return 1;
}
if (rw == FREAD)
{
- DBGL4(L4_TELDBG, "i4btelsel", ("i4bteld%d, FREAD, result = %d\n", unit, sc->result));
+ NDBGL4(L4_TELDBG, "i4bteld%d, FREAD, result = %d", unit, sc->result);
if (sc->result != 0)
{
splx(s);
@@ -862,7 +988,7 @@ i4btelsel(dev_t dev, int rw, struct proc *p)
}
}
- DBGL4(L4_TELDBG, "i4btelsel", ("i4bteld%d, selrecord\n", unit));
+ NDBGL4(L4_TELDBG, "i4bteld%d, selrecord", unit);
selrecord(p, &sc->selp);
splx(s);
return 0;
@@ -935,7 +1061,7 @@ tel_disconnect(int unit, void *cdp)
sc = &tel_sc[unit][FUNCDIAL];
- if(sc->devstate == ST_ISOPEN)
+ if(sc->devstate & ST_ISOPEN)
{
sc->result = RSP_HUP;
@@ -945,6 +1071,11 @@ tel_disconnect(int unit, void *cdp)
wakeup((caddr_t) &sc->result);
}
selwakeup(&sc->selp);
+
+ if (sc->devstate & ST_TONE) {
+ sc->devstate &= ~ST_TONE;
+ wakeup((caddr_t) &sc->tones);
+ }
}
}
@@ -956,7 +1087,7 @@ tel_dialresponse(int unit, int status, cause_t cause)
{
tel_sc_t *sc = &tel_sc[unit][FUNCDIAL];
- DBGL4(L4_TELDBG, "tel_dialresponse", ("i4btel%d, status=%d, cause=0x%4x\n", unit, status, cause));
+ NDBGL4(L4_TELDBG, "i4btel%d, status=%d, cause=0x%4x", unit, status, cause);
if((sc->devstate == ST_ISOPEN) && status)
{
@@ -1012,7 +1143,11 @@ tel_tx_queue_empty(int unit)
sc->devstate &= ~ST_WRWAITEMPTY;
wakeup((caddr_t) &sc->isdn_linktab->tx_queue);
}
- selwakeup(&sc->selp);
+ if(sc->devstate & ST_TONE) {
+ tel_tone(sc);
+ } else {
+ selwakeup(&sc->selp);
+ }
}
/*---------------------------------------------------------------------------*
@@ -1184,6 +1319,581 @@ static unsigned char bitreverse[256] = {
/* f8 */ 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
};
+static u_char sinetab[8000] = { 213, 213, 213, 213, 213, 213, 213, 212,
+212, 212, 212, 212, 212, 215, 215, 215, 215, 215, 215, 214, 214,
+214, 214, 214, 214, 209, 209, 209, 209, 209, 209, 209, 208, 208,
+208, 208, 208, 208, 211, 211, 211, 211, 211, 211, 210, 210, 210,
+210, 210, 210, 221, 221, 221, 221, 221, 221, 220, 220, 220, 220,
+220, 220, 220, 223, 223, 223, 223, 223, 223, 222, 222, 222, 222,
+222, 222, 217, 217, 217, 217, 217, 217, 216, 216, 216, 216, 216,
+216, 216, 219, 219, 219, 219, 219, 219, 218, 218, 218, 218, 218,
+218, 197, 197, 197, 197, 197, 197, 196, 196, 196, 196, 196, 196,
+196, 199, 199, 199, 199, 199, 199, 198, 198, 198, 198, 198, 198,
+193, 193, 193, 193, 193, 193, 192, 192, 192, 192, 192, 192, 192,
+195, 195, 195, 195, 195, 195, 194, 194, 194, 194, 194, 194, 205,
+205, 205, 205, 205, 205, 204, 204, 204, 204, 204, 204, 204, 207,
+207, 207, 207, 207, 207, 206, 206, 206, 206, 206, 206, 201, 201,
+201, 201, 201, 201, 200, 200, 200, 200, 200, 200, 200, 203, 203,
+203, 203, 203, 203, 202, 202, 202, 202, 202, 202, 245, 245, 245,
+245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 244, 244, 244,
+244, 244, 244, 244, 244, 244, 244, 244, 244, 247, 247, 247, 247,
+247, 247, 247, 247, 247, 247, 247, 247, 247, 246, 246, 246, 246,
+246, 246, 246, 246, 246, 246, 246, 246, 246, 241, 241, 241, 241,
+241, 241, 241, 241, 241, 241, 241, 241, 240, 240, 240, 240, 240,
+240, 240, 240, 240, 240, 240, 240, 240, 243, 243, 243, 243, 243,
+243, 243, 243, 243, 243, 243, 243, 243, 242, 242, 242, 242, 242,
+242, 242, 242, 242, 242, 242, 242, 242, 253, 253, 253, 253, 253,
+253, 253, 253, 253, 253, 253, 253, 253, 252, 252, 252, 252, 252,
+252, 252, 252, 252, 252, 252, 252, 255, 255, 255, 255, 255, 255,
+255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 254, 254, 254,
+254, 254, 254, 254, 254, 254, 254, 249, 249, 249, 249, 249, 249,
+249, 249, 249, 249, 249, 249, 249, 248, 248, 248, 248, 248, 248,
+248, 248, 248, 248, 248, 248, 248, 251, 251, 251, 251, 251, 251,
+251, 251, 251, 251, 251, 251, 251, 250, 250, 250, 250, 250, 250,
+250, 250, 250, 250, 250, 250, 250, 229, 229, 229, 229, 229, 229,
+229, 229, 229, 229, 229, 229, 229, 229, 229, 229, 229, 229, 229,
+229, 229, 229, 229, 229, 229, 229, 228, 228, 228, 228, 228, 228,
+228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228,
+228, 228, 228, 228, 228, 228, 228, 228, 231, 231, 231, 231, 231,
+231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231,
+231, 231, 231, 231, 231, 231, 231, 231, 231, 230, 230, 230, 230,
+230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230,
+230, 230, 230, 230, 230, 230, 230, 230, 230, 225, 225, 225, 225,
+225, 225, 225, 225, 225, 225, 225, 225, 225, 225, 225, 225, 225,
+225, 225, 225, 225, 225, 225, 225, 225, 225, 225, 225, 224, 224,
+224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224,
+224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 227,
+227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227,
+227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227,
+227, 226, 226, 226, 226, 226, 226, 226, 226, 226, 226, 226, 226,
+226, 226, 226, 226, 226, 226, 226, 226, 226, 226, 226, 226, 226,
+226, 226, 226, 237, 237, 237, 237, 237, 237, 237, 237, 237, 237,
+237, 237, 237, 237, 237, 237, 237, 237, 237, 237, 237, 237, 237,
+237, 237, 237, 237, 237, 236, 236, 236, 236, 236, 236, 236, 236,
+236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236,
+236, 236, 236, 236, 236, 236, 236, 236, 239, 239, 239, 239, 239,
+239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 239,
+239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 238, 238,
+238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238,
+238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238,
+238, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233,
+233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233,
+233, 233, 233, 233, 233, 232, 232, 232, 232, 232, 232, 232, 232,
+232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
+232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 235, 235, 235,
+235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235,
+235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235,
+235, 235, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234,
+234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234,
+234, 234, 234, 234, 234, 234, 234, 149, 149, 149, 149, 149, 149,
+149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
+149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
+149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
+149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
+149, 149, 149, 149, 149, 149, 149, 148, 148, 148, 148, 148, 148,
+148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
+148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
+148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
+148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
+148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 151, 151, 151,
+151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151,
+151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151,
+151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151,
+151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151,
+151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151,
+151, 151, 151, 151, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+156, 156, 156, 156, 156, 156, 156, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+157, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146,
+146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147,
+147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 147, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
+144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+145, 145, 145, 145, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
+150, 150, 150, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151,
+151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151,
+151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151,
+151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151,
+151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151,
+151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 148, 148, 148,
+148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
+148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
+148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
+148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
+148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
+149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
+149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
+149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
+149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
+149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
+234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234,
+234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234,
+234, 234, 234, 234, 234, 235, 235, 235, 235, 235, 235, 235, 235,
+235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235,
+235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 232, 232, 232,
+232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
+232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
+232, 232, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233,
+233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233,
+233, 233, 233, 233, 233, 233, 238, 238, 238, 238, 238, 238, 238,
+238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238,
+238, 238, 238, 238, 238, 238, 238, 238, 238, 239, 239, 239, 239,
+239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 239,
+239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, 236,
+236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236,
+236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236,
+236, 236, 237, 237, 237, 237, 237, 237, 237, 237, 237, 237, 237,
+237, 237, 237, 237, 237, 237, 237, 237, 237, 237, 237, 237, 237,
+237, 237, 237, 237, 226, 226, 226, 226, 226, 226, 226, 226, 226,
+226, 226, 226, 226, 226, 226, 226, 226, 226, 226, 226, 226, 226,
+226, 226, 226, 226, 226, 226, 227, 227, 227, 227, 227, 227, 227,
+227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227,
+227, 227, 227, 227, 227, 227, 227, 227, 224, 224, 224, 224, 224,
+224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224,
+224, 224, 224, 224, 224, 224, 224, 224, 224, 225, 225, 225, 225,
+225, 225, 225, 225, 225, 225, 225, 225, 225, 225, 225, 225, 225,
+225, 225, 225, 225, 225, 225, 225, 225, 225, 225, 225, 230, 230,
+230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230,
+230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 231, 231,
+231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231,
+231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 228,
+228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228,
+228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228,
+229, 229, 229, 229, 229, 229, 229, 229, 229, 229, 229, 229, 229,
+229, 229, 229, 229, 229, 229, 229, 229, 229, 229, 229, 229, 229,
+250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
+251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251,
+248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248,
+249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249,
+254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
+255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253,
+253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 242,
+242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 243,
+243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 240,
+240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 241,
+241, 241, 241, 241, 241, 241, 241, 241, 241, 241, 241, 246, 246,
+246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 247,
+247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 244, 244,
+244, 244, 244, 244, 244, 244, 244, 244, 244, 244, 245, 245, 245,
+245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 202, 202, 202,
+202, 202, 202, 203, 203, 203, 203, 203, 203, 200, 200, 200, 200,
+200, 200, 200, 201, 201, 201, 201, 201, 201, 206, 206, 206, 206,
+206, 206, 207, 207, 207, 207, 207, 207, 204, 204, 204, 204, 204,
+204, 204, 205, 205, 205, 205, 205, 205, 194, 194, 194, 194, 194,
+194, 195, 195, 195, 195, 195, 195, 192, 192, 192, 192, 192, 192,
+192, 193, 193, 193, 193, 193, 193, 198, 198, 198, 198, 198, 198,
+199, 199, 199, 199, 199, 199, 196, 196, 196, 196, 196, 196, 196,
+197, 197, 197, 197, 197, 197, 218, 218, 218, 218, 218, 218, 219,
+219, 219, 219, 219, 219, 216, 216, 216, 216, 216, 216, 216, 217,
+217, 217, 217, 217, 217, 222, 222, 222, 222, 222, 222, 223, 223,
+223, 223, 223, 223, 220, 220, 220, 220, 220, 220, 220, 221, 221,
+221, 221, 221, 221, 210, 210, 210, 210, 210, 210, 211, 211, 211,
+211, 211, 211, 208, 208, 208, 208, 208, 208, 209, 209, 209, 209,
+209, 209, 209, 214, 214, 214, 214, 214, 214, 215, 215, 215, 215,
+215, 215, 212, 212, 212, 212, 212, 212, 213, 213, 213, 213, 213,
+213, 213, 90, 90, 90, 85, 85, 85, 85, 85, 85, 84, 84, 84, 84, 84,
+84, 87, 87, 87, 87, 87, 87, 86, 86, 86, 86, 86, 86, 81, 81, 81,
+81, 81, 81, 81, 80, 80, 80, 80, 80, 80, 83, 83, 83, 83, 83, 83,
+82, 82, 82, 82, 82, 82, 93, 93, 93, 93, 93, 93, 93, 92, 92, 92,
+92, 92, 92, 95, 95, 95, 95, 95, 95, 94, 94, 94, 94, 94, 94, 89,
+89, 89, 89, 89, 89, 88, 88, 88, 88, 88, 88, 88, 91, 91, 91, 91,
+91, 91, 90, 90, 90, 90, 90, 90, 69, 69, 69, 69, 69, 69, 68, 68,
+68, 68, 68, 68, 68, 71, 71, 71, 71, 71, 71, 70, 70, 70, 70, 70,
+70, 65, 65, 65, 65, 65, 65, 64, 64, 64, 64, 64, 64, 64, 67, 67,
+67, 67, 67, 67, 66, 66, 66, 66, 66, 66, 77, 77, 77, 77, 77, 77,
+76, 76, 76, 76, 76, 76, 76, 79, 79, 79, 79, 79, 79, 78, 78, 78,
+78, 78, 78, 73, 73, 73, 73, 73, 73, 73, 72, 72, 72, 72, 72, 72,
+75, 75, 75, 75, 75, 75, 74, 74, 74, 74, 74, 74, 117, 117, 117, 117,
+117, 117, 117, 117, 117, 117, 117, 117, 117, 116, 116, 116, 116,
+116, 116, 116, 116, 116, 116, 116, 116, 116, 119, 119, 119, 119,
+119, 119, 119, 119, 119, 119, 119, 119, 118, 118, 118, 118, 118,
+118, 118, 118, 118, 118, 118, 118, 118, 113, 113, 113, 113, 113,
+113, 113, 113, 113, 113, 113, 113, 113, 112, 112, 112, 112, 112,
+112, 112, 112, 112, 112, 112, 112, 115, 115, 115, 115, 115, 115,
+115, 115, 115, 115, 115, 115, 115, 114, 114, 114, 114, 114, 114,
+114, 114, 114, 114, 114, 114, 114, 125, 125, 125, 125, 125, 125,
+125, 125, 125, 125, 125, 125, 125, 124, 124, 124, 124, 124, 124,
+124, 124, 124, 124, 124, 124, 124, 127, 127, 127, 127, 127, 127,
+127, 127, 127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126,
+126, 126, 126, 126, 126, 126, 121, 121, 121, 121, 121, 121, 121,
+121, 121, 121, 121, 121, 121, 120, 120, 120, 120, 120, 120, 120,
+120, 120, 120, 120, 120, 120, 123, 123, 123, 123, 123, 123, 123,
+123, 123, 123, 123, 123, 123, 122, 122, 122, 122, 122, 122, 122,
+122, 122, 122, 122, 122, 122, 101, 101, 101, 101, 101, 101, 101,
+101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
+101, 101, 101, 101, 101, 101, 101, 100, 100, 100, 100, 100, 100,
+100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
+100, 100, 100, 100, 100, 100, 100, 103, 103, 103, 103, 103, 103,
+103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
+103, 103, 103, 103, 103, 103, 103, 103, 102, 102, 102, 102, 102,
+102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
+102, 102, 102, 102, 102, 102, 102, 102, 102, 97, 97, 97, 97, 97,
+97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
+97, 97, 97, 97, 97, 97, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+96, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 98, 98, 98,
+98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
+98, 98, 98, 98, 98, 98, 98, 98, 98, 109, 109, 109, 109, 109, 109,
+109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109,
+109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 108, 108, 108,
+108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
+108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 111,
+111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111,
+111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111,
+111, 111, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
+110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
+110, 110, 110, 110, 110, 110, 105, 105, 105, 105, 105, 105, 105,
+105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105,
+105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 104, 104, 104,
+104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
+104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
+104, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
+107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
+107, 107, 107, 107, 107, 107, 106, 106, 106, 106, 106, 106, 106,
+106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 21,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+20, 20, 20, 20, 20, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+19, 19, 19, 19, 19, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17, 17, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 20, 20, 20, 20, 20, 20,
+20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
+106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+106, 106, 106, 106, 106, 106, 107, 107, 107, 107, 107, 107, 107,
+107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
+107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 104, 104,
+104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
+104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
+104, 104, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105,
+105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105,
+105, 105, 105, 105, 105, 105, 110, 110, 110, 110, 110, 110, 110,
+110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
+110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 111, 111, 111,
+111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111,
+111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111,
+108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
+108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
+108, 108, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109,
+109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109,
+109, 109, 109, 109, 109, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
+98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
+98, 98, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 96, 96,
+96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+96, 96, 96, 96, 96, 96, 96, 96, 96, 97, 97, 97, 97, 97, 97, 97,
+97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
+97, 97, 97, 97, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
+102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
+102, 102, 102, 102, 103, 103, 103, 103, 103, 103, 103, 103, 103,
+103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
+103, 103, 103, 103, 103, 100, 100, 100, 100, 100, 100, 100, 100,
+100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
+100, 100, 100, 100, 100, 101, 101, 101, 101, 101, 101, 101, 101,
+101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
+101, 101, 101, 101, 101, 101, 122, 122, 122, 122, 122, 122, 122,
+122, 122, 122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 123,
+123, 123, 123, 123, 123, 123, 120, 120, 120, 120, 120, 120, 120,
+120, 120, 120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121,
+121, 121, 121, 121, 121, 121, 126, 126, 126, 126, 126, 126, 126,
+126, 126, 126, 126, 126, 126, 127, 127, 127, 127, 127, 127, 127,
+127, 127, 127, 127, 127, 124, 124, 124, 124, 124, 124, 124, 124,
+124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 125,
+125, 125, 125, 125, 125, 114, 114, 114, 114, 114, 114, 114, 114,
+114, 114, 114, 114, 114, 115, 115, 115, 115, 115, 115, 115, 115,
+115, 115, 115, 115, 115, 112, 112, 112, 112, 112, 112, 112, 112,
+112, 112, 112, 112, 113, 113, 113, 113, 113, 113, 113, 113, 113,
+113, 113, 113, 113, 118, 118, 118, 118, 118, 118, 118, 118, 118,
+118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 119,
+119, 119, 119, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116,
+116, 116, 116, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117,
+117, 117, 117, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, 72,
+72, 72, 72, 72, 72, 73, 73, 73, 73, 73, 73, 73, 78, 78, 78, 78,
+78, 78, 79, 79, 79, 79, 79, 79, 76, 76, 76, 76, 76, 76, 76, 77,
+77, 77, 77, 77, 77, 66, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67,
+67, 64, 64, 64, 64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 70, 70,
+70, 70, 70, 70, 71, 71, 71, 71, 71, 71, 68, 68, 68, 68, 68, 68,
+68, 69, 69, 69, 69, 69, 69, 90, 90, 90, 90, 90, 90, 91, 91, 91,
+91, 91, 91, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, 89,
+94, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 92, 92, 92, 92,
+92, 92, 93, 93, 93, 93, 93, 93, 93, 82, 82, 82, 82, 82, 82, 83,
+83, 83, 83, 83, 83, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81,
+81, 81, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87, 87, 84, 84,
+84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 90, 90, 90 };
+
/*===========================================================================*/
#endif /* NI4BTEL > 0 */
diff --git a/sys/i4b/driver/i4b_trace.c b/sys/i4b/driver/i4b_trace.c
index c3c1688..3847508 100644
--- a/sys/i4b/driver/i4b_trace.c
+++ b/sys/i4b/driver/i4b_trace.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
+ * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,9 +27,9 @@
* i4btrc - device driver for trace data read device
* ---------------------------------------------------
*
- * $Id: i4b_trace.c,v 1.24 1999/12/13 21:25:24 hm Exp $
+ * $Id: i4b_trace.c,v 1.27 2000/06/02 16:14:35 hm Exp $
*
- * last edit-date: [Mon Dec 13 21:39:35 1999]
+ * last edit-date: [Fri Jun 2 17:48:19 2000]
*
* $FreeBSD$
*
@@ -41,17 +41,6 @@
#if NI4BTRC > 0
-#ifdef __FreeBSD__
-#include "isic.h" /* 'isic' is no pseudo-device on non FreeBSD -
- * so we just can't count it at compile time,
- * we're doing an attach-time check instead. */
-
-#if NI4BTRC < NISIC
-#error "number of trace devices != number of passive ISDN controllers !"
-#error "change number of i4btrc to be equal to number of isic devices !"
-#endif
-#endif /* __FreeBSD__ */
-
#include <sys/param.h>
#include <sys/systm.h>
@@ -72,6 +61,9 @@
#ifdef __FreeBSD__
+#ifdef DEVFS
+#include <sys/devfsext.h>
+#endif
#include <machine/i4b_trace.h>
#include <machine/i4b_ioctl.h>
@@ -98,6 +90,9 @@ static int device_state[NI4BTRC];
#define ST_WAITDATA 0x02
#if defined(__FreeBSD__) && __FreeBSD__ == 3
+#ifdef DEVFS
+static void *devfs_token[NI4BTRC];
+#endif
#endif
static int analyzemode = 0;
@@ -238,6 +233,12 @@ i4btrcattach()
#if defined(__FreeBSD__)
#if __FreeBSD__ < 4
+#ifdef DEVFS
+ devfs_token[i]
+ = devfs_add_devswf(&i4btrc_cdevsw, i, DV_CHR,
+ UID_ROOT, GID_WHEEL, 0600,
+ "i4btrc%d", i);
+#endif
#else
make_dev(&i4btrc_cdevsw, i,
@@ -361,7 +362,7 @@ i4btrcopen(dev_t dev, int flag, int fmt, struct proc *p)
int x;
int unit = minor(dev);
- if(unit > NI4BTRC)
+ if(unit >= NI4BTRC)
return(ENXIO);
if(device_state[unit] & ST_ISOPEN)
@@ -386,11 +387,13 @@ PDEVSTATIC int
i4btrcclose(dev_t dev, int flag, int fmt, struct proc *p)
{
int unit = minor(dev);
- int i, x, cno = -1;
+ int i, x;
+ int cno = -1;
- for(i = 0; i < nctrl; i++)
+ for(i=0; i < nctrl; i++)
{
- if(ctrl_desc[i].N_SET_TRACE)
+ if((ctrl_desc[i].ctrl_type == CTRL_PASSIVE) &&
+ (ctrl_desc[i].unit == unit))
{
cno = i;
break;
@@ -404,8 +407,8 @@ i4btrcclose(dev_t dev, int flag, int fmt, struct proc *p)
if(cno >= 0)
{
- ctrl_desc[cno].N_SET_TRACE(rxunit, TRACE_OFF);
- ctrl_desc[cno].N_SET_TRACE(txunit, TRACE_OFF);
+ (*ctrl_desc[cno].N_MGMT_COMMAND)(rxunit, CMR_SETTRACE, TRACE_OFF);
+ (*ctrl_desc[cno].N_MGMT_COMMAND)(txunit, CMR_SETTRACE, TRACE_OFF);
}
rxunit = -1;
txunit = -1;
@@ -413,7 +416,7 @@ i4btrcclose(dev_t dev, int flag, int fmt, struct proc *p)
if(cno >= 0)
{
- ctrl_desc[cno].N_SET_TRACE(unit, TRACE_OFF);
+ (*ctrl_desc[cno].N_MGMT_COMMAND)(ctrl_desc[cno].unit, CMR_SETTRACE, TRACE_OFF);
}
x = SPLI4B();
@@ -494,33 +497,27 @@ i4btrcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
int error = 0;
int unit = minor(dev);
i4b_trace_setupa_t *tsa;
- int i, cno = -1;
+ int i;
+ int cno = -1;
- /* find the first passive controller to get at the set/get function
- pointers. Would be better if we had the controller class virtual
- function table separate from the port registry... */
+ /* find the first passive controller matching our unit no */
for(i=0; i < nctrl; i++)
{
- if(ctrl_desc[i].N_SET_TRACE)
+ if((ctrl_desc[i].ctrl_type == CTRL_PASSIVE) &&
+ (ctrl_desc[i].unit == unit))
{
- cno = i; /* one suitable controller, might not */
- break; /* be related to the trace unit at all, but */
- } /* has the right function pointers */
+ cno = i;
+ break;
+ }
}
switch(cmd)
{
- case I4B_TRC_GET:
- if(cno < 0)
- return ENOTTY;
- *(int *)data = ctrl_desc[cno].N_GET_TRACE(unit);
- break;
-
case I4B_TRC_SET:
if(cno < 0)
return ENOTTY;
- ctrl_desc[cno].N_SET_TRACE(unit, *(int *)data);
+ (*ctrl_desc[cno].N_MGMT_COMMAND)(ctrl_desc[cno].unit, CMR_SETTRACE, (void *)*(unsigned int *)data);
break;
case I4B_TRC_SETA:
@@ -549,8 +546,8 @@ i4btrcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
outunit = unit;
analyzemode = 1;
- ctrl_desc[cno].N_SET_TRACE(rxunit, tsa->rxflags & (TRACE_I | TRACE_D_RX | TRACE_B_RX));
- ctrl_desc[cno].N_SET_TRACE(txunit, tsa->txflags & (TRACE_I | TRACE_D_RX | TRACE_B_RX));
+ (*ctrl_desc[cno].N_MGMT_COMMAND)(rxunit, CMR_SETTRACE, (int *)(tsa->rxflags & (TRACE_I | TRACE_D_RX | TRACE_B_RX)));
+ (*ctrl_desc[cno].N_MGMT_COMMAND)(txunit, CMR_SETTRACE, (int *)(tsa->txflags & (TRACE_I | TRACE_D_RX | TRACE_B_RX)));
}
break;
OpenPOWER on IntegriCloud