xref: /freebsd/usr.sbin/ppp/hdlc.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
165309e5cSBrian Somers /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
465309e5cSBrian Somers  * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
565309e5cSBrian Somers  *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
665309e5cSBrian Somers  *                           Internet Initiative Japan, Inc (IIJ)
765309e5cSBrian Somers  * All rights reserved.
8af57ed9fSAtsushi Murai  *
965309e5cSBrian Somers  * Redistribution and use in source and binary forms, with or without
1065309e5cSBrian Somers  * modification, are permitted provided that the following conditions
1165309e5cSBrian Somers  * are met:
1265309e5cSBrian Somers  * 1. Redistributions of source code must retain the above copyright
1365309e5cSBrian Somers  *    notice, this list of conditions and the following disclaimer.
1465309e5cSBrian Somers  * 2. Redistributions in binary form must reproduce the above copyright
1565309e5cSBrian Somers  *    notice, this list of conditions and the following disclaimer in the
1665309e5cSBrian Somers  *    documentation and/or other materials provided with the distribution.
17af57ed9fSAtsushi Murai  *
1865309e5cSBrian Somers  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1965309e5cSBrian Somers  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2065309e5cSBrian Somers  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2165309e5cSBrian Somers  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2265309e5cSBrian Somers  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2365309e5cSBrian Somers  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2465309e5cSBrian Somers  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2565309e5cSBrian Somers  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2665309e5cSBrian Somers  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2765309e5cSBrian Somers  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2865309e5cSBrian Somers  * SUCH DAMAGE.
29af57ed9fSAtsushi Murai  */
30af57ed9fSAtsushi Murai 
31af57ed9fSAtsushi Murai /*
32af57ed9fSAtsushi Murai  *  Definition for Async HDLC
33af57ed9fSAtsushi Murai  */
34af57ed9fSAtsushi Murai #define HDLC_SYN 0x7e		/* SYNC character */
35af57ed9fSAtsushi Murai #define HDLC_ESC 0x7d		/* Escape character */
36af57ed9fSAtsushi Murai #define HDLC_XOR 0x20		/* Modifier value */
37af57ed9fSAtsushi Murai 
38af57ed9fSAtsushi Murai #define	HDLC_ADDR 0xff
39af57ed9fSAtsushi Murai #define	HDLC_UI	  0x03
40af57ed9fSAtsushi Murai /*
41af57ed9fSAtsushi Murai  *  Definition for HDLC Frame Check Sequence
42af57ed9fSAtsushi Murai  */
43af57ed9fSAtsushi Murai #define INITFCS 0xffff		/* Initial value for FCS computation */
44af57ed9fSAtsushi Murai #define GOODFCS 0xf0b8		/* Good FCS value */
45af57ed9fSAtsushi Murai 
46af57ed9fSAtsushi Murai #define	DEF_MRU		1500
47a40fdd98SBrian Somers #define	MAX_MRU		2048
48af57ed9fSAtsushi Murai #define	MIN_MRU		296
49af57ed9fSAtsushi Murai 
50da2b73b1SBrian Somers #define	DEF_MTU		0	/* whatever peer says */
51a40fdd98SBrian Somers #define	MAX_MTU		2048
52da2b73b1SBrian Somers #define	MIN_MTU		296
53da2b73b1SBrian Somers 
5463b73463SBrian Somers struct physical;
558c07a7b2SBrian Somers struct link;
562764b86aSBrian Somers struct lcp;
572764b86aSBrian Somers struct bundle;
582764b86aSBrian Somers struct mbuf;
592764b86aSBrian Somers struct cmdargs;
60af57ed9fSAtsushi Murai 
6163258dccSBrian Somers struct hdlc {
6263258dccSBrian Somers   struct pppTimer ReportTimer;
6363258dccSBrian Somers 
6463258dccSBrian Somers   struct {
6563258dccSBrian Somers     int badfcs;
6663258dccSBrian Somers     int badaddr;
6763258dccSBrian Somers     int badcommand;
6863258dccSBrian Somers     int unknownproto;
6963258dccSBrian Somers   } laststats, stats;
7063258dccSBrian Somers 
7163258dccSBrian Somers   struct {
72879ed6faSBrian Somers     struct lcp *owner;			/* parent LCP */
73879ed6faSBrian Somers     struct pppTimer timer;		/* When to send */
74879ed6faSBrian Somers     int method;				/* bit-mask for LQM_* from lqr.h */
75879ed6faSBrian Somers 
76a57095e7SBrian Somers     u_int32_t ifOutUniPackets;		/* Packets sent by me */
77a57095e7SBrian Somers     u_int32_t ifOutOctets;		/* Octets sent by me */
78a57095e7SBrian Somers     u_int32_t ifInUniPackets;		/* Packets received from peer */
79a57095e7SBrian Somers     u_int32_t ifInDiscards;		/* Discards */
80a57095e7SBrian Somers     u_int32_t ifInErrors;		/* Errors */
81a57095e7SBrian Somers     u_int32_t ifInOctets;		/* Octets received from peer (unused) */
82879ed6faSBrian Somers 
83879ed6faSBrian Somers     struct {
84a57095e7SBrian Somers       u_int32_t InGoodOctets;		/* Good octets received from peer */
85879ed6faSBrian Somers       u_int32_t OutLQRs;		/* LQRs sent by me */
86a57095e7SBrian Somers       u_int32_t InLQRs;			/* LQRs received from peer */
87a57095e7SBrian Somers 
88a57095e7SBrian Somers       struct lqrsavedata Save;		/* Our last LQR */
89a57095e7SBrian Somers       struct lqrsavedata prevSave;	/* Our last-but-one LQR (analysis) */
90a57095e7SBrian Somers 
91879ed6faSBrian Somers       struct lqrdata peer;		/* Last LQR from peer */
92879ed6faSBrian Somers       int peer_timeout;			/* peers max lqr timeout */
93879ed6faSBrian Somers       int resent;			/* Resent last packet `resent' times */
9463258dccSBrian Somers     } lqr;
95879ed6faSBrian Somers 
96879ed6faSBrian Somers     struct {
97879ed6faSBrian Somers       u_int32_t seq_sent;		/* last echo sent */
98879ed6faSBrian Somers       u_int32_t seq_recv;		/* last echo received */
99879ed6faSBrian Somers     } echo;
100879ed6faSBrian Somers   } lqm;
10163258dccSBrian Somers };
10263258dccSBrian Somers 
10363258dccSBrian Somers 
104643f4904SBrian Somers extern void hdlc_Init(struct hdlc *, struct lcp *);
10563258dccSBrian Somers extern void hdlc_StartTimer(struct hdlc *);
10663258dccSBrian Somers extern void hdlc_StopTimer(struct hdlc *);
10763258dccSBrian Somers extern int hdlc_ReportStatus(struct cmdargs const *);
10863258dccSBrian Somers extern const char *hdlc_Protocol2Nam(u_short);
109cd7bd93aSBrian Somers extern void hdlc_DecodePacket(struct bundle *, u_short, struct mbuf *,
110cd7bd93aSBrian Somers                               struct link *);
11163258dccSBrian Somers 
1125d9e6103SBrian Somers extern u_short hdlc_Fcs(u_char *, size_t);
113057f1760SBrian Somers extern int hdlc_Detect(u_char const **, unsigned, int);
114057f1760SBrian Somers #define hdlc_WrapperOctets() (2)
1155d9e6103SBrian Somers 
1165d9e6103SBrian Somers extern struct layer hdlclayer;
117