hdlc.c (31343) | hdlc.c (31514) |
---|---|
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 * | 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 * |
20 * $Id: hdlc.c,v 1.21 1997/10/26 12:42:10 brian Exp $ | 20 * $Id: hdlc.c,v 1.22 1997/11/22 03:37:32 brian Exp $ |
21 * 22 * TODO: 23 */ 24#include <sys/param.h> 25#include <netinet/in.h> 26 27#include <stdio.h> 28#include <string.h> --- 12 unchanged lines hidden (view full) --- 41#include "vjcomp.h" 42#include "pap.h" 43#include "chap.h" 44#include "lcp.h" 45#include "async.h" 46#include "lqr.h" 47#include "loadalias.h" 48#include "vars.h" | 21 * 22 * TODO: 23 */ 24#include <sys/param.h> 25#include <netinet/in.h> 26 27#include <stdio.h> 28#include <string.h> --- 12 unchanged lines hidden (view full) --- 41#include "vjcomp.h" 42#include "pap.h" 43#include "chap.h" 44#include "lcp.h" 45#include "async.h" 46#include "lqr.h" 47#include "loadalias.h" 48#include "vars.h" |
49#include "pred.h" | |
50#include "modem.h" 51#include "ccp.h" 52 53struct hdlcstat { 54 int badfcs; 55 int badaddr; 56 int badcommand; 57 int unknownproto; --- 77 unchanged lines hidden (view full) --- 135inline u_short 136HdlcFcs(u_short fcs, u_char * cp, int len) 137{ 138 while (len--) 139 fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff]; 140 return (fcs); 141} 142 | 49#include "modem.h" 50#include "ccp.h" 51 52struct hdlcstat { 53 int badfcs; 54 int badaddr; 55 int badcommand; 56 int unknownproto; --- 77 unchanged lines hidden (view full) --- 134inline u_short 135HdlcFcs(u_short fcs, u_char * cp, int len) 136{ 137 while (len--) 138 fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff]; 139 return (fcs); 140} 141 |
142inline u_short 143HdlcFcsBuf(u_short fcs, struct mbuf *m) 144{ 145 int len; 146 u_char *pos, *end; 147 148 len = plength(m); 149 pos = MBUF_CTOP(m); 150 end = pos + m->cnt; 151 while (len--) { 152 fcs = (fcs >> 8) ^ fcstab[(fcs ^ *pos++) & 0xff]; 153 if (pos == end && len) { 154 m = m->next; 155 pos = MBUF_CTOP(m); 156 end = pos + m->cnt; 157 } 158 } 159 return (fcs); 160} 161 |
|
143void 144HdlcOutput(int pri, u_short proto, struct mbuf * bp) 145{ 146 struct mbuf *mhp, *mfcs; 147 struct protostat *statp; 148 struct lqrdata *lqr; 149 u_char *cp; 150 u_short fcs; 151 | 162void 163HdlcOutput(int pri, u_short proto, struct mbuf * bp) 164{ 165 struct mbuf *mhp, *mfcs; 166 struct protostat *statp; 167 struct lqrdata *lqr; 168 u_char *cp; 169 u_short fcs; 170 |
152 if ((proto & 0xfff1) == 0x21) { /* Network Layer protocol */ 153 if (CcpFsm.state == ST_OPENED) { 154 if (CcpInfo.want_proto == TY_PRED1) { 155 Pred1Output(pri, proto, bp); | 171 if ((proto & 0xfff1) == 0x21) /* Network Layer protocol */ 172 if (CcpFsm.state == ST_OPENED) 173 if (CcpOutput(pri, proto, bp)) |
156 return; | 174 return; |
157 } 158 } 159 } | 175 |
160 if (DEV_IS_SYNC) 161 mfcs = NULLBUFF; 162 else 163 mfcs = mballoc(2, MB_HDLCOUT); | 176 if (DEV_IS_SYNC) 177 mfcs = NULLBUFF; 178 else 179 mfcs = mballoc(2, MB_HDLCOUT); |
180 |
|
164 mhp = mballoc(4, MB_HDLCOUT); 165 mhp->cnt = 0; 166 cp = MBUF_CTOP(mhp); 167 if (proto == PROTO_LCP || LcpInfo.his_acfcomp == 0) { 168 *cp++ = HDLC_ADDR; 169 *cp++ = HDLC_UI; 170 mhp->cnt += 2; 171 } --- 5 unchanged lines hidden (view full) --- 177 *cp++ = proto; 178 mhp->cnt++; 179 } else { 180 *cp++ = proto >> 8; 181 *cp = proto & 0377; 182 mhp->cnt += 2; 183 } 184 mhp->next = bp; | 181 mhp = mballoc(4, MB_HDLCOUT); 182 mhp->cnt = 0; 183 cp = MBUF_CTOP(mhp); 184 if (proto == PROTO_LCP || LcpInfo.his_acfcomp == 0) { 185 *cp++ = HDLC_ADDR; 186 *cp++ = HDLC_UI; 187 mhp->cnt += 2; 188 } --- 5 unchanged lines hidden (view full) --- 194 *cp++ = proto; 195 mhp->cnt++; 196 } else { 197 *cp++ = proto >> 8; 198 *cp = proto & 0377; 199 mhp->cnt += 2; 200 } 201 mhp->next = bp; |
202 while (bp->next != NULL) 203 bp = bp->next; |
|
185 bp->next = mfcs; | 204 bp->next = mfcs; |
205 bp = mhp->next; |
|
186 187 lqr = &MyLqrData; 188 lqr->PeerOutPackets = ifOutPackets++; 189 ifOutOctets += plength(mhp) + 1; 190 lqr->PeerOutOctets = ifOutOctets; 191 192 if (proto == PROTO_LQR) { 193 lqr->MagicNumber = LcpInfo.want_magic; --- 17 unchanged lines hidden (view full) --- 211 *cp++ = fcs & 0377; /* Low byte first!! */ 212 *cp++ = fcs >> 8; 213 } 214 LogDumpBp(LogHDLC, "HdlcOutput", mhp); 215 for (statp = ProtocolStat; statp->number; statp++) 216 if (statp->number == proto) 217 break; 218 statp->out_count++; | 206 207 lqr = &MyLqrData; 208 lqr->PeerOutPackets = ifOutPackets++; 209 ifOutOctets += plength(mhp) + 1; 210 lqr->PeerOutOctets = ifOutOctets; 211 212 if (proto == PROTO_LQR) { 213 lqr->MagicNumber = LcpInfo.want_magic; --- 17 unchanged lines hidden (view full) --- 231 *cp++ = fcs & 0377; /* Low byte first!! */ 232 *cp++ = fcs >> 8; 233 } 234 LogDumpBp(LogHDLC, "HdlcOutput", mhp); 235 for (statp = ProtocolStat; statp->number; statp++) 236 if (statp->number == proto) 237 break; 238 statp->out_count++; |
239 240 LogPrintf(LogDEBUG, "HdlcOutput: proto = 0x%04x\n", proto); 241 |
|
219 if (DEV_IS_SYNC) 220 ModemOutput(pri, mhp); 221 else 222 AsyncOutput(pri, mhp, proto); 223} 224 225void 226DecodePacket(u_short proto, struct mbuf * bp) 227{ 228 u_char *cp; 229 | 242 if (DEV_IS_SYNC) 243 ModemOutput(pri, mhp); 244 else 245 AsyncOutput(pri, mhp, proto); 246} 247 248void 249DecodePacket(u_short proto, struct mbuf * bp) 250{ 251 u_char *cp; 252 |
230 LogPrintf(LogDEBUG, "DecodePacket: proto = %04x\n", proto); | 253 LogPrintf(LogDEBUG, "DecodePacket: proto = 0x%04x\n", proto); |
231 | 254 |
255 /* 256 * If proto isn't PROTO_COMPD, we still want to pass it to the 257 * decompression routines so that the dictionary's updated 258 */ 259 if (proto == PROTO_COMPD) { 260 if ((bp = CompdInput(&proto, bp)) == NULL) 261 return; 262 } else if ((proto & 0xfff1) == 0x21) /* Network Layer protocol */ 263 if (CcpFsm.state == ST_OPENED) 264 CcpDictSetup(proto, bp); 265 |
|
232 switch (proto) { 233 case PROTO_LCP: 234 LcpInput(bp); 235 break; 236 case PROTO_PAP: 237 PapInput(bp); 238 break; 239 case PROTO_LQR: --- 14 unchanged lines hidden (view full) --- 254 IpInput(bp); 255 break; 256 case PROTO_IPCP: 257 IpcpInput(bp); 258 break; 259 case PROTO_CCP: 260 CcpInput(bp); 261 break; | 266 switch (proto) { 267 case PROTO_LCP: 268 LcpInput(bp); 269 break; 270 case PROTO_PAP: 271 PapInput(bp); 272 break; 273 case PROTO_LQR: --- 14 unchanged lines hidden (view full) --- 288 IpInput(bp); 289 break; 290 case PROTO_IPCP: 291 IpcpInput(bp); 292 break; 293 case PROTO_CCP: 294 CcpInput(bp); 295 break; |
262 case PROTO_COMPD: 263 Pred1Input(bp); 264 break; | |
265 default: 266 LogPrintf(LogPHASE, "Unknown protocol 0x%04x\n", proto); 267 bp->offset -= 2; 268 bp->cnt += 2; 269 cp = MBUF_CTOP(bp); 270 LcpSendProtoRej(cp, bp->cnt); 271 HisLqrSave.SaveInDiscards++; 272 HdlcStat.unknownproto++; --- 151 unchanged lines hidden --- | 296 default: 297 LogPrintf(LogPHASE, "Unknown protocol 0x%04x\n", proto); 298 bp->offset -= 2; 299 bp->cnt += 2; 300 cp = MBUF_CTOP(bp); 301 LcpSendProtoRej(cp, bp->cnt); 302 HisLqrSave.SaveInDiscards++; 303 HdlcStat.unknownproto++; --- 151 unchanged lines hidden --- |