ccp.h revision 50479
16059Samurai/*
26059Samurai *	    Written by Toshiharu OHNO (tony-o@iij.ad.jp)
36059Samurai *
46059Samurai *   Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
56059Samurai *
66059Samurai * Redistribution and use in source and binary forms are permitted
76059Samurai * provided that the above copyright notice and this paragraph are
86059Samurai * duplicated in all such forms and that any documentation,
96059Samurai * advertising materials, and other materials related to such
106059Samurai * distribution and use acknowledge that the software was developed
116059Samurai * by the Internet Initiative Japan.  The name of the
126059Samurai * IIJ may not be used to endorse or promote products derived
136059Samurai * from this software without specific prior written permission.
146059Samurai * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
156059Samurai * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
166059Samurai * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
176059Samurai *
1850479Speter * $FreeBSD: head/usr.sbin/ppp/ccp.h 50479 1999-08-28 01:35:59Z peter $
196059Samurai *
206059Samurai *	TODO:
216059Samurai */
226059Samurai
236059Samurai#define	CCP_MAXCODE	CODE_RESETACK
246059Samurai
256059Samurai#define	TY_OUI		0	/* OUI */
266059Samurai#define	TY_PRED1	1	/* Predictor type 1 */
276059Samurai#define	TY_PRED2	2	/* Predictor type 2 */
286059Samurai#define	TY_PUDDLE	3	/* Puddle Jumper */
296059Samurai#define	TY_HWPPC	16	/* Hewlett-Packard PPC */
306059Samurai#define	TY_STAC		17	/* Stac Electronics LZS */
316059Samurai#define	TY_MSPPC	18	/* Microsoft PPC */
326059Samurai#define	TY_GAND		19	/* Gandalf FZA */
336059Samurai#define	TY_V42BIS	20	/* V.42bis compression */
346059Samurai#define	TY_BSD		21	/* BSD LZW Compress */
3531518Sbrian#define	TY_PPPD_DEFLATE	24	/* Deflate (gzip) - (mis) numbered by pppd */
3631518Sbrian#define	TY_DEFLATE	26	/* Deflate (gzip) - rfc 1979 */
376059Samurai
3836285Sbrian#define CCP_NEG_DEFLATE		0
3936285Sbrian#define CCP_NEG_PRED1		1
4036285Sbrian#define CCP_NEG_DEFLATE24	2
4136285Sbrian#define CCP_NEG_TOTAL		3
4236285Sbrian
4336285Sbrianstruct mbuf;
4436285Sbrianstruct link;
4536285Sbrian
4636285Sbrianstruct ccp_config {
4736285Sbrian  struct {
4836285Sbrian    struct {
4936285Sbrian      int winsize;
5036285Sbrian    } in, out;
5136285Sbrian  } deflate;
5244305Sbrian  struct fsm_retry fsm;	/* How often/frequently to resend requests */
5336285Sbrian  unsigned neg[CCP_NEG_TOTAL];
5436285Sbrian};
5536285Sbrian
5636285Sbrianstruct ccp_opt {
5736285Sbrian  struct ccp_opt *next;
5836285Sbrian  int algorithm;
5936285Sbrian  struct lcp_opt val;
6036285Sbrian};
6136285Sbrian
6236285Sbrianstruct ccp {
6336285Sbrian  struct fsm fsm;		/* The finite state machine */
6436285Sbrian
6532439Sbrian  int his_proto;		/* peer's compression protocol */
6632439Sbrian  int my_proto;			/* our compression protocol */
676059Samurai
6832381Sbrian  int reset_sent;		/* If != -1, ignore compressed 'till ack */
6932381Sbrian  int last_reset;		/* We can receive more (dups) w/ this id */
7032381Sbrian
7136285Sbrian  struct {
7236285Sbrian    int algorithm;		/* Algorithm in use */
7336285Sbrian    void *state;		/* Returned by implementations Init() */
7436285Sbrian    struct lcp_opt opt;		/* Set by implementations OptInit() */
7536285Sbrian  } in;
7636285Sbrian
7736285Sbrian  struct {
7836285Sbrian    int algorithm;		/* Algorithm in use */
7936285Sbrian    void *state;		/* Returned by implementations Init() */
8036285Sbrian    struct ccp_opt *opt;	/* Set by implementations OptInit() */
8136285Sbrian  } out;
8236285Sbrian
8332439Sbrian  u_int32_t his_reject;		/* Request codes rejected by peer */
8432439Sbrian  u_int32_t my_reject;		/* Request codes I have rejected */
856059Samurai
8637210Sbrian  u_long uncompout, compout;	/* Outgoing bytes before/after compression */
8737210Sbrian  u_long uncompin, compin;	/* Incoming bytes after/before decompression */
8836285Sbrian
8936285Sbrian  struct ccp_config cfg;
906059Samurai};
916059Samurai
9236285Sbrian#define fsm2ccp(fp) (fp->proto == PROTO_CCP ? (struct ccp *)fp : NULL)
9331514Sbrian
9431514Sbrianstruct ccp_algorithm {
9531514Sbrian  int id;
9637010Sbrian  int Neg;					/* ccp_config neg array item */
9737010Sbrian  const char *(*Disp)(struct lcp_opt *);	/* Use result immediately !  */
9831514Sbrian  struct {
9936285Sbrian    int (*Set)(struct lcp_opt *, const struct ccp_config *);
10036285Sbrian    void *(*Init)(struct lcp_opt *);
10136285Sbrian    void (*Term)(void *);
10236285Sbrian    void (*Reset)(void *);
10336285Sbrian    struct mbuf *(*Read)(void *, struct ccp *, u_short *, struct mbuf *);
10436285Sbrian    void (*DictSetup)(void *, struct ccp *, u_short, struct mbuf *);
10531514Sbrian  } i;
10631514Sbrian  struct {
10736285Sbrian    void (*OptInit)(struct lcp_opt *, const struct ccp_config *);
10831514Sbrian    int (*Set)(struct lcp_opt *);
10936285Sbrian    void *(*Init)(struct lcp_opt *);
11036285Sbrian    void (*Term)(void *);
11136285Sbrian    void (*Reset)(void *);
11246686Sbrian    struct mbuf *(*Write)(void *, struct ccp *, struct link *, int, u_short *,
11346686Sbrian                          struct mbuf *);
11431514Sbrian  } o;
11531514Sbrian};
11631514Sbrian
11736285Sbrianextern void ccp_Init(struct ccp *, struct bundle *, struct link *,
11836285Sbrian                     const struct fsm_parent *);
11936285Sbrianextern void ccp_Setup(struct ccp *);
1206059Samurai
12136285Sbrianextern void ccp_SendResetReq(struct fsm *);
12246686Sbrianextern struct mbuf *ccp_Input(struct bundle *, struct link *, struct mbuf *);
12336285Sbrianextern int ccp_ReportStatus(struct cmdargs const *);
12436285Sbrianextern u_short ccp_Proto(struct ccp *);
12536285Sbrianextern void ccp_SetupCallbacks(struct ccp *);
12637320Sbrianextern int ccp_SetOpenMode(struct ccp *);
12746686Sbrian
12846686Sbrianextern struct layer ccplayer;
129