xref: /titanic_52/usr/src/uts/common/net/ppp-comp.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * ppp-comp.h - Definitions for doing PPP packet compression.
24  *
25  * Copyright (c) 2000 by Sun Microsystems, Inc.
26  * All rights reserved.
27  *
28  * Copyright (c) 1994 The Australian National University.
29  * All rights reserved.
30  *
31  * Permission to use, copy, modify, and distribute this software and its
32  * documentation is hereby granted, provided that the above copyright
33  * notice appears in all copies.  This software is provided without any
34  * warranty, express or implied. The Australian National University
35  * makes no representations about the suitability of this software for
36  * any purpose.
37  *
38  * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
39  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
40  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
41  * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
42  * OF SUCH DAMAGE.
43  *
44  * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
45  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
46  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
47  * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
48  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
49  * OR MODIFICATIONS.
50  *
51  * $Id: ppp-comp.h,v 1.11 1998/03/25 03:33:34 paulus Exp $
52  */
53 
54 #ifndef _NET_PPP_COMP_H
55 #define	_NET_PPP_COMP_H
56 
57 #pragma ident	"%Z%%M%	%I%	%E% SMI"
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 /*
64  * The following symbols control whether we include code for
65  * various compression methods.
66  */
67 #ifndef DO_BSD_COMPRESS
68 #define	DO_BSD_COMPRESS	1	/* by default, include BSD-Compress */
69 #endif
70 #ifndef DO_DEFLATE
71 #define	DO_DEFLATE	1	/* by default, include Deflate */
72 #endif
73 #define	DO_PREDICTOR_1	0
74 #define	DO_PREDICTOR_2	0
75 
76 /*
77  * Structure giving methods for compression/decompression.
78  */
79 #ifdef PACKETPTR
80 struct compressor {
81 	int	compress_proto;	/* CCP compression protocol number */
82 
83 	/* Allocate space for a compressor (transmit side) */
84 	void	*(*comp_alloc) __P((uchar_t *options, int opt_len));
85 	/* Free space used by a compressor */
86 	void	(*comp_free) __P((void *state));
87 	/* Initialize a compressor */
88 	int	(*comp_init) __P((void *state, uchar_t *options, int opt_len,
89 	    int unit, int hdrlen, int debug));
90 	/* Reset a compressor */
91 	void	(*comp_reset) __P((void *state));
92 	/* Compress a packet */
93 	int	(*compress) __P((void *state, PACKETPTR *mret,
94 	    PACKETPTR mp, int orig_len, int max_len));
95 	/* Return compression statistics */
96 	void	(*comp_stat) __P((void *state, struct compstat *stats));
97 
98 	/* Allocate space for a decompressor (receive side) */
99 	void	*(*decomp_alloc) __P((uchar_t *options, int opt_len));
100 	/* Free space used by a decompressor */
101 	void	(*decomp_free) __P((void *state));
102 	/* Initialize a decompressor */
103 	int	(*decomp_init) __P((void *state, uchar_t *options, int opt_len,
104 				    int unit, int hdrlen, int mru, int debug));
105 	/* Reset a decompressor */
106 	void	(*decomp_reset) __P((void *state));
107 	/* Decompress a packet. */
108 	int	(*decompress) __P((void *state, PACKETPTR *mp));
109 	/* Update state for an incompressible packet received */
110 	int	(*incomp) __P((void *state, PACKETPTR mp));
111 	/* Return decompression statistics */
112 	void	(*decomp_stat) __P((void *state, struct compstat *stats));
113 
114 	/* Set or change compression effort level */
115 	int	(*set_effort) __P((void *xstate, void *rstate,
116 	    int effortlevel));
117 };
118 #endif /* PACKETPTR */
119 
120 /*
121  * Return values for decompress routine.
122  * We need to make these distinctions so that we can disable certain
123  * useful functionality, namely sending a CCP reset-request as a result
124  * of an error detected after decompression.  This is to avoid infringing
125  * a patent held by Motorola.
126  * Don't you just lurve software patents.
127  */
128 #define	DECOMP_OK		0	/* everything went OK */
129 #define	DECOMP_ERROR		1	/* error detected before decomp. */
130 #define	DECOMP_FATALERROR	2	/* error detected after decomp. */
131 
132 /*
133  * CCP codes.
134  */
135 #define	CCP_CONFREQ	1
136 #define	CCP_CONFACK	2
137 #define	CCP_TERMREQ	5
138 #define	CCP_TERMACK	6
139 #define	CCP_RESETREQ	14
140 #define	CCP_RESETACK	15
141 
142 /*
143  * Max # bytes for a CCP option
144  */
145 #define	CCP_MAX_OPTION_LENGTH	32
146 
147 /*
148  * Parts of a CCP packet.
149  */
150 #define	CCP_CODE(dp)		((dp)[0])
151 #define	CCP_ID(dp)		((dp)[1])
152 #define	CCP_LENGTH(dp)		(((dp)[2] << 8) + (dp)[3])
153 #define	CCP_HDRLEN		4
154 
155 #define	CCP_OPT_CODE(dp)	((dp)[0])
156 #define	CCP_OPT_LENGTH(dp)	((dp)[1])
157 #define	CCP_OPT_MINLEN		2
158 
159 /*
160  * Definitions for BSD-Compress.
161  */
162 #define	CI_BSD_COMPRESS		21	/* config. option for BSD-Compress */
163 #define	CILEN_BSD_COMPRESS	3	/* length of config. option */
164 
165 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
166 #define	BSD_NBITS(x)		((x) & 0x1F)	/* number of bits requested */
167 #define	BSD_VERSION(x)		((x) >> 5)	/* version of option format */
168 #define	BSD_CURRENT_VERSION	1		/* current version number */
169 #define	BSD_MAKE_OPT(v, n)	(((v) << 5) | (n))
170 
171 #define	BSD_MIN_BITS		9	/* smallest code size supported */
172 #define	BSD_MAX_BITS		15	/* largest code size supported */
173 
174 /*
175  * Definitions for Deflate.
176  */
177 #define	CI_DEFLATE		26	/* config option for Deflate */
178 #define	CI_DEFLATE_DRAFT	24	/* value used in original draft RFC */
179 #define	CILEN_DEFLATE		4	/* length of its config option */
180 
181 #define	DEFLATE_MIN_SIZE	8
182 #define	DEFLATE_MAX_SIZE	15
183 #define	DEFLATE_METHOD_VAL	8
184 #define	DEFLATE_SIZE(x)		(((x) >> 4) + DEFLATE_MIN_SIZE)
185 #define	DEFLATE_METHOD(x)	((x) & 0x0F)
186 #define	DEFLATE_MAKE_OPT(w)	((((w) - DEFLATE_MIN_SIZE) << 4) \
187 				    + DEFLATE_METHOD_VAL)
188 #define	DEFLATE_CHK_SEQUENCE	0
189 
190 /*
191  * Definitions for other, as yet unsupported, compression methods.
192  */
193 #define	CI_PREDICTOR_1		1	/* config option for Predictor-1 */
194 #define	CILEN_PREDICTOR_1	2	/* length of its config option */
195 #define	CI_PREDICTOR_2		2	/* config option for Predictor-2 */
196 #define	CILEN_PREDICTOR_2	2	/* length of its config option */
197 
198 /*
199  * Note that some systems emit requests for STAC using a length of 6.
200  * The extra octet is 00 and should be ignored.
201  */
202 #define	CI_STAC			17	/* config option for STAC LZS */
203 #define	CILEN_STAC		5	/* length of its config option */
204 
205 #define	STAC_CHK_NONE		0	/* No checking */
206 #define	STAC_CHK_LCB		1	/* Longitudinal Check Bytes */
207 #define	STAC_CHK_CRC		2	/* Cyclic Redundancy Check */
208 #define	STAC_CHK_SEQ		3	/* Sequence Number */
209 #define	STAC_CHK_EXTENDED	4	/* Extended (Microsoft) */
210 
211 #define	CI_MPPC			18	/* config option for MS-PPC */
212 #define	CILEN_MPPC		6	/* length of its config option */
213 
214 #define	MPPC_COMP		0x00000001	/* Compression */
215 #define	MPPC_40LANM		0x00000010	/* MPPE, 40 bit LANManager */
216 #define	MPPC_40NT		0x00000020	/* MPPE, 40 bit NT key */
217 #define	MPPC_128NT		0x00000040	/* MPPE, 128 bit NT key */
218 #define	MPPC_56NT		0x00000080	/* MPPE, 56 bit NT key */
219 #define	MPPC_PBP		0x01000000	/* Packet-by-Packet mode */
220 #define	MPPC_MPPE		0x000000F0
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif /* _NET_PPP_COMP_H */
227