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