changes from ppp-2.3.9 [synchronous]
This commit is contained in:
parent
0bdb76e5cf
commit
ec608f7058
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_ppp.h,v 1.16 1999/05/12 18:50:51 thorpej Exp $ */
|
||||
/* $NetBSD: if_ppp.h,v 1.17 1999/08/25 02:04:05 christos Exp $ */
|
||||
/* Id: if_ppp.h,v 1.16 1997/04/30 05:46:04 paulus Exp */
|
||||
|
||||
/*
|
||||
|
@ -39,10 +39,12 @@
|
|||
#define SC_LOG_OUTPKT 0x00040000 /* log contents of pkts sent */
|
||||
#define SC_LOG_RAWIN 0x00080000 /* log all chars received */
|
||||
#define SC_LOG_FLUSH 0x00100000 /* log all chars flushed */
|
||||
#define SC_SYNC 0x00200000 /* synchronous HDLC */
|
||||
#define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */
|
||||
#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */
|
||||
#define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */
|
||||
#define SC_RCV_ODDP 0x08000000 /* have rcvd char with odd parity */
|
||||
|
||||
#define SC_MASK 0x0fff00ff /* bits that user can change */
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ppp_tty.c,v 1.17 1999/05/24 20:12:10 tron Exp $ */
|
||||
/* $NetBSD: ppp_tty.c,v 1.18 1999/08/25 02:04:06 christos Exp $ */
|
||||
/* Id: ppp_tty.c,v 1.3 1996/07/01 01:04:11 paulus Exp */
|
||||
|
||||
/*
|
||||
|
@ -123,7 +123,9 @@ int ppptioctl __P((struct tty *tp, u_long cmd, caddr_t data, int flag,
|
|||
int pppinput __P((int c, struct tty *tp));
|
||||
int pppstart __P((struct tty *tp));
|
||||
|
||||
static void ppprcvframe __P((struct ppp_softc *sc, struct mbuf *m));
|
||||
static u_int16_t pppfcs __P((u_int16_t fcs, u_char *cp, int len));
|
||||
static void pppsyncstart __P((struct ppp_softc *sc));
|
||||
static void pppasyncstart __P((struct ppp_softc *));
|
||||
static void pppasyncctlp __P((struct ppp_softc *));
|
||||
static void pppasyncrelinq __P((struct ppp_softc *));
|
||||
|
@ -131,6 +133,8 @@ static void ppp_timeout __P((void *));
|
|||
static void pppgetm __P((struct ppp_softc *sc));
|
||||
static void pppdumpb __P((u_char *b, int l));
|
||||
static void ppplogchar __P((struct ppp_softc *, int));
|
||||
static void pppdumpframe __P((struct ppp_softc *sc, struct mbuf* m,
|
||||
int xmit));
|
||||
|
||||
/*
|
||||
* Some useful mbuf macros not in mbuf.h.
|
||||
|
@ -410,6 +414,10 @@ ppptioctl(tp, cmd, data, flag, p)
|
|||
|
||||
error = 0;
|
||||
switch (cmd) {
|
||||
case TIOCRCVFRAME:
|
||||
ppprcvframe(sc,*((struct mbuf **)data));
|
||||
break;
|
||||
|
||||
case PPPIOCSASYNCMAP:
|
||||
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
||||
break;
|
||||
|
@ -454,6 +462,115 @@ ppptioctl(tp, cmd, data, flag, p)
|
|||
return error;
|
||||
}
|
||||
|
||||
/* receive a complete ppp frame from device in synchronous
|
||||
* hdlc mode. caller gives up ownership of mbuf
|
||||
*/
|
||||
static void
|
||||
ppprcvframe(sc, m)
|
||||
struct ppp_softc *sc;
|
||||
struct mbuf *m;
|
||||
{
|
||||
int len, s;
|
||||
struct mbuf *n;
|
||||
u_char hdr[4];
|
||||
int hlen,count;
|
||||
|
||||
for (n=m,len=0;n != NULL;n = n->m_next)
|
||||
len += n->m_len;
|
||||
if (len==0) {
|
||||
m_freem(m);
|
||||
return;
|
||||
}
|
||||
|
||||
/* extract PPP header from mbuf chain (1 to 4 bytes) */
|
||||
for (n=m,hlen=0;n!=NULL && hlen<sizeof(hdr);n=n->m_next) {
|
||||
count = (sizeof(hdr)-hlen) < n->m_len ?
|
||||
sizeof(hdr)-hlen : n->m_len;
|
||||
bcopy(mtod(n,u_char*),&hdr[hlen],count);
|
||||
hlen+=count;
|
||||
}
|
||||
|
||||
s = spltty();
|
||||
|
||||
/* if AFCF compressed then prepend AFCF */
|
||||
if (hdr[0] != PPP_ALLSTATIONS) {
|
||||
if (sc->sc_flags & SC_REJ_COMP_AC) {
|
||||
if (sc->sc_flags & SC_DEBUG)
|
||||
printf(
|
||||
"%s: garbage received: 0x%x (need 0xFF)\n",
|
||||
sc->sc_if.if_xname, hdr[0]);
|
||||
goto bail;
|
||||
}
|
||||
M_PREPEND(m,2,M_DONTWAIT);
|
||||
if (m==NULL) {
|
||||
splx(s);
|
||||
return;
|
||||
}
|
||||
hdr[3] = hdr[1];
|
||||
hdr[2] = hdr[0];
|
||||
hdr[0] = PPP_ALLSTATIONS;
|
||||
hdr[1] = PPP_UI;
|
||||
len += 2;
|
||||
}
|
||||
|
||||
/* if protocol field compressed, add MSB of protocol field = 0 */
|
||||
if (hdr[2] & 1) {
|
||||
/* a compressed protocol */
|
||||
M_PREPEND(m,1,M_DONTWAIT);
|
||||
if (m==NULL) {
|
||||
splx(s);
|
||||
return;
|
||||
}
|
||||
hdr[3] = hdr[2];
|
||||
hdr[2] = 0;
|
||||
len++;
|
||||
}
|
||||
|
||||
/* valid LSB of protocol field has bit0 set */
|
||||
if (!(hdr[3] & 1)) {
|
||||
if (sc->sc_flags & SC_DEBUG)
|
||||
printf("%s: bad protocol %x\n", sc->sc_if.if_xname,
|
||||
(hdr[2] << 8) + hdr[3]);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* packet beyond configured mru? */
|
||||
if (len > sc->sc_mru + PPP_HDRLEN) {
|
||||
if (sc->sc_flags & SC_DEBUG)
|
||||
printf("%s: packet too big\n", sc->sc_if.if_xname);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* add expanded 4 byte header to mbuf chain */
|
||||
for (n=m,hlen=0;n!=NULL && hlen<sizeof(hdr);n=n->m_next) {
|
||||
count = (sizeof(hdr)-hlen) < n->m_len ?
|
||||
sizeof(hdr)-hlen : n->m_len;
|
||||
bcopy(&hdr[hlen],mtod(n,u_char*),count);
|
||||
hlen+=count;
|
||||
}
|
||||
|
||||
/* if_ppp.c requires the PPP header and IP header */
|
||||
/* to be contiguous */
|
||||
count = len < MHLEN ? len : MHLEN;
|
||||
if (m->m_len < count) {
|
||||
m = m_pullup(m,count);
|
||||
if (m==NULL)
|
||||
goto bail;
|
||||
}
|
||||
|
||||
sc->sc_stats.ppp_ibytes += len;
|
||||
|
||||
if (sc->sc_flags & SC_LOG_RAWIN)
|
||||
pppdumpframe(sc,m,0);
|
||||
|
||||
ppppktin(sc, m, 0);
|
||||
splx(s);
|
||||
return;
|
||||
bail:
|
||||
m_freem(m);
|
||||
splx(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* FCS lookup table as calculated by genfcstab.
|
||||
*/
|
||||
|
@ -506,6 +623,41 @@ pppfcs(fcs, cp, len)
|
|||
return (fcs);
|
||||
}
|
||||
|
||||
/* This gets called at splsoftnet from pppasyncstart at various times
|
||||
* when there is data ready to be sent.
|
||||
*/
|
||||
static void
|
||||
pppsyncstart(sc)
|
||||
struct ppp_softc *sc;
|
||||
{
|
||||
struct tty *tp = (struct tty *) sc->sc_devp;
|
||||
struct mbuf *m, *n;
|
||||
int len;
|
||||
|
||||
for(m = sc->sc_outm;;) {
|
||||
if (m == NULL) {
|
||||
m = ppp_dequeue(sc); /* get new packet */
|
||||
if (m == NULL)
|
||||
break; /* no more packets */
|
||||
if (sc->sc_flags & SC_DEBUG)
|
||||
pppdumpframe(sc,m,1);
|
||||
}
|
||||
microtime(&sc->sc_if.if_lastchange);
|
||||
for(n=m,len=0;n!=NULL;n=n->m_next)
|
||||
len += n->m_len;
|
||||
|
||||
/* call device driver IOCTL to transmit a frame */
|
||||
if ((*cdevsw[major(tp->t_dev)].d_ioctl)
|
||||
(tp->t_dev, TIOCXMTFRAME, (caddr_t)&m, 0, 0)) {
|
||||
/* busy or error, set as current packet */
|
||||
sc->sc_outm = m;
|
||||
break;
|
||||
}
|
||||
sc->sc_outm = m = NULL;
|
||||
sc->sc_stats.ppp_obytes += len;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This gets called at splsoftnet from if_ppp.c at various times
|
||||
* when there is data ready to be sent.
|
||||
|
@ -522,6 +674,11 @@ pppasyncstart(sc)
|
|||
struct mbuf *m2;
|
||||
int s;
|
||||
|
||||
if (sc->sc_flags & SC_SYNC){
|
||||
pppsyncstart(sc);
|
||||
return;
|
||||
}
|
||||
|
||||
idle = 0;
|
||||
while (CCOUNT(&tp->t_outq) < PPP_HIWAT) {
|
||||
/*
|
||||
|
@ -1078,4 +1235,48 @@ pppdumpb(b, l)
|
|||
printf("%s\n", buf);
|
||||
}
|
||||
|
||||
static void
|
||||
pppdumpframe(sc, m, xmit)
|
||||
struct ppp_softc *sc;
|
||||
struct mbuf* m;
|
||||
int xmit;
|
||||
{
|
||||
int i,lcount,copycount,count;
|
||||
char lbuf[16];
|
||||
char *data;
|
||||
|
||||
if (m == NULL)
|
||||
return;
|
||||
|
||||
for(count=m->m_len,data=mtod(m,char*);m != NULL;) {
|
||||
/* build a line of output */
|
||||
for(lcount=0;lcount < sizeof(lbuf);lcount += copycount) {
|
||||
if (!count) {
|
||||
m = m->m_next;
|
||||
if (m == NULL)
|
||||
break;
|
||||
count = m->m_len;
|
||||
data = mtod(m,char*);
|
||||
}
|
||||
copycount = (count > sizeof(lbuf)-lcount) ?
|
||||
sizeof(lbuf)-lcount : count;
|
||||
bcopy(data,&lbuf[lcount],copycount);
|
||||
data += copycount;
|
||||
count -= copycount;
|
||||
}
|
||||
|
||||
/* output line (hex 1st, then ascii) */
|
||||
printf("%s %s:", sc->sc_if.if_xname,
|
||||
xmit ? "output" : "input ");
|
||||
for(i=0;i<lcount;i++)
|
||||
printf("%02x ",(u_char)lbuf[i]);
|
||||
for(;i<sizeof(lbuf);i++)
|
||||
printf(" ");
|
||||
for(i=0;i<lcount;i++)
|
||||
printf("%c",(lbuf[i] >= 040 &&
|
||||
lbuf[i] <= 0176) ? lbuf[i] : '.');
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* NPPP > 0 */
|
||||
|
|
Loading…
Reference in New Issue