hdlc.c revision 31514
16059Samurai/* 26059Samurai * PPP High Level Link Control (HDLC) Module 36059Samurai * 46059Samurai * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 56059Samurai * 66059Samurai * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 76059Samurai * 86059Samurai * Redistribution and use in source and binary forms are permitted 96059Samurai * provided that the above copyright notice and this paragraph are 106059Samurai * duplicated in all such forms and that any documentation, 116059Samurai * advertising materials, and other materials related to such 126059Samurai * distribution and use acknowledge that the software was developed 136059Samurai * by the Internet Initiative Japan, Inc. The name of the 146059Samurai * IIJ may not be used to endorse or promote products derived 156059Samurai * from this software without specific prior written permission. 166059Samurai * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 176059Samurai * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 186059Samurai * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 198857Srgrimes * 2031514Sbrian * $Id: hdlc.c,v 1.22 1997/11/22 03:37:32 brian Exp $ 218857Srgrimes * 226059Samurai * TODO: 236059Samurai */ 2430715Sbrian#include <sys/param.h> 2530715Sbrian#include <netinet/in.h> 2630715Sbrian 2730715Sbrian#include <stdio.h> 2830715Sbrian#include <string.h> 2930715Sbrian#include <termios.h> 3030715Sbrian 3131343Sbrian#include "command.h" 3230715Sbrian#include "mbuf.h" 3330715Sbrian#include "log.h" 3430715Sbrian#include "defs.h" 3530715Sbrian#include "timer.h" 366059Samurai#include "fsm.h" 376059Samurai#include "hdlc.h" 386059Samurai#include "lcpproto.h" 3930733Sbrian#include "ipcp.h" 4030733Sbrian#include "ip.h" 4130733Sbrian#include "vjcomp.h" 4230733Sbrian#include "pap.h" 4330733Sbrian#include "chap.h" 446059Samurai#include "lcp.h" 4531343Sbrian#include "async.h" 466059Samurai#include "lqr.h" 4726142Sbrian#include "loadalias.h" 486735Samurai#include "vars.h" 4913389Sphk#include "modem.h" 5013389Sphk#include "ccp.h" 516059Samurai 526059Samuraistruct hdlcstat { 5328679Sbrian int badfcs; 5428679Sbrian int badaddr; 5528679Sbrian int badcommand; 5628679Sbrian int unknownproto; 5728679Sbrian} HdlcStat; 586059Samurai 5930715Sbrianstatic int ifOutPackets; 6030715Sbrianstatic int ifOutOctets; 6130715Sbrianstatic int ifOutLQRs; 6230715Sbrianstatic int ifInPackets; 6330715Sbrianstatic int ifInOctets; 646059Samurai 656059Samuraistruct protostat { 666059Samurai u_short number; 6731343Sbrian const char *name; 686059Samurai u_long in_count; 696059Samurai u_long out_count; 7028679Sbrian} ProtocolStat[] = { 7128679Sbrian 7231343Sbrian { PROTO_IP, "IP" }, 7331343Sbrian { PROTO_VJUNCOMP, "VJ_UNCOMP" }, 7431343Sbrian { PROTO_VJCOMP, "VJ_COMP" }, 7531343Sbrian { PROTO_COMPD, "COMPD" }, 7631343Sbrian { PROTO_LCP, "LCP" }, 7731343Sbrian { PROTO_IPCP, "IPCP" }, 7831343Sbrian { PROTO_CCP, "CCP" }, 7931343Sbrian { PROTO_PAP, "PAP" }, 8031343Sbrian { PROTO_LQR, "LQR" }, 8131343Sbrian { PROTO_CHAP, "CHAP" }, 8231343Sbrian { 0, "Others" } 836059Samurai}; 846059Samurai 8513760Sphkstatic u_short const fcstab[256] = { 8628679Sbrian /* 00 */ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 8728679Sbrian /* 08 */ 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 8828679Sbrian /* 10 */ 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 8928679Sbrian /* 18 */ 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 9028679Sbrian /* 20 */ 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 9128679Sbrian /* 28 */ 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 9228679Sbrian /* 30 */ 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 9328679Sbrian /* 38 */ 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 9428679Sbrian /* 40 */ 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 9528679Sbrian /* 48 */ 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 9628679Sbrian /* 50 */ 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 9728679Sbrian /* 58 */ 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 9828679Sbrian /* 60 */ 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 9928679Sbrian /* 68 */ 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 10028679Sbrian /* 70 */ 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 10128679Sbrian /* 78 */ 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 10228679Sbrian /* 80 */ 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 10328679Sbrian /* 88 */ 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 10428679Sbrian /* 90 */ 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 10528679Sbrian /* 98 */ 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 10628679Sbrian /* a0 */ 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 10728679Sbrian /* a8 */ 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 10828679Sbrian /* b0 */ 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 10928679Sbrian /* b8 */ 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 11028679Sbrian /* c0 */ 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 11128679Sbrian /* c8 */ 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 11228679Sbrian /* d0 */ 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 11328679Sbrian /* d8 */ 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 11428679Sbrian /* e0 */ 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 11528679Sbrian /* e8 */ 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 11628679Sbrian /* f0 */ 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 11728679Sbrian /* f8 */ 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 1186059Samurai}; 1196059Samurai 12028679Sbrianu_char EscMap[33]; 12128679Sbrian 1226059Samuraivoid 1236059SamuraiHdlcInit() 1246059Samurai{ 1256059Samurai ifInOctets = ifOutOctets = 0; 1266059Samurai ifInPackets = ifOutPackets = 0; 1276059Samurai ifOutLQRs = 0; 1286059Samurai} 1296059Samurai 1306059Samurai/* 1316059Samurai * HDLC FCS computation. Read RFC 1171 Appendix B and CCITT X.25 section 1326059Samurai * 2.27 for further details. 1336059Samurai */ 13428679Sbrianinline u_short 13528679SbrianHdlcFcs(u_short fcs, u_char * cp, int len) 1366059Samurai{ 1376059Samurai while (len--) 1386059Samurai fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff]; 13928679Sbrian return (fcs); 1406059Samurai} 1416059Samurai 14231514Sbrianinline u_short 14331514SbrianHdlcFcsBuf(u_short fcs, struct mbuf *m) 14431514Sbrian{ 14531514Sbrian int len; 14631514Sbrian u_char *pos, *end; 14731514Sbrian 14831514Sbrian len = plength(m); 14931514Sbrian pos = MBUF_CTOP(m); 15031514Sbrian end = pos + m->cnt; 15131514Sbrian while (len--) { 15231514Sbrian fcs = (fcs >> 8) ^ fcstab[(fcs ^ *pos++) & 0xff]; 15331514Sbrian if (pos == end && len) { 15431514Sbrian m = m->next; 15531514Sbrian pos = MBUF_CTOP(m); 15631514Sbrian end = pos + m->cnt; 15731514Sbrian } 15831514Sbrian } 15931514Sbrian return (fcs); 16031514Sbrian} 16131514Sbrian 1626059Samuraivoid 16328679SbrianHdlcOutput(int pri, u_short proto, struct mbuf * bp) 1646059Samurai{ 1656059Samurai struct mbuf *mhp, *mfcs; 1666059Samurai struct protostat *statp; 1676059Samurai struct lqrdata *lqr; 1686059Samurai u_char *cp; 1696059Samurai u_short fcs; 1706059Samurai 17131514Sbrian if ((proto & 0xfff1) == 0x21) /* Network Layer protocol */ 17231514Sbrian if (CcpFsm.state == ST_OPENED) 17331514Sbrian if (CcpOutput(pri, proto, bp)) 17429294Sbrian return; 17531514Sbrian 1766735Samurai if (DEV_IS_SYNC) 1776735Samurai mfcs = NULLBUFF; 1786735Samurai else 1796735Samurai mfcs = mballoc(2, MB_HDLCOUT); 18031514Sbrian 1816059Samurai mhp = mballoc(4, MB_HDLCOUT); 1826059Samurai mhp->cnt = 0; 1836059Samurai cp = MBUF_CTOP(mhp); 1846059Samurai if (proto == PROTO_LCP || LcpInfo.his_acfcomp == 0) { 1856059Samurai *cp++ = HDLC_ADDR; 1866059Samurai *cp++ = HDLC_UI; 1876059Samurai mhp->cnt += 2; 1886059Samurai } 18928679Sbrian 1906059Samurai /* 19128679Sbrian * If possible, compress protocol field. 1926059Samurai */ 1936059Samurai if (LcpInfo.his_protocomp && (proto & 0xff00) == 0) { 1946059Samurai *cp++ = proto; 1956059Samurai mhp->cnt++; 1966059Samurai } else { 1976059Samurai *cp++ = proto >> 8; 1986059Samurai *cp = proto & 0377; 1996059Samurai mhp->cnt += 2; 2006059Samurai } 2016059Samurai mhp->next = bp; 20231514Sbrian while (bp->next != NULL) 20331514Sbrian bp = bp->next; 2046059Samurai bp->next = mfcs; 20531514Sbrian bp = mhp->next; 2066059Samurai 2076059Samurai lqr = &MyLqrData; 2086059Samurai lqr->PeerOutPackets = ifOutPackets++; 2096059Samurai ifOutOctets += plength(mhp) + 1; 2106059Samurai lqr->PeerOutOctets = ifOutOctets; 2116059Samurai 2126059Samurai if (proto == PROTO_LQR) { 2136059Samurai lqr->MagicNumber = LcpInfo.want_magic; 2146059Samurai lqr->LastOutLQRs = HisLqrData.PeerOutLQRs; 2156059Samurai lqr->LastOutPackets = HisLqrData.PeerOutPackets; 2166059Samurai lqr->LastOutOctets = HisLqrData.PeerOutOctets; 2176059Samurai lqr->PeerInLQRs = HisLqrSave.SaveInLQRs; 2186059Samurai lqr->PeerInPackets = HisLqrSave.SaveInPackets; 2196059Samurai lqr->PeerInDiscards = HisLqrSave.SaveInDiscards; 2206059Samurai lqr->PeerInErrors = HisLqrSave.SaveInErrors; 2216059Samurai lqr->PeerInOctets = HisLqrSave.SaveInOctets; 2226059Samurai lqr->PeerOutLQRs = ++ifOutLQRs; 2236059Samurai LqrDump("LqrOutput", lqr); 22428679Sbrian LqrChangeOrder(lqr, (struct lqrdata *) (MBUF_CTOP(bp))); 2256059Samurai } 2266735Samurai if (!DEV_IS_SYNC) { 2276735Samurai fcs = HdlcFcs(INITFCS, MBUF_CTOP(mhp), mhp->cnt); 2286735Samurai fcs = HdlcFcs(fcs, MBUF_CTOP(bp), bp->cnt); 2296735Samurai fcs = ~fcs; 2306735Samurai cp = MBUF_CTOP(mfcs); 23128679Sbrian *cp++ = fcs & 0377; /* Low byte first!! */ 2326735Samurai *cp++ = fcs >> 8; 2336735Samurai } 23426516Sbrian LogDumpBp(LogHDLC, "HdlcOutput", mhp); 2356059Samurai for (statp = ProtocolStat; statp->number; statp++) 2366059Samurai if (statp->number == proto) 2376059Samurai break; 2386059Samurai statp->out_count++; 23931514Sbrian 24031514Sbrian LogPrintf(LogDEBUG, "HdlcOutput: proto = 0x%04x\n", proto); 24131514Sbrian 2426735Samurai if (DEV_IS_SYNC) 2436735Samurai ModemOutput(pri, mhp); 2446735Samurai else 2456735Samurai AsyncOutput(pri, mhp, proto); 2466059Samurai} 2476059Samurai 24813379Sphkvoid 24928679SbrianDecodePacket(u_short proto, struct mbuf * bp) 2506059Samurai{ 2519448Samurai u_char *cp; 2529448Samurai 25331514Sbrian LogPrintf(LogDEBUG, "DecodePacket: proto = 0x%04x\n", proto); 25426516Sbrian 25531514Sbrian /* 25631514Sbrian * If proto isn't PROTO_COMPD, we still want to pass it to the 25731514Sbrian * decompression routines so that the dictionary's updated 25831514Sbrian */ 25931514Sbrian if (proto == PROTO_COMPD) { 26031514Sbrian if ((bp = CompdInput(&proto, bp)) == NULL) 26131514Sbrian return; 26231514Sbrian } else if ((proto & 0xfff1) == 0x21) /* Network Layer protocol */ 26331514Sbrian if (CcpFsm.state == ST_OPENED) 26431514Sbrian CcpDictSetup(proto, bp); 26531514Sbrian 2666059Samurai switch (proto) { 2676059Samurai case PROTO_LCP: 2686059Samurai LcpInput(bp); 2696059Samurai break; 2706059Samurai case PROTO_PAP: 2716059Samurai PapInput(bp); 2726059Samurai break; 2736059Samurai case PROTO_LQR: 2746059Samurai HisLqrSave.SaveInLQRs++; 2756059Samurai LqrInput(bp); 2766059Samurai break; 2776059Samurai case PROTO_CHAP: 2786059Samurai ChapInput(bp); 2796059Samurai break; 2806059Samurai case PROTO_VJUNCOMP: 2816059Samurai case PROTO_VJCOMP: 2826059Samurai bp = VjCompInput(bp, proto); 2836735Samurai if (bp == NULLBUFF) { 2846735Samurai break; 2856735Samurai } 2866059Samurai /* fall down */ 2876059Samurai case PROTO_IP: 2886059Samurai IpInput(bp); 2896059Samurai break; 2906059Samurai case PROTO_IPCP: 2916059Samurai IpcpInput(bp); 2926059Samurai break; 2936059Samurai case PROTO_CCP: 2946059Samurai CcpInput(bp); 2956059Samurai break; 2966059Samurai default: 29726516Sbrian LogPrintf(LogPHASE, "Unknown protocol 0x%04x\n", proto); 2989448Samurai bp->offset -= 2; 2999448Samurai bp->cnt += 2; 3009448Samurai cp = MBUF_CTOP(bp); 30128679Sbrian LcpSendProtoRej(cp, bp->cnt); 3026059Samurai HisLqrSave.SaveInDiscards++; 3036059Samurai HdlcStat.unknownproto++; 3046059Samurai pfree(bp); 3056059Samurai break; 3066059Samurai } 3076059Samurai} 3086059Samurai 3096059Samuraiint 31031343SbrianReportProtStatus(struct cmdargs const *arg) 3116059Samurai{ 3126059Samurai struct protostat *statp; 3136059Samurai int cnt; 3146059Samurai 3156059Samurai statp = ProtocolStat; 3166059Samurai statp--; 3176059Samurai cnt = 0; 31826516Sbrian fprintf(VarTerm, " Protocol in out Protocol in out\n"); 3196059Samurai do { 3206059Samurai statp++; 32126516Sbrian fprintf(VarTerm, " %-9s: %8lu, %8lu", 32228679Sbrian statp->name, statp->in_count, statp->out_count); 3236059Samurai if (++cnt == 2) { 32426516Sbrian fprintf(VarTerm, "\n"); 3256059Samurai cnt = 0; 3266059Samurai } 3276059Samurai } while (statp->number); 3286059Samurai if (cnt) 32928679Sbrian fprintf(VarTerm, "\n"); 33028679Sbrian return (1); 3316059Samurai} 3326059Samurai 3336059Samuraiint 33431343SbrianReportHdlcStatus(struct cmdargs const *arg) 3356059Samurai{ 3366059Samurai struct hdlcstat *hp = &HdlcStat; 3376059Samurai 33826516Sbrian if (VarTerm) { 33926516Sbrian fprintf(VarTerm, "HDLC level errors\n\n"); 34026516Sbrian fprintf(VarTerm, "FCS: %u ADDR: %u COMMAND: %u PROTO: %u\n", 34128679Sbrian hp->badfcs, hp->badaddr, hp->badcommand, hp->unknownproto); 34226516Sbrian } 34326516Sbrian return 0; 3446059Samurai} 3456059Samurai 3466059Samuraistatic struct hdlcstat laststat; 3476059Samurai 3486059Samuraivoid 3496059SamuraiHdlcErrorCheck() 3506059Samurai{ 3516059Samurai struct hdlcstat *hp = &HdlcStat; 3526059Samurai struct hdlcstat *op = &laststat; 3536059Samurai 35430715Sbrian if (memcmp(hp, op, sizeof(laststat))) { 35526516Sbrian LogPrintf(LogPHASE, "HDLC errors -> FCS: %u ADDR: %u COMD: %u PROTO: %u\n", 35628679Sbrian hp->badfcs - op->badfcs, hp->badaddr - op->badaddr, 35728679Sbrian hp->badcommand - op->badcommand, hp->unknownproto - op->unknownproto); 3586059Samurai } 3596059Samurai laststat = HdlcStat; 3606059Samurai} 3616059Samurai 3626059Samuraivoid 36328679SbrianHdlcInput(struct mbuf * bp) 3646059Samurai{ 3656059Samurai u_short fcs, proto; 3666059Samurai u_char *cp, addr, ctrl; 3676059Samurai struct protostat *statp; 3686059Samurai 36926516Sbrian LogDumpBp(LogHDLC, "HdlcInput:", bp); 3706735Samurai if (DEV_IS_SYNC) 3716735Samurai fcs = GOODFCS; 3726735Samurai else 3736735Samurai fcs = HdlcFcs(INITFCS, MBUF_CTOP(bp), bp->cnt); 3746059Samurai HisLqrSave.SaveInOctets += bp->cnt + 1; 3756059Samurai 37626516Sbrian LogPrintf(LogDEBUG, "HdlcInput: fcs = %04x (%s)\n", 37728679Sbrian fcs, (fcs == GOODFCS) ? "good" : "bad"); 3786059Samurai if (fcs != GOODFCS) { 3796059Samurai HisLqrSave.SaveInErrors++; 38026516Sbrian LogPrintf(LogDEBUG, "HdlcInput: Bad FCS\n"); 3816059Samurai HdlcStat.badfcs++; 3826059Samurai pfree(bp); 3836059Samurai return; 3846059Samurai } 3856735Samurai if (!DEV_IS_SYNC) 3866735Samurai bp->cnt -= 2; /* discard FCS part */ 38725019Sphk 38825019Sphk if (bp->cnt < 2) { /* XXX: raise this bar ? */ 38928679Sbrian pfree(bp); 39028679Sbrian return; 39125019Sphk } 3926059Samurai cp = MBUF_CTOP(bp); 3936059Samurai 3946059Samurai ifInPackets++; 3956059Samurai ifInOctets += bp->cnt; 3966059Samurai 3976059Samurai if (!LcpInfo.want_acfcomp) { 39828679Sbrian 3996059Samurai /* 40028679Sbrian * We expect that packet is not compressed. 4016059Samurai */ 4026059Samurai addr = *cp++; 4036059Samurai if (addr != HDLC_ADDR) { 4046059Samurai HisLqrSave.SaveInErrors++; 4056059Samurai HdlcStat.badaddr++; 40626516Sbrian LogPrintf(LogDEBUG, "HdlcInput: addr %02x\n", *cp); 4076059Samurai pfree(bp); 4086059Samurai return; 4096059Samurai } 4106059Samurai ctrl = *cp++; 4116059Samurai if (ctrl != HDLC_UI) { 4126059Samurai HisLqrSave.SaveInErrors++; 4136059Samurai HdlcStat.badcommand++; 41426516Sbrian LogPrintf(LogDEBUG, "HdlcInput: %02x\n", *cp); 4156059Samurai pfree(bp); 4166059Samurai return; 4176059Samurai } 4186059Samurai bp->offset += 2; 4196059Samurai bp->cnt -= 2; 4206059Samurai } else if (cp[0] == HDLC_ADDR && cp[1] == HDLC_UI) { 42128679Sbrian 4226059Samurai /* 42328679Sbrian * We can receive compressed packet, but peer still send uncompressed 42428679Sbrian * packet to me. 4256059Samurai */ 4266059Samurai cp += 2; 4276059Samurai bp->offset += 2; 4286059Samurai bp->cnt -= 2; 4296059Samurai } 4306059Samurai if (LcpInfo.want_protocomp) { 4316059Samurai proto = 0; 4326059Samurai cp--; 4336059Samurai do { 43428679Sbrian cp++; 43528679Sbrian bp->offset++; 43628679Sbrian bp->cnt--; 4376059Samurai proto = proto << 8; 4386059Samurai proto += *cp; 4396059Samurai } while (!(proto & 1)); 4406059Samurai } else { 4416059Samurai proto = *cp++ << 8; 4426059Samurai proto |= *cp++; 4436059Samurai bp->offset += 2; 4446059Samurai bp->cnt -= 2; 4456059Samurai } 4466059Samurai 4476059Samurai for (statp = ProtocolStat; statp->number; statp++) 4486059Samurai if (statp->number == proto) 4496059Samurai break; 4506059Samurai statp->in_count++; 4516059Samurai HisLqrSave.SaveInPackets++; 4526059Samurai 4536059Samurai DecodePacket(proto, bp); 4546059Samurai} 455