1/*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * ppp-comp.h - Definitions for doing PPP packet compression.
25 *
26 * Copyright (c) 1994 The Australian National University.
27 * All rights reserved.
28 *
29 * Permission to use, copy, modify, and distribute this software and its
30 * documentation is hereby granted, provided that the above copyright
31 * notice appears in all copies.  This software is provided without any
32 * warranty, express or implied. The Australian National University
33 * makes no representations about the suitability of this software for
34 * any purpose.
35 *
36 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
37 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
38 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
39 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
40 * OF SUCH DAMAGE.
41 *
42 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
43 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
44 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
45 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
46 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
47 * OR MODIFICATIONS.
48 *
49 * $Id: ppp-comp.h,v 1.3 2003/08/14 00:00:39 callie Exp $
50 */
51
52#ifndef _NET_PPP_COMP_H
53#define _NET_PPP_COMP_H
54
55/*
56 * The following symbols control whether we include code for
57 * various compression methods.
58 */
59#ifndef DO_BSD_COMPRESS
60#define DO_BSD_COMPRESS	1	/* by default, include BSD-Compress */
61#endif
62#ifndef DO_DEFLATE
63#define DO_DEFLATE	1	/* by default, include Deflate */
64#endif
65#define DO_PREDICTOR_1	0
66#define DO_PREDICTOR_2	0
67
68/*
69 * Structure giving methods for compression/decompression.
70 */
71struct compressor {
72	int	compress_proto;	/* CCP compression protocol number */
73
74	/* Allocate space for a decompressor (receive side) */
75	void	*(*decomp_alloc) __P((u_char *options, int opt_len));
76	/* Free space used by a decompressor */
77	void	(*decomp_free) __P((void *state));
78	/* Initialize a decompressor */
79	int	(*decomp_init) __P((void *state, u_char *options, int opt_len,
80				    int unit, int hdrlen, int mru, int debug));
81	/* Reset a decompressor */
82	void	(*decomp_reset) __P((void *state));
83	/* Decompress a packet. */
84	int	(*decompress) __P((void *state, u_char *mp, int inlen,
85				   u_char *dmp, int *outlen));
86	/* Update state for an incompressible packet received */
87	void	(*incomp) __P((void *state, u_char *mp, int len));
88	/* Return decompression statistics */
89	void	(*decomp_stat) __P((void *state, struct compstat *stats));
90};
91
92/*
93 * Return values for decompress routine.
94 * We need to make these distinctions so that we can disable certain
95 * useful functionality, namely sending a CCP reset-request as a result
96 * of an error detected after decompression.  This is to avoid infringing
97 * a patent held by Motorola.
98 * Don't you just lurve software patents.
99 */
100#define DECOMP_OK		0	/* everything went OK */
101#define DECOMP_ERROR		1	/* error detected before decomp. */
102#define DECOMP_FATALERROR	2	/* error detected after decomp. */
103
104/*
105 * CCP codes.
106 */
107#define CCP_CONFREQ	1
108#define CCP_CONFACK	2
109#define CCP_CONFNAK	3
110#define CCP_CONFREJ	4
111#define CCP_TERMREQ	5
112#define CCP_TERMACK	6
113#define CCP_RESETREQ	14
114#define CCP_RESETACK	15
115
116/*
117 * Max # bytes for a CCP option
118 */
119#define CCP_MAX_OPTION_LENGTH	32
120
121/*
122 * Parts of a CCP packet.
123 */
124#define CCP_CODE(dp)		((dp)[0])
125#define CCP_ID(dp)		((dp)[1])
126#define CCP_LENGTH(dp)		(((dp)[2] << 8) + (dp)[3])
127#define CCP_HDRLEN		4
128
129#define CCP_OPT_CODE(dp)	((dp)[0])
130#define CCP_OPT_LENGTH(dp)	((dp)[1])
131#define CCP_OPT_MINLEN		2
132
133/*
134 * Definitions for BSD-Compress.
135 */
136#define CI_BSD_COMPRESS		21	/* config. option for BSD-Compress */
137#define CILEN_BSD_COMPRESS	3	/* length of config. option */
138
139/* Macros for handling the 3rd byte of the BSD-Compress config option. */
140#define BSD_NBITS(x)		((x) & 0x1F)	/* number of bits requested */
141#define BSD_VERSION(x)		((x) >> 5)	/* version of option format */
142#define BSD_CURRENT_VERSION	1		/* current version number */
143#define BSD_MAKE_OPT(v, n)	(((v) << 5) | (n))
144
145#define BSD_MIN_BITS		9	/* smallest code size supported */
146#define BSD_MAX_BITS		15	/* largest code size supported */
147
148/*
149 * Definitions for Deflate.
150 */
151#define CI_DEFLATE		26	/* config option for Deflate */
152#define CI_DEFLATE_DRAFT	24	/* value used in original draft RFC */
153#define CILEN_DEFLATE		4	/* length of its config option */
154
155#define DEFLATE_MIN_SIZE	8
156#define DEFLATE_MAX_SIZE	15
157#define DEFLATE_METHOD_VAL	8
158#define DEFLATE_SIZE(x)		(((x) >> 4) + DEFLATE_MIN_SIZE)
159#define DEFLATE_METHOD(x)	((x) & 0x0F)
160#define DEFLATE_MAKE_OPT(w)	((((w) - DEFLATE_MIN_SIZE) << 4) \
161				 + DEFLATE_METHOD_VAL)
162#define DEFLATE_CHK_SEQUENCE	0
163
164/*
165 * Definitions for other, as yet unsupported, compression methods.
166 */
167#define CI_PREDICTOR_1		1	/* config option for Predictor-1 */
168#define CILEN_PREDICTOR_1	2	/* length of its config option */
169#define CI_PREDICTOR_2		2	/* config option for Predictor-2 */
170#define CILEN_PREDICTOR_2	2	/* length of its config option */
171
172#endif /* _NET_PPP_COMP_H */
173