]> git.ozlabs.org Git - ppp.git/blob - include/linux/ppp-comp.h
Update README and patchlevel for 2.4.7 release
[ppp.git] / include / linux / ppp-comp.h
1 /*
2  * ppp-comp.h - Definitions for doing PPP packet compression.
3  *
4  * Copyright (c) 1984 Paul Mackerras. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
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
16  *    distribution.
17  *
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.
21  *
22  * 4. Redistributions of any form whatsoever must retain the following
23  *    acknowledgment:
24  *    "This product includes software developed by Paul Mackerras
25  *     <paulus@samba.org>".
26  *
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.
34  *
35  * $Id: ppp-comp.h,v 1.10 2002/12/06 09:49:15 paulus Exp $
36  */
37
38 /*
39  *  ==FILEVERSION 20020319==
40  *
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.
48  */
49
50 #ifndef _NET_PPP_COMP_H
51 #define _NET_PPP_COMP_H
52
53 /*
54  * The following symbols control whether we include code for
55  * various compression methods.
56  */
57
58 #ifndef DO_BSD_COMPRESS
59 #define DO_BSD_COMPRESS 1       /* by default, include BSD-Compress */
60 #endif
61 #ifndef DO_DEFLATE
62 #define DO_DEFLATE      1       /* by default, include Deflate */
63 #endif
64 #define DO_PREDICTOR_1  0
65 #define DO_PREDICTOR_2  0
66
67 /*
68  * Structure giving methods for compression/decompression.
69  */
70
71 struct compressor {
72         int     compress_proto; /* CCP compression protocol number */
73
74         /* Allocate space for a compressor (transmit side) */
75         void    *(*comp_alloc) (unsigned char *options, int opt_len);
76
77         /* Free space used by a compressor */
78         void    (*comp_free) (void *state);
79
80         /* Initialize a compressor */
81         int     (*comp_init) (void *state, unsigned char *options,
82                               int opt_len, int unit, int opthdr, int debug);
83
84         /* Reset a compressor */
85         void    (*comp_reset) (void *state);
86
87         /* Compress a packet */
88         int     (*compress) (void *state, unsigned char *rptr,
89                               unsigned char *obuf, int isize, int osize);
90
91         /* Return compression statistics */
92         void    (*comp_stat) (void *state, struct compstat *stats);
93
94         /* Allocate space for a decompressor (receive side) */
95         void    *(*decomp_alloc) (unsigned char *options, int opt_len);
96
97         /* Free space used by a decompressor */
98         void    (*decomp_free) (void *state);
99
100         /* Initialize a decompressor */
101         int     (*decomp_init) (void *state, unsigned char *options,
102                                 int opt_len, int unit, int opthdr, int mru,
103                                 int debug);
104
105         /* Reset a decompressor */
106         void    (*decomp_reset) (void *state);
107
108         /* Decompress a packet. */
109         int     (*decompress) (void *state, unsigned char *ibuf, int isize,
110                                 unsigned char *obuf, int osize);
111
112         /* Update state for an incompressible packet received */
113         void    (*incomp) (void *state, unsigned char *ibuf, int icnt);
114
115         /* Return decompression statistics */
116         void    (*decomp_stat) (void *state, struct compstat *stats);
117 };
118
119 /*
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.
123  * 
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.
129  */
130
131 #define DECOMP_ERROR            -1      /* error detected before decomp. */
132 #define DECOMP_FATALERROR       -2      /* error detected after decomp. */
133
134 /*
135  * CCP codes.
136  */
137
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
144
145 /*
146  * Max # bytes for a CCP option
147  */
148
149 #define CCP_MAX_OPTION_LENGTH   32
150
151 /*
152  * Parts of a CCP packet.
153  */
154
155 #define CCP_CODE(dp)            ((dp)[0])
156 #define CCP_ID(dp)              ((dp)[1])
157 #define CCP_LENGTH(dp)          (((dp)[2] << 8) + (dp)[3])
158 #define CCP_HDRLEN              4
159
160 #define CCP_OPT_CODE(dp)        ((dp)[0])
161 #define CCP_OPT_LENGTH(dp)      ((dp)[1])
162 #define CCP_OPT_MINLEN          2
163
164 /*
165  * Definitions for BSD-Compress.
166  */
167
168 #define CI_BSD_COMPRESS         21      /* config. option for BSD-Compress */
169 #define CILEN_BSD_COMPRESS      3       /* length of config. option */
170
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))
176
177 #define BSD_MIN_BITS            9       /* smallest code size supported */
178 #define BSD_MAX_BITS            15      /* largest code size supported */
179
180 /*
181  * Definitions for Deflate.
182  */
183
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 */
187
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
196
197 /*
198  * Definitions for MPPE.
199  */
200
201 #define CI_MPPE                 18      /* config option for MPPE */
202 #define CILEN_MPPE              6       /* length of config option */
203
204 /*
205  * Definitions for other, as yet unsupported, compression methods.
206  */
207
208 #define CI_PREDICTOR_1          1       /* config option for Predictor-1 */
209 #define CILEN_PREDICTOR_1       2       /* length of its config option */
210 #define CI_PREDICTOR_2          2       /* config option for Predictor-2 */
211 #define CILEN_PREDICTOR_2       2       /* length of its config option */
212
213 #endif /* _NET_PPP_COMP_H */