2 * ppp-comp.h - Definitions for doing PPP packet compression.
4 * Copyright (c) 1994 The Australian National University.
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation is hereby granted, provided that the above copyright
9 * notice appears in all copies. This software is provided without any
10 * warranty, express or implied. The Australian National University
11 * makes no representations about the suitability of this software for
14 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
15 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
17 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
20 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
21 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
24 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
27 * $Id: ppp-comp.h,v 1.12 2002/04/02 13:54:59 dfs Exp $
30 #ifndef _NET_PPP_COMP_H
31 #define _NET_PPP_COMP_H
34 * The following symbols control whether we include code for
35 * various compression methods.
37 #ifndef DO_BSD_COMPRESS
38 #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
41 #define DO_DEFLATE 1 /* by default, include Deflate */
43 #define DO_PREDICTOR_1 0
44 #define DO_PREDICTOR_2 0
47 * Structure giving methods for compression/decompression.
51 int compress_proto; /* CCP compression protocol number */
53 /* Allocate space for a compressor (transmit side) */
54 void *(*comp_alloc) __P((u_char *options, int opt_len));
55 /* Free space used by a compressor */
56 void (*comp_free) __P((void *state));
57 /* Initialize a compressor */
58 int (*comp_init) __P((void *state, u_char *options, int opt_len,
59 int unit, int hdrlen, int debug));
60 /* Reset a compressor */
61 void (*comp_reset) __P((void *state));
62 /* Compress a packet */
63 int (*compress) __P((void *state, PACKETPTR *mret,
64 PACKETPTR mp, int orig_len, int max_len));
65 /* Return compression statistics */
66 void (*comp_stat) __P((void *state, struct compstat *stats));
68 /* Allocate space for a decompressor (receive side) */
69 void *(*decomp_alloc) __P((u_char *options, int opt_len));
70 /* Free space used by a decompressor */
71 void (*decomp_free) __P((void *state));
72 /* Initialize a decompressor */
73 int (*decomp_init) __P((void *state, u_char *options, int opt_len,
74 int unit, int hdrlen, int mru, int debug));
75 /* Reset a decompressor */
76 void (*decomp_reset) __P((void *state));
77 /* Decompress a packet. */
78 int (*decompress) __P((void *state, PACKETPTR mp,
80 /* Update state for an incompressible packet received */
81 void (*incomp) __P((void *state, PACKETPTR mp));
82 /* Return decompression statistics */
83 void (*decomp_stat) __P((void *state, struct compstat *stats));
85 #endif /* PACKETPTR */
88 * Return values for decompress routine.
89 * We need to make these distinctions so that we can disable certain
90 * useful functionality, namely sending a CCP reset-request as a result
91 * of an error detected after decompression. This is to avoid infringing
92 * a patent held by Motorola.
93 * Don't you just lurve software patents.
95 #define DECOMP_OK 0 /* everything went OK */
96 #define DECOMP_ERROR 1 /* error detected before decomp. */
97 #define DECOMP_FATALERROR 2 /* error detected after decomp. */
102 #define CCP_CONFREQ 1
103 #define CCP_CONFACK 2
104 #define CCP_TERMREQ 5
105 #define CCP_TERMACK 6
106 #define CCP_RESETREQ 14
107 #define CCP_RESETACK 15
110 * Max # bytes for a CCP option
112 #define CCP_MAX_OPTION_LENGTH 32
115 * Parts of a CCP packet.
117 #define CCP_CODE(dp) ((dp)[0])
118 #define CCP_ID(dp) ((dp)[1])
119 #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
122 #define CCP_OPT_CODE(dp) ((dp)[0])
123 #define CCP_OPT_LENGTH(dp) ((dp)[1])
124 #define CCP_OPT_MINLEN 2
127 * Definitions for BSD-Compress.
129 #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
130 #define CILEN_BSD_COMPRESS 3 /* length of config. option */
132 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
133 #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
134 #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
135 #define BSD_CURRENT_VERSION 1 /* current version number */
136 #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
138 #define BSD_MIN_BITS 9 /* smallest code size supported */
139 #define BSD_MAX_BITS 15 /* largest code size supported */
142 * Definitions for Deflate.
144 #define CI_DEFLATE 26 /* config option for Deflate */
145 #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
146 #define CILEN_DEFLATE 4 /* length of its config option */
148 #define DEFLATE_MIN_SIZE 8
149 #define DEFLATE_MAX_SIZE 15
150 #define DEFLATE_METHOD_VAL 8
151 #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
152 #define DEFLATE_METHOD(x) ((x) & 0x0F)
153 #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
154 + DEFLATE_METHOD_VAL)
155 #define DEFLATE_CHK_SEQUENCE 0
158 * Definitions for MPPE.
160 #define CI_MPPE 18 /* config option for MPPE */
161 #define CILEN_MPPE 6 /* length of config option */
163 #define MPPE_PAD 4 /* MPPE growth per frame */
164 #define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */
166 /* option bits for ccp_options.mppe */
167 #define MPPE_OPT_40 0x01 /* 40 bit */
168 #define MPPE_OPT_128 0x02 /* 128 bit */
169 #define MPPE_OPT_STATEFUL 0x04 /* stateful mode */
170 /* unsupported opts */
171 #define MPPE_OPT_56 0x08 /* 56 bit */
172 #define MPPE_OPT_MPPC 0x10 /* MPPC compression */
173 #define MPPE_OPT_D 0x20 /* Unknown */
174 #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
175 #define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */
178 * This is not nice ... the alternative is a bitfield struct though.
179 * And unfortunately, we cannot share the same bits for the option
180 * names above since C and H are the same bit. We could do a u_int32
181 * but then we have to do a htonl() all the time and/or we still need
182 * to know which octet is which.
184 #define MPPE_C_BIT 0x01 /* MPPC */
185 #define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */
186 #define MPPE_L_BIT 0x20 /* 40-bit */
187 #define MPPE_S_BIT 0x40 /* 128-bit */
188 #define MPPE_M_BIT 0x80 /* 56-bit, not supported */
189 #define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */
191 /* Does not include H bit; used for least significant octet only. */
192 #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
194 /* Build a CI from mppe opts (see RFC 3078) */
195 #define MPPE_OPTS_TO_CI(opts, ci) \
197 u_char *ptr = ci; /* u_char[4] */ \
200 if (opts & MPPE_OPT_STATEFUL) \
203 *ptr++ = MPPE_H_BIT; \
209 if (opts & MPPE_OPT_128) \
210 *ptr |= MPPE_S_BIT; \
211 if (opts & MPPE_OPT_40) \
212 *ptr |= MPPE_L_BIT; \
213 /* M,D,C bits not supported */ \
214 } while (/* CONSTCOND */ 0)
216 /* The reverse of the above */
217 #define MPPE_CI_TO_OPTS(ci, opts) \
219 u_char *ptr = ci; /* u_char[4] */ \
224 if (!(ptr[0] & MPPE_H_BIT)) \
225 opts |= MPPE_OPT_STATEFUL; \
228 if (ptr[3] & MPPE_S_BIT) \
229 opts |= MPPE_OPT_128; \
230 if (ptr[3] & MPPE_L_BIT) \
231 opts |= MPPE_OPT_40; \
234 if (ptr[3] & MPPE_M_BIT) \
235 opts |= MPPE_OPT_56; \
236 if (ptr[3] & MPPE_D_BIT) \
237 opts |= MPPE_OPT_D; \
238 if (ptr[3] & MPPE_C_BIT) \
239 opts |= MPPE_OPT_MPPC; \
242 if (ptr[0] & ~MPPE_H_BIT) \
243 opts |= MPPE_OPT_UNKNOWN; \
244 if (ptr[1] || ptr[2]) \
245 opts |= MPPE_OPT_UNKNOWN; \
246 if (ptr[3] & ~MPPE_ALL_BITS) \
247 opts |= MPPE_OPT_UNKNOWN; \
248 } while (/* CONSTCOND */ 0)
251 * Definitions for other, as yet unsupported, compression methods.
253 #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
254 #define CILEN_PREDICTOR_1 2 /* length of its config option */
255 #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
256 #define CILEN_PREDICTOR_2 2 /* length of its config option */
258 #endif /* _NET_PPP_COMP_H */