Deleted Added
full compact
hdlc.c (6060) hdlc.c (6735)
1/*
2 * PPP High Level Link Control (HDLC) Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1/*
2 * PPP High Level Link Control (HDLC) Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
19 *
20 * $Id:$
20 * $Id:$
21 *
21 *
22 * TODO:
23 */
24#include "fsm.h"
25#include "hdlc.h"
26#include "lcpproto.h"
27#include "lcp.h"
28#include "lqr.h"
22 * TODO:
23 */
24#include "fsm.h"
25#include "hdlc.h"
26#include "lcpproto.h"
27#include "lcp.h"
28#include "lqr.h"
29#include "vars.h"
29
30struct hdlcstat {
31 int badfcs;
32 int badaddr;
33 int badcommand;
34 int unknownproto;
35} HdlcStat;
36

--- 87 unchanged lines hidden (view full) ---

124 u_short fcs;
125
126 if ((proto & 0xfff1) == 0x21) { /* Network Layer protocol */
127 if (CcpFsm.state == ST_OPENED) {
128 Pred1Output(pri, proto, bp);
129 return;
130 }
131 }
30
31struct hdlcstat {
32 int badfcs;
33 int badaddr;
34 int badcommand;
35 int unknownproto;
36} HdlcStat;
37

--- 87 unchanged lines hidden (view full) ---

125 u_short fcs;
126
127 if ((proto & 0xfff1) == 0x21) { /* Network Layer protocol */
128 if (CcpFsm.state == ST_OPENED) {
129 Pred1Output(pri, proto, bp);
130 return;
131 }
132 }
132 mfcs = mballoc(2, MB_HDLCOUT);
133 if (DEV_IS_SYNC)
134 mfcs = NULLBUFF;
135 else
136 mfcs = mballoc(2, MB_HDLCOUT);
133 mhp = mballoc(4, MB_HDLCOUT);
134 mhp->cnt = 0;
135 cp = MBUF_CTOP(mhp);
136 if (proto == PROTO_LCP || LcpInfo.his_acfcomp == 0) {
137 *cp++ = HDLC_ADDR;
138 *cp++ = HDLC_UI;
139 mhp->cnt += 2;
140 }

--- 26 unchanged lines hidden (view full) ---

167 lqr->PeerInDiscards = HisLqrSave.SaveInDiscards;
168 lqr->PeerInErrors = HisLqrSave.SaveInErrors;
169 lqr->PeerInOctets = HisLqrSave.SaveInOctets;
170 lqr->PeerOutLQRs = ++ifOutLQRs;
171 LqrDump("LqrOutput", lqr);
172 LqrChangeOrder(lqr, (struct lqrdata *)(MBUF_CTOP(bp)));
173 }
174
137 mhp = mballoc(4, MB_HDLCOUT);
138 mhp->cnt = 0;
139 cp = MBUF_CTOP(mhp);
140 if (proto == PROTO_LCP || LcpInfo.his_acfcomp == 0) {
141 *cp++ = HDLC_ADDR;
142 *cp++ = HDLC_UI;
143 mhp->cnt += 2;
144 }

--- 26 unchanged lines hidden (view full) ---

171 lqr->PeerInDiscards = HisLqrSave.SaveInDiscards;
172 lqr->PeerInErrors = HisLqrSave.SaveInErrors;
173 lqr->PeerInOctets = HisLqrSave.SaveInOctets;
174 lqr->PeerOutLQRs = ++ifOutLQRs;
175 LqrDump("LqrOutput", lqr);
176 LqrChangeOrder(lqr, (struct lqrdata *)(MBUF_CTOP(bp)));
177 }
178
175 fcs = HdlcFcs(INITFCS, MBUF_CTOP(mhp), mhp->cnt);
176 fcs = HdlcFcs(fcs, MBUF_CTOP(bp), bp->cnt);
177 fcs = ~fcs;
178 cp = MBUF_CTOP(mfcs);
179 *cp++ = fcs & 0377; /* Low byte first!! */
180 *cp++ = fcs >> 8;
179 if (!DEV_IS_SYNC) {
180 fcs = HdlcFcs(INITFCS, MBUF_CTOP(mhp), mhp->cnt);
181 fcs = HdlcFcs(fcs, MBUF_CTOP(bp), bp->cnt);
182 fcs = ~fcs;
183 cp = MBUF_CTOP(mfcs);
184 *cp++ = fcs & 0377; /* Low byte first!! */
185 *cp++ = fcs >> 8;
186 }
181
182 LogDumpBp(LOG_HDLC, "HdlcOutput", mhp);
183 for (statp = ProtocolStat; statp->number; statp++)
184 if (statp->number == proto)
185 break;
186 statp->out_count++;
187
188 LogDumpBp(LOG_HDLC, "HdlcOutput", mhp);
189 for (statp = ProtocolStat; statp->number; statp++)
190 if (statp->number == proto)
191 break;
192 statp->out_count++;
187 AsyncOutput(pri, mhp, proto);
193 if (DEV_IS_SYNC)
194 ModemOutput(pri, mhp);
195 else
196 AsyncOutput(pri, mhp, proto);
188}
189
190DecodePacket(proto, bp)
191u_short proto;
192struct mbuf *bp;
193{
194#ifdef DEBUG
195 logprintf("proto = %04x\n", proto);

--- 10 unchanged lines hidden (view full) ---

206 LqrInput(bp);
207 break;
208 case PROTO_CHAP:
209 ChapInput(bp);
210 break;
211 case PROTO_VJUNCOMP:
212 case PROTO_VJCOMP:
213 bp = VjCompInput(bp, proto);
197}
198
199DecodePacket(proto, bp)
200u_short proto;
201struct mbuf *bp;
202{
203#ifdef DEBUG
204 logprintf("proto = %04x\n", proto);

--- 10 unchanged lines hidden (view full) ---

215 LqrInput(bp);
216 break;
217 case PROTO_CHAP:
218 ChapInput(bp);
219 break;
220 case PROTO_VJUNCOMP:
221 case PROTO_VJCOMP:
222 bp = VjCompInput(bp, proto);
223 if (bp == NULLBUFF) {
224 break;
225 }
214 /* fall down */
215 case PROTO_IP:
216 IpInput(bp);
217 break;
218 case PROTO_IPCP:
219 IpcpInput(bp);
220 break;
221 case PROTO_CCP:

--- 68 unchanged lines hidden (view full) ---

290void
291HdlcInput(struct mbuf *bp)
292{
293 u_short fcs, proto;
294 u_char *cp, addr, ctrl;
295 struct protostat *statp;
296
297 LogDumpBp(LOG_HDLC, "HdlcInput:", bp);
226 /* fall down */
227 case PROTO_IP:
228 IpInput(bp);
229 break;
230 case PROTO_IPCP:
231 IpcpInput(bp);
232 break;
233 case PROTO_CCP:

--- 68 unchanged lines hidden (view full) ---

302void
303HdlcInput(struct mbuf *bp)
304{
305 u_short fcs, proto;
306 u_char *cp, addr, ctrl;
307 struct protostat *statp;
308
309 LogDumpBp(LOG_HDLC, "HdlcInput:", bp);
298 fcs = HdlcFcs(INITFCS, MBUF_CTOP(bp), bp->cnt);
310 if (DEV_IS_SYNC)
311 fcs = GOODFCS;
312 else
313 fcs = HdlcFcs(INITFCS, MBUF_CTOP(bp), bp->cnt);
299 HisLqrSave.SaveInOctets += bp->cnt + 1;
300
301#ifdef DEBUG
302 logprintf("fcs = %04x (%s)\n", fcs, (fcs == GOODFCS)? "good" : "bad");
303#endif
304 if (fcs != GOODFCS) {
305 HisLqrSave.SaveInErrors++;
306#ifdef DEBUG
307 logprintf("Bad FCS\n");
308#endif
309 HdlcStat.badfcs++;
310 pfree(bp);
311 return;
312 }
314 HisLqrSave.SaveInOctets += bp->cnt + 1;
315
316#ifdef DEBUG
317 logprintf("fcs = %04x (%s)\n", fcs, (fcs == GOODFCS)? "good" : "bad");
318#endif
319 if (fcs != GOODFCS) {
320 HisLqrSave.SaveInErrors++;
321#ifdef DEBUG
322 logprintf("Bad FCS\n");
323#endif
324 HdlcStat.badfcs++;
325 pfree(bp);
326 return;
327 }
313 bp->cnt -= 2; /* discard FCS part */
328 if (!DEV_IS_SYNC)
329 bp->cnt -= 2; /* discard FCS part */
314 cp = MBUF_CTOP(bp);
315
316 ifInPackets++;
317 ifInOctets += bp->cnt;
318
319 if (!LcpInfo.want_acfcomp) {
320 /*
321 * We expect that packet is not compressed.

--- 57 unchanged lines hidden ---
330 cp = MBUF_CTOP(bp);
331
332 ifInPackets++;
333 ifInOctets += bp->cnt;
334
335 if (!LcpInfo.want_acfcomp) {
336 /*
337 * We expect that packet is not compressed.

--- 57 unchanged lines hidden ---