xref: /illumos-gate/usr/src/uts/common/net/ppp-comp.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
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 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * The following symbols control whether we include code for
42  * various compression methods.
43  */
44 #ifndef DO_BSD_COMPRESS
45 #define	DO_BSD_COMPRESS	1	/* by default, include BSD-Compress */
46 #endif
47 #ifndef DO_DEFLATE
48 #define	DO_DEFLATE	1	/* by default, include Deflate */
49 #endif
50 #define	DO_PREDICTOR_1	0
51 #define	DO_PREDICTOR_2	0
52 
53 /*
54  * Structure giving methods for compression/decompression.
55  */
56 #ifdef PACKETPTR
57 struct compressor {
58 	int	compress_proto;	/* CCP compression protocol number */
59 
60 	/* Allocate space for a compressor (transmit side) */
61 	void	*(*comp_alloc) __P((uchar_t *options, int opt_len));
62 	/* Free space used by a compressor */
63 	void	(*comp_free) __P((void *state));
64 	/* Initialize a compressor */
65 	int	(*comp_init) __P((void *state, uchar_t *options, int opt_len,
66 	    int unit, int hdrlen, int debug));
67 	/* Reset a compressor */
68 	void	(*comp_reset) __P((void *state));
69 	/* Compress a packet */
70 	int	(*compress) __P((void *state, PACKETPTR *mret,
71 	    PACKETPTR mp, int orig_len, int max_len));
72 	/* Return compression statistics */
73 	void	(*comp_stat) __P((void *state, struct compstat *stats));
74 
75 	/* Allocate space for a decompressor (receive side) */
76 	void	*(*decomp_alloc) __P((uchar_t *options, int opt_len));
77 	/* Free space used by a decompressor */
78 	void	(*decomp_free) __P((void *state));
79 	/* Initialize a decompressor */
80 	int	(*decomp_init) __P((void *state, uchar_t *options, int opt_len,
81 				    int unit, int hdrlen, int mru, int debug));
82 	/* Reset a decompressor */
83 	void	(*decomp_reset) __P((void *state));
84 	/* Decompress a packet. */
85 	int	(*decompress) __P((void *state, PACKETPTR *mp));
86 	/* Update state for an incompressible packet received */
87 	int	(*incomp) __P((void *state, PACKETPTR mp));
88 	/* Return decompression statistics */
89 	void	(*decomp_stat) __P((void *state, struct compstat *stats));
90 
91 	/* Set or change compression effort level */
92 	int	(*set_effort) __P((void *xstate, void *rstate,
93 	    int effortlevel));
94 };
95 #endif /* PACKETPTR */
96 
97 /*
98  * Return values for decompress routine.
99  * We need to make these distinctions so that we can disable certain
100  * useful functionality, namely sending a CCP reset-request as a result
101  * of an error detected after decompression.  This is to avoid infringing
102  * a patent held by Motorola.
103  * Don't you just lurve software patents.
104  */
105 #define	DECOMP_OK		0	/* everything went OK */
106 #define	DECOMP_ERROR		1	/* error detected before decomp. */
107 #define	DECOMP_FATALERROR	2	/* error detected after decomp. */
108 
109 /*
110  * CCP codes.
111  */
112 #define	CCP_CONFREQ	1
113 #define	CCP_CONFACK	2
114 #define	CCP_TERMREQ	5
115 #define	CCP_TERMACK	6
116 #define	CCP_RESETREQ	14
117 #define	CCP_RESETACK	15
118 
119 /*
120  * Max # bytes for a CCP option
121  */
122 #define	CCP_MAX_OPTION_LENGTH	32
123 
124 /*
125  * Parts of a CCP packet.
126  */
127 #define	CCP_CODE(dp)		((dp)[0])
128 #define	CCP_ID(dp)		((dp)[1])
129 #define	CCP_LENGTH(dp)		(((dp)[2] << 8) + (dp)[3])
130 #define	CCP_HDRLEN		4
131 
132 #define	CCP_OPT_CODE(dp)	((dp)[0])
133 #define	CCP_OPT_LENGTH(dp)	((dp)[1])
134 #define	CCP_OPT_MINLEN		2
135 
136 /*
137  * Definitions for BSD-Compress.
138  */
139 #define	CI_BSD_COMPRESS		21	/* config. option for BSD-Compress */
140 #define	CILEN_BSD_COMPRESS	3	/* length of config. option */
141 
142 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
143 #define	BSD_NBITS(x)		((x) & 0x1F)	/* number of bits requested */
144 #define	BSD_VERSION(x)		((x) >> 5)	/* version of option format */
145 #define	BSD_CURRENT_VERSION	1		/* current version number */
146 #define	BSD_MAKE_OPT(v, n)	(((v) << 5) | (n))
147 
148 #define	BSD_MIN_BITS		9	/* smallest code size supported */
149 #define	BSD_MAX_BITS		15	/* largest code size supported */
150 
151 /*
152  * Definitions for Deflate.
153  */
154 #define	CI_DEFLATE		26	/* config option for Deflate */
155 #define	CI_DEFLATE_DRAFT	24	/* value used in original draft RFC */
156 #define	CILEN_DEFLATE		4	/* length of its config option */
157 
158 #define	DEFLATE_MIN_SIZE	8
159 #define	DEFLATE_MAX_SIZE	15
160 #define	DEFLATE_METHOD_VAL	8
161 #define	DEFLATE_SIZE(x)		(((x) >> 4) + DEFLATE_MIN_SIZE)
162 #define	DEFLATE_METHOD(x)	((x) & 0x0F)
163 #define	DEFLATE_MAKE_OPT(w)	((((w) - DEFLATE_MIN_SIZE) << 4) \
164 				    + DEFLATE_METHOD_VAL)
165 #define	DEFLATE_CHK_SEQUENCE	0
166 
167 /*
168  * Definitions for other, as yet unsupported, compression methods.
169  */
170 #define	CI_PREDICTOR_1		1	/* config option for Predictor-1 */
171 #define	CILEN_PREDICTOR_1	2	/* length of its config option */
172 #define	CI_PREDICTOR_2		2	/* config option for Predictor-2 */
173 #define	CILEN_PREDICTOR_2	2	/* length of its config option */
174 
175 /*
176  * Note that some systems emit requests for STAC using a length of 6.
177  * The extra octet is 00 and should be ignored.
178  */
179 #define	CI_STAC			17	/* config option for STAC LZS */
180 #define	CILEN_STAC		5	/* length of its config option */
181 
182 #define	STAC_CHK_NONE		0	/* No checking */
183 #define	STAC_CHK_LCB		1	/* Longitudinal Check Bytes */
184 #define	STAC_CHK_CRC		2	/* Cyclic Redundancy Check */
185 #define	STAC_CHK_SEQ		3	/* Sequence Number */
186 #define	STAC_CHK_EXTENDED	4	/* Extended (Microsoft) */
187 
188 #define	CI_MPPC			18	/* config option for MS-PPC */
189 #define	CILEN_MPPC		6	/* length of its config option */
190 
191 #define	MPPC_COMP		0x00000001	/* Compression */
192 #define	MPPC_40LANM		0x00000010	/* MPPE, 40 bit LANManager */
193 #define	MPPC_40NT		0x00000020	/* MPPE, 40 bit NT key */
194 #define	MPPC_128NT		0x00000040	/* MPPE, 128 bit NT key */
195 #define	MPPC_56NT		0x00000080	/* MPPE, 56 bit NT key */
196 #define	MPPC_PBP		0x01000000	/* Packet-by-Packet mode */
197 #define	MPPC_MPPE		0x000000F0
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif /* _NET_PPP_COMP_H */
204