1 --- sys.stable/net/ppp_tty.c Fri Apr 16 16:14:38 1999
2 +++ /usr/src/synclink/bsd2/ppp_tty.c Thu Apr 15 14:40:51 1999
4 static int pppinput __P((int c, struct tty *tp));
5 static int pppstart __P((struct tty *tp));
7 +static void ppprcvframe __P((struct ppp_softc *sc, struct mbuf *m));
9 static u_short pppfcs __P((u_short fcs, u_char *cp, int len));
10 +static void pppsyncstart __P((register struct ppp_softc *sc));
11 static void pppasyncstart __P((struct ppp_softc *));
12 static void pppasyncctlp __P((struct ppp_softc *));
13 static void pppasyncrelinq __P((struct ppp_softc *));
15 static void ppp_timeout __P((void *));
16 static void pppgetm __P((struct ppp_softc *sc));
17 static void ppplogchar __P((struct ppp_softc *, int));
18 +static void pppdumpframe __P((struct ppp_softc *sc,struct mbuf* m,int xmit));
20 /* XXX called from if_ppp.c - layering violation */
21 void pppasyncattach __P((void *));
27 + ppprcvframe(sc,*((struct mbuf **)data));
31 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
37 +/* receive a complete ppp frame from device in synchronous
38 + * hdlc mode. caller gives up ownership of mbuf
40 +static void ppprcvframe(struct ppp_softc *sc, struct mbuf *m)
47 + for (n=m,len=0;n != NULL;n = n->m_next)
54 + /* extract PPP header from mbuf chain (1 to 4 bytes) */
55 + for (n=m,hlen=0;n!=NULL && hlen<sizeof(hdr);n=n->m_next) {
56 + count = (sizeof(hdr)-hlen) < n->m_len ?
57 + sizeof(hdr)-hlen : n->m_len;
58 + bcopy(mtod(n,u_char*),&hdr[hlen],count);
64 + /* if AFCF compressed then prepend AFCF */
65 + if (hdr[0] != PPP_ALLSTATIONS) {
66 + if (sc->sc_flags & SC_REJ_COMP_AC) {
67 + if (sc->sc_flags & SC_DEBUG)
68 + printf("ppp%d: garbage received: 0x%x (need 0xFF)\n",
69 + sc->sc_if.if_unit, hdr[0]);
72 + M_PREPEND(m,2,M_DONTWAIT);
79 + hdr[0] = PPP_ALLSTATIONS;
84 + /* if protocol field compressed, add MSB of protocol field = 0 */
86 + /* a compressed protocol */
87 + M_PREPEND(m,1,M_DONTWAIT);
97 + /* valid LSB of protocol field has bit0 set */
98 + if (!(hdr[3] & 1)) {
99 + if (sc->sc_flags & SC_DEBUG)
100 + printf("ppp%d: bad protocol %x\n", sc->sc_if.if_unit,
101 + (hdr[2] << 8) + hdr[3]);
105 + /* packet beyond configured mru? */
106 + if (len > sc->sc_mru + PPP_HDRLEN) {
107 + if (sc->sc_flags & SC_DEBUG)
108 + printf("ppp%d: packet too big\n", sc->sc_if.if_unit);
112 + /* add expanded 4 byte header to mbuf chain */
113 + for (n=m,hlen=0;n!=NULL && hlen<sizeof(hdr);n=n->m_next) {
114 + count = (sizeof(hdr)-hlen) < n->m_len ?
115 + sizeof(hdr)-hlen : n->m_len;
116 + bcopy(&hdr[hlen],mtod(n,u_char*),count);
120 + /* if_ppp.c requires the PPP header and IP header */
121 + /* to be contiguous */
122 + count = len < MHLEN ? len : MHLEN;
123 + if (m->m_len < count) {
124 + m = m_pullup(m,count);
129 + sc->sc_stats.ppp_ibytes += len;
131 + if (sc->sc_flags & SC_LOG_RAWIN)
132 + pppdumpframe(sc,m,0);
134 + ppppktin(sc, m, 0);
143 * FCS lookup table as calculated by genfcstab.
149 +/* This gets called at splsoftnet from pppasyncstart at various times
150 + * when there is data ready to be sent.
152 +static void pppsyncstart(register struct ppp_softc *sc)
154 + struct tty *tp = (struct tty *) sc->sc_devp;
155 + struct mbuf *m, *n;
158 + for(m = sc->sc_outm;;) {
160 + m = ppp_dequeue(sc); /* get new packet */
162 + break; /* no more packets */
163 + if (sc->sc_flags & SC_DEBUG)
164 + pppdumpframe(sc,m,1);
166 + microtime(&sc->sc_if.if_lastchange);
167 + for(n=m,len=0;n!=NULL;n=n->m_next)
170 + /* call device driver IOCTL to transmit a frame */
171 + if ((*cdevsw[major(tp->t_dev)]->d_ioctl)
172 + (tp->t_dev,TIOCXMTFRAME,(caddr_t)&m,0,0)) {
173 + /* busy or error, set as current packet */
177 + sc->sc_outm = m = NULL;
178 + sc->sc_stats.ppp_obytes += len;
183 * This gets called at splsoftnet from if_ppp.c at various times
184 * when there is data ready to be sent.
189 + if (sc->sc_flags & SC_SYNC){
195 /* XXX assumes atomic access to *tp although we're not at spltty(). */
196 while (CCOUNT(&tp->t_outq) < PPP_HIWAT) {
197 @@ -1125,6 +1276,44 @@
198 sc->sc_rawin_count, sc->sc_rawin, " ");
199 sc->sc_rawin_count = 0;
203 +static void pppdumpframe(struct ppp_softc *sc,struct mbuf* m,int xmit)
205 + int i,lcount,copycount,count;
212 + for(count=m->m_len,data=mtod(m,char*);m != NULL;) {
213 + /* build a line of output */
214 + for(lcount=0;lcount < sizeof(lbuf);lcount += copycount) {
220 + data = mtod(m,char*);
222 + copycount = (count > sizeof(lbuf)-lcount) ?
223 + sizeof(lbuf)-lcount : count;
224 + bcopy(data,&lbuf[lcount],copycount);
226 + count -= copycount;
229 + /* output line (hex 1st, then ascii) */
230 + printf("ppp%d %s:",sc->sc_if.if_unit,xmit ? "output":"input ");
231 + for(i=0;i<lcount;i++)
232 + printf("%02x ",(u_char)lbuf[i]);
233 + for(;i<sizeof(lbuf);i++)
235 + for(i=0;i<lcount;i++)
236 + printf("%c",(lbuf[i]>=040 && lbuf[i]<=0176)?lbuf[i]:'.');
241 #endif /* NPPP > 0 */