2 * ppp-comp.h - Definitions for doing PPP packet compression.
4 * Copyright (c) 1984 Paul Mackerras. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * 3. The name(s) of the authors of this software must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission.
22 * 4. Redistributions of any form whatsoever must retain the following
24 * "This product includes software developed by Paul Mackerras
25 * <paulus@samba.org>".
27 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
28 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
33 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
35 * $Id: ppp-comp.h,v 1.10 2002/12/06 09:49:15 paulus Exp $
39 * ==FILEVERSION 20020319==
41 * NOTE TO MAINTAINERS:
42 * If you modify this file at all, please set the above date.
43 * ppp-comp.h is shipped with a PPP distribution as well as with the kernel;
44 * if everyone increases the FILEVERSION number above, then scripts
45 * can do the right thing when deciding whether to install a new ppp-comp.h
46 * file. Don't change the format of that line otherwise, so the
47 * installation script can recognize it.
50 #ifndef _NET_PPP_COMP_H
51 #define _NET_PPP_COMP_H
54 * The following symbols control whether we include code for
55 * various compression methods.
58 #ifndef DO_BSD_COMPRESS
59 #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
62 #define DO_DEFLATE 1 /* by default, include Deflate */
64 #define DO_PREDICTOR_1 0
65 #define DO_PREDICTOR_2 0
68 * Structure giving methods for compression/decompression.
72 int compress_proto; /* CCP compression protocol number */
74 /* Allocate space for a compressor (transmit side) */
75 void *(*comp_alloc) (unsigned char *options, int opt_len);
77 /* Free space used by a compressor */
78 void (*comp_free) (void *state);
80 /* Initialize a compressor */
81 int (*comp_init) (void *state, unsigned char *options,
82 int opt_len, int unit, int opthdr, int debug);
84 /* Reset a compressor */
85 void (*comp_reset) (void *state);
87 /* Compress a packet */
88 int (*compress) (void *state, unsigned char *rptr,
89 unsigned char *obuf, int isize, int osize);
91 /* Return compression statistics */
92 void (*comp_stat) (void *state, struct compstat *stats);
94 /* Allocate space for a decompressor (receive side) */
95 void *(*decomp_alloc) (unsigned char *options, int opt_len);
97 /* Free space used by a decompressor */
98 void (*decomp_free) (void *state);
100 /* Initialize a decompressor */
101 int (*decomp_init) (void *state, unsigned char *options,
102 int opt_len, int unit, int opthdr, int mru,
105 /* Reset a decompressor */
106 void (*decomp_reset) (void *state);
108 /* Decompress a packet. */
109 int (*decompress) (void *state, unsigned char *ibuf, int isize,
110 unsigned char *obuf, int osize);
112 /* Update state for an incompressible packet received */
113 void (*incomp) (void *state, unsigned char *ibuf, int icnt);
115 /* Return decompression statistics */
116 void (*decomp_stat) (void *state, struct compstat *stats);
120 * The return value from decompress routine is the length of the
121 * decompressed packet if successful, otherwise DECOMP_ERROR
122 * or DECOMP_FATALERROR if an error occurred.
124 * We need to make this distinction so that we can disable certain
125 * useful functionality, namely sending a CCP reset-request as a result
126 * of an error detected after decompression. This is to avoid infringing
127 * a patent held by Motorola.
128 * Don't you just lurve software patents.
131 #define DECOMP_ERROR -1 /* error detected before decomp. */
132 #define DECOMP_FATALERROR -2 /* error detected after decomp. */
138 #define CCP_CONFREQ 1
139 #define CCP_CONFACK 2
140 #define CCP_TERMREQ 5
141 #define CCP_TERMACK 6
142 #define CCP_RESETREQ 14
143 #define CCP_RESETACK 15
146 * Max # bytes for a CCP option
149 #define CCP_MAX_OPTION_LENGTH 32
152 * Parts of a CCP packet.
155 #define CCP_CODE(dp) ((dp)[0])
156 #define CCP_ID(dp) ((dp)[1])
157 #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
160 #define CCP_OPT_CODE(dp) ((dp)[0])
161 #define CCP_OPT_LENGTH(dp) ((dp)[1])
162 #define CCP_OPT_MINLEN 2
165 * Definitions for BSD-Compress.
168 #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
169 #define CILEN_BSD_COMPRESS 3 /* length of config. option */
171 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
172 #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
173 #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
174 #define BSD_CURRENT_VERSION 1 /* current version number */
175 #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
177 #define BSD_MIN_BITS 9 /* smallest code size supported */
178 #define BSD_MAX_BITS 15 /* largest code size supported */
181 * Definitions for Deflate.
184 #define CI_DEFLATE 26 /* config option for Deflate */
185 #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
186 #define CILEN_DEFLATE 4 /* length of its config option */
188 #define DEFLATE_MIN_SIZE 8
189 #define DEFLATE_MAX_SIZE 15
190 #define DEFLATE_METHOD_VAL 8
191 #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
192 #define DEFLATE_METHOD(x) ((x) & 0x0F)
193 #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
194 + DEFLATE_METHOD_VAL)
195 #define DEFLATE_CHK_SEQUENCE 0
198 * Definitions for MPPE.
201 #define CI_MPPE 18 /* config option for MPPE */
202 #define CILEN_MPPE 6 /* length of config option */
204 #define MPPE_PAD 4 /* MPPE growth per frame */
205 #define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */
207 /* option bits for ccp_options.mppe */
208 #define MPPE_OPT_40 0x01 /* 40 bit */
209 #define MPPE_OPT_128 0x02 /* 128 bit */
210 #define MPPE_OPT_STATEFUL 0x04 /* stateful mode */
211 /* unsupported opts */
212 #define MPPE_OPT_56 0x08 /* 56 bit */
213 #define MPPE_OPT_MPPC 0x10 /* MPPC compression */
214 #define MPPE_OPT_D 0x20 /* Unknown */
215 #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
216 #define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */
219 * This is not nice ... the alternative is a bitfield struct though.
220 * And unfortunately, we cannot share the same bits for the option
221 * names above since C and H are the same bit. We could do a u_int32
222 * but then we have to do a htonl() all the time and/or we still need
223 * to know which octet is which.
225 #define MPPE_C_BIT 0x01 /* MPPC */
226 #define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */
227 #define MPPE_L_BIT 0x20 /* 40-bit */
228 #define MPPE_S_BIT 0x40 /* 128-bit */
229 #define MPPE_M_BIT 0x80 /* 56-bit, not supported */
230 #define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */
232 /* Does not include H bit; used for least significant octet only. */
233 #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
235 /* Build a CI from mppe opts (see RFC 3078) */
236 #define MPPE_OPTS_TO_CI(opts, ci) \
238 u_char *ptr = ci; /* u_char[4] */ \
241 if (opts & MPPE_OPT_STATEFUL) \
244 *ptr++ = MPPE_H_BIT; \
250 if (opts & MPPE_OPT_128) \
251 *ptr |= MPPE_S_BIT; \
252 if (opts & MPPE_OPT_40) \
253 *ptr |= MPPE_L_BIT; \
254 /* M,D,C bits not supported */ \
255 } while (/* CONSTCOND */ 0)
257 /* The reverse of the above */
258 #define MPPE_CI_TO_OPTS(ci, opts) \
260 u_char *ptr = ci; /* u_char[4] */ \
265 if (!(ptr[0] & MPPE_H_BIT)) \
266 opts |= MPPE_OPT_STATEFUL; \
269 if (ptr[3] & MPPE_S_BIT) \
270 opts |= MPPE_OPT_128; \
271 if (ptr[3] & MPPE_L_BIT) \
272 opts |= MPPE_OPT_40; \
275 if (ptr[3] & MPPE_M_BIT) \
276 opts |= MPPE_OPT_56; \
277 if (ptr[3] & MPPE_D_BIT) \
278 opts |= MPPE_OPT_D; \
279 if (ptr[3] & MPPE_C_BIT) \
280 opts |= MPPE_OPT_MPPC; \
283 if (ptr[0] & ~MPPE_H_BIT) \
284 opts |= MPPE_OPT_UNKNOWN; \
285 if (ptr[1] || ptr[2]) \
286 opts |= MPPE_OPT_UNKNOWN; \
287 if (ptr[3] & ~MPPE_ALL_BITS) \
288 opts |= MPPE_OPT_UNKNOWN; \
289 } while (/* CONSTCOND */ 0)
292 * Definitions for other, as yet unsupported, compression methods.
295 #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
296 #define CILEN_PREDICTOR_1 2 /* length of its config option */
297 #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
298 #define CILEN_PREDICTOR_2 2 /* length of its config option */
301 extern int ppp_register_compressor(struct compressor *);
302 extern void ppp_unregister_compressor(struct compressor *);
303 #endif /* __KERNEL__ */
305 #endif /* _NET_PPP_COMP_H */