178189Sbrian/*-
278189Sbrian * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
378189Sbrian *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
478189Sbrian *                           Internet Initiative Japan, Inc (IIJ)
578189Sbrian * All rights reserved.
66059Samurai *
778189Sbrian * Redistribution and use in source and binary forms, with or without
878189Sbrian * modification, are permitted provided that the following conditions
978189Sbrian * are met:
1078189Sbrian * 1. Redistributions of source code must retain the above copyright
1178189Sbrian *    notice, this list of conditions and the following disclaimer.
1278189Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1378189Sbrian *    notice, this list of conditions and the following disclaimer in the
1478189Sbrian *    documentation and/or other materials provided with the distribution.
156059Samurai *
1678189Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1778189Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1878189Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1978189Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2078189Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2178189Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2278189Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2378189Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2478189Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2578189Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2678189Sbrian * SUCH DAMAGE.
276059Samurai *
2850479Speter * $FreeBSD: releng/11.0/usr.sbin/ppp/ccp.h 98132 2002-06-12 00:33:17Z brian $
296059Samurai */
306059Samurai
316059Samurai#define	CCP_MAXCODE	CODE_RESETACK
326059Samurai
336059Samurai#define	TY_OUI		0	/* OUI */
346059Samurai#define	TY_PRED1	1	/* Predictor type 1 */
356059Samurai#define	TY_PRED2	2	/* Predictor type 2 */
366059Samurai#define	TY_PUDDLE	3	/* Puddle Jumper */
376059Samurai#define	TY_HWPPC	16	/* Hewlett-Packard PPC */
386059Samurai#define	TY_STAC		17	/* Stac Electronics LZS */
396059Samurai#define	TY_MSPPC	18	/* Microsoft PPC */
4067910Sbrian#define	TY_MPPE		18	/* Microsoft PPE */
416059Samurai#define	TY_GAND		19	/* Gandalf FZA */
426059Samurai#define	TY_V42BIS	20	/* V.42bis compression */
436059Samurai#define	TY_BSD		21	/* BSD LZW Compress */
4431518Sbrian#define	TY_PPPD_DEFLATE	24	/* Deflate (gzip) - (mis) numbered by pppd */
4531518Sbrian#define	TY_DEFLATE	26	/* Deflate (gzip) - rfc 1979 */
466059Samurai
4736285Sbrian#define CCP_NEG_DEFLATE		0
4836285Sbrian#define CCP_NEG_PRED1		1
4936285Sbrian#define CCP_NEG_DEFLATE24	2
5093418Sbrian#ifndef NODES
5167910Sbrian#define CCP_NEG_MPPE		3
5267910Sbrian#define CCP_NEG_TOTAL		4
5367910Sbrian#else
5436285Sbrian#define CCP_NEG_TOTAL		3
5567910Sbrian#endif
5636285Sbrian
5793418Sbrian#ifndef NODES
5878411Sbrianenum mppe_negstate {
5978411Sbrian  MPPE_ANYSTATE,
6078411Sbrian  MPPE_STATELESS,
6178411Sbrian  MPPE_STATEFUL
6278411Sbrian};
6378411Sbrian#endif
6478411Sbrian
6536285Sbrianstruct mbuf;
6636285Sbrianstruct link;
6736285Sbrian
6836285Sbrianstruct ccp_config {
6936285Sbrian  struct {
7036285Sbrian    struct {
7136285Sbrian      int winsize;
7236285Sbrian    } in, out;
7336285Sbrian  } deflate;
7493418Sbrian#ifndef NODES
7567910Sbrian  struct {
7667910Sbrian    int keybits;
7778411Sbrian    enum mppe_negstate state;
7878411Sbrian    unsigned required : 1;
7967910Sbrian  } mppe;
8067910Sbrian#endif
8144305Sbrian  struct fsm_retry fsm;	/* How often/frequently to resend requests */
8236285Sbrian  unsigned neg[CCP_NEG_TOTAL];
8336285Sbrian};
8436285Sbrian
8536285Sbrianstruct ccp_opt {
8636285Sbrian  struct ccp_opt *next;
8736285Sbrian  int algorithm;
8894894Sbrian  struct fsm_opt val;
8936285Sbrian};
9036285Sbrian
9136285Sbrianstruct ccp {
9236285Sbrian  struct fsm fsm;		/* The finite state machine */
9336285Sbrian
9432439Sbrian  int his_proto;		/* peer's compression protocol */
9532439Sbrian  int my_proto;			/* our compression protocol */
966059Samurai
9732381Sbrian  int reset_sent;		/* If != -1, ignore compressed 'till ack */
9832381Sbrian  int last_reset;		/* We can receive more (dups) w/ this id */
9932381Sbrian
10036285Sbrian  struct {
10136285Sbrian    int algorithm;		/* Algorithm in use */
10236285Sbrian    void *state;		/* Returned by implementations Init() */
10394894Sbrian    struct fsm_opt opt;		/* Set by implementation's OptInit() */
10436285Sbrian  } in;
10536285Sbrian
10636285Sbrian  struct {
10736285Sbrian    int algorithm;		/* Algorithm in use */
10836285Sbrian    void *state;		/* Returned by implementations Init() */
10968423Sbrian    struct ccp_opt *opt;	/* Set by implementation's OptInit() */
11036285Sbrian  } out;
11136285Sbrian
11232439Sbrian  u_int32_t his_reject;		/* Request codes rejected by peer */
11332439Sbrian  u_int32_t my_reject;		/* Request codes I have rejected */
1146059Samurai
11537210Sbrian  u_long uncompout, compout;	/* Outgoing bytes before/after compression */
11637210Sbrian  u_long uncompin, compin;	/* Incoming bytes after/before decompression */
11736285Sbrian
11836285Sbrian  struct ccp_config cfg;
1196059Samurai};
1206059Samurai
12136285Sbrian#define fsm2ccp(fp) (fp->proto == PROTO_CCP ? (struct ccp *)fp : NULL)
12231514Sbrian
12331514Sbrianstruct ccp_algorithm {
12431514Sbrian  int id;
12537010Sbrian  int Neg;					/* ccp_config neg array item */
12694894Sbrian  const char *(*Disp)(struct fsm_opt *);	/* Use result immediately !  */
12772025Sbrian  int (*Usable)(struct fsm *);			/* Ok to negotiate ? */
12878411Sbrian  int (*Required)(struct fsm *);		/* Must negotiate ? */
12931514Sbrian  struct {
13098132Sbrian    int (*Set)(struct bundle *, struct fsm_opt *, const struct ccp_config *);
13198132Sbrian    void *(*Init)(struct bundle *, struct fsm_opt *);
13236285Sbrian    void (*Term)(void *);
13336285Sbrian    void (*Reset)(void *);
13436285Sbrian    struct mbuf *(*Read)(void *, struct ccp *, u_short *, struct mbuf *);
13536285Sbrian    void (*DictSetup)(void *, struct ccp *, u_short, struct mbuf *);
13631514Sbrian  } i;
13731514Sbrian  struct {
13879165Sbrian    int MTUOverhead;
13998132Sbrian    void (*OptInit)(struct bundle *, struct fsm_opt *,
14098132Sbrian                    const struct ccp_config *);
14198132Sbrian    int (*Set)(struct bundle *, struct fsm_opt *, const struct ccp_config *);
14298132Sbrian    void *(*Init)(struct bundle *, struct fsm_opt *);
14336285Sbrian    void (*Term)(void *);
14478411Sbrian    int (*Reset)(void *);
14546686Sbrian    struct mbuf *(*Write)(void *, struct ccp *, struct link *, int, u_short *,
14646686Sbrian                          struct mbuf *);
14731514Sbrian  } o;
14831514Sbrian};
14931514Sbrian
15036285Sbrianextern void ccp_Init(struct ccp *, struct bundle *, struct link *,
15136285Sbrian                     const struct fsm_parent *);
15236285Sbrianextern void ccp_Setup(struct ccp *);
15378411Sbrianextern int ccp_Required(struct ccp *);
15479165Sbrianextern int ccp_MTUOverhead(struct ccp *);
1556059Samurai
15636285Sbrianextern void ccp_SendResetReq(struct fsm *);
15746686Sbrianextern struct mbuf *ccp_Input(struct bundle *, struct link *, struct mbuf *);
15836285Sbrianextern int ccp_ReportStatus(struct cmdargs const *);
15936285Sbrianextern u_short ccp_Proto(struct ccp *);
16036285Sbrianextern void ccp_SetupCallbacks(struct ccp *);
16137320Sbrianextern int ccp_SetOpenMode(struct ccp *);
16278411Sbrianextern int ccp_DefaultUsable(struct fsm *);
16378411Sbrianextern int ccp_DefaultRequired(struct fsm *);
16446686Sbrian
16546686Sbrianextern struct layer ccplayer;
166