]> git.ozlabs.org Git - ppp.git/blob - include/linux/ppp-comp.h
ECP patches from Frank Cusack:
[ppp.git] / include / linux / ppp-comp.h
1 /*
2  * ppp-comp.h - Definitions for doing PPP packet compression.
3  *
4  * Copyright (c) 1994 The Australian National University.
5  * All rights reserved.
6  *
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
12  * any purpose.
13  *
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
18  * OF SUCH DAMAGE.
19  *
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,
25  * OR MODIFICATIONS.
26  *
27  * $Id: ppp-comp.h,v 1.9 2002/04/02 13:54:59 dfs Exp $
28  */
29
30 /*
31  *  ==FILEVERSION 20020319==
32  *
33  *  NOTE TO MAINTAINERS:
34  *     If you modify this file at all, please set the above date.
35  *     ppp-comp.h is shipped with a PPP distribution as well as with the kernel;
36  *     if everyone increases the FILEVERSION number above, then scripts
37  *     can do the right thing when deciding whether to install a new ppp-comp.h
38  *     file.  Don't change the format of that line otherwise, so the
39  *     installation script can recognize it.
40  */
41
42 #ifndef _NET_PPP_COMP_H
43 #define _NET_PPP_COMP_H
44
45 /*
46  * The following symbols control whether we include code for
47  * various compression methods.
48  */
49
50 #ifndef DO_BSD_COMPRESS
51 #define DO_BSD_COMPRESS 1       /* by default, include BSD-Compress */
52 #endif
53 #ifndef DO_DEFLATE
54 #define DO_DEFLATE      1       /* by default, include Deflate */
55 #endif
56 #define DO_PREDICTOR_1  0
57 #define DO_PREDICTOR_2  0
58
59 /*
60  * Structure giving methods for compression/decompression.
61  */
62
63 struct compressor {
64         int     compress_proto; /* CCP compression protocol number */
65
66         /* Allocate space for a compressor (transmit side) */
67         void    *(*comp_alloc) (unsigned char *options, int opt_len);
68
69         /* Free space used by a compressor */
70         void    (*comp_free) (void *state);
71
72         /* Initialize a compressor */
73         int     (*comp_init) (void *state, unsigned char *options,
74                               int opt_len, int unit, int opthdr, int debug);
75
76         /* Reset a compressor */
77         void    (*comp_reset) (void *state);
78
79         /* Compress a packet */
80         int     (*compress) (void *state, unsigned char *rptr,
81                               unsigned char *obuf, int isize, int osize);
82
83         /* Return compression statistics */
84         void    (*comp_stat) (void *state, struct compstat *stats);
85
86         /* Allocate space for a decompressor (receive side) */
87         void    *(*decomp_alloc) (unsigned char *options, int opt_len);
88
89         /* Free space used by a decompressor */
90         void    (*decomp_free) (void *state);
91
92         /* Initialize a decompressor */
93         int     (*decomp_init) (void *state, unsigned char *options,
94                                 int opt_len, int unit, int opthdr, int mru,
95                                 int debug);
96
97         /* Reset a decompressor */
98         void    (*decomp_reset) (void *state);
99
100         /* Decompress a packet. */
101         int     (*decompress) (void *state, unsigned char *ibuf, int isize,
102                                 unsigned char *obuf, int osize);
103
104         /* Update state for an incompressible packet received */
105         void    (*incomp) (void *state, unsigned char *ibuf, int icnt);
106
107         /* Return decompression statistics */
108         void    (*decomp_stat) (void *state, struct compstat *stats);
109 };
110
111 /*
112  * The return value from decompress routine is the length of the
113  * decompressed packet if successful, otherwise DECOMP_ERROR
114  * or DECOMP_FATALERROR if an error occurred.
115  * 
116  * We need to make this distinction so that we can disable certain
117  * useful functionality, namely sending a CCP reset-request as a result
118  * of an error detected after decompression.  This is to avoid infringing
119  * a patent held by Motorola.
120  * Don't you just lurve software patents.
121  */
122
123 #define DECOMP_ERROR            -1      /* error detected before decomp. */
124 #define DECOMP_FATALERROR       -2      /* error detected after decomp. */
125
126 /*
127  * CCP codes.
128  */
129
130 #define CCP_CONFREQ     1
131 #define CCP_CONFACK     2
132 #define CCP_TERMREQ     5
133 #define CCP_TERMACK     6
134 #define CCP_RESETREQ    14
135 #define CCP_RESETACK    15
136
137 /*
138  * Max # bytes for a CCP option
139  */
140
141 #define CCP_MAX_OPTION_LENGTH   32
142
143 /*
144  * Parts of a CCP packet.
145  */
146
147 #define CCP_CODE(dp)            ((dp)[0])
148 #define CCP_ID(dp)              ((dp)[1])
149 #define CCP_LENGTH(dp)          (((dp)[2] << 8) + (dp)[3])
150 #define CCP_HDRLEN              4
151
152 #define CCP_OPT_CODE(dp)        ((dp)[0])
153 #define CCP_OPT_LENGTH(dp)      ((dp)[1])
154 #define CCP_OPT_MINLEN          2
155
156 /*
157  * Definitions for BSD-Compress.
158  */
159
160 #define CI_BSD_COMPRESS         21      /* config. option for BSD-Compress */
161 #define CILEN_BSD_COMPRESS      3       /* length of config. option */
162
163 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
164 #define BSD_NBITS(x)            ((x) & 0x1F)    /* number of bits requested */
165 #define BSD_VERSION(x)          ((x) >> 5)      /* version of option format */
166 #define BSD_CURRENT_VERSION     1               /* current version number */
167 #define BSD_MAKE_OPT(v, n)      (((v) << 5) | (n))
168
169 #define BSD_MIN_BITS            9       /* smallest code size supported */
170 #define BSD_MAX_BITS            15      /* largest code size supported */
171
172 /*
173  * Definitions for Deflate.
174  */
175
176 #define CI_DEFLATE              26      /* config option for Deflate */
177 #define CI_DEFLATE_DRAFT        24      /* value used in original draft RFC */
178 #define CILEN_DEFLATE           4       /* length of its config option */
179
180 #define DEFLATE_MIN_SIZE        8
181 #define DEFLATE_MAX_SIZE        15
182 #define DEFLATE_METHOD_VAL      8
183 #define DEFLATE_SIZE(x)         (((x) >> 4) + DEFLATE_MIN_SIZE)
184 #define DEFLATE_METHOD(x)       ((x) & 0x0F)
185 #define DEFLATE_MAKE_OPT(w)     ((((w) - DEFLATE_MIN_SIZE) << 4) \
186                                  + DEFLATE_METHOD_VAL)
187 #define DEFLATE_CHK_SEQUENCE    0
188
189 /*
190  * Definitions for MPPE.
191  */
192
193 #define CI_MPPE                 18      /* config option for MPPE */
194 #define CILEN_MPPE              6       /* length of config option */
195
196 #define MPPE_PAD                4       /* MPPE growth per frame */
197 #define MPPE_MAX_KEY_LEN        16      /* largest key length (128-bit) */
198
199 /* option bits for ccp_options.mppe */
200 #define MPPE_OPT_40             0x01    /* 40 bit */
201 #define MPPE_OPT_128            0x02    /* 128 bit */
202 #define MPPE_OPT_STATEFUL       0x04    /* stateful mode */
203 /* unsupported opts */
204 #define MPPE_OPT_56             0x08    /* 56 bit */
205 #define MPPE_OPT_MPPC           0x10    /* MPPC compression */
206 #define MPPE_OPT_D              0x20    /* Unknown */
207 #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
208 #define MPPE_OPT_UNKNOWN        0x40    /* Bits !defined in RFC 3078 were set */
209
210 /*
211  * This is not nice ... the alternative is a bitfield struct though.
212  * And unfortunately, we cannot share the same bits for the option
213  * names above since C and H are the same bit.  We could do a u_int32
214  * but then we have to do a htonl() all the time and/or we still need
215  * to know which octet is which.
216  */
217 #define MPPE_C_BIT              0x01    /* MPPC */
218 #define MPPE_D_BIT              0x10    /* Obsolete, usage unknown */
219 #define MPPE_L_BIT              0x20    /* 40-bit */
220 #define MPPE_S_BIT              0x40    /* 128-bit */
221 #define MPPE_M_BIT              0x80    /* 56-bit, not supported */
222 #define MPPE_H_BIT              0x01    /* Stateless (in a different byte) */
223
224 /* Does not include H bit; used for least significant octet only. */
225 #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
226
227 /* Build a CI from mppe opts (see RFC 3078) */
228 #define MPPE_OPTS_TO_CI(opts, ci)               \
229     do {                                        \
230         u_char *ptr = ci; /* u_char[4] */       \
231                                                 \
232         /* H bit */                             \
233         if (opts & MPPE_OPT_STATEFUL)           \
234             *ptr++ = 0x0;                       \
235         else                                    \
236             *ptr++ = MPPE_H_BIT;                \
237         *ptr++ = 0;                             \
238         *ptr++ = 0;                             \
239                                                 \
240         /* S,L bits */                          \
241         *ptr = 0;                               \
242         if (opts & MPPE_OPT_128)                \
243             *ptr |= MPPE_S_BIT;                 \
244         if (opts & MPPE_OPT_40)                 \
245             *ptr |= MPPE_L_BIT;                 \
246         /* M,D,C bits not supported */          \
247     } while (/* CONSTCOND */ 0)
248
249 /* The reverse of the above */
250 #define MPPE_CI_TO_OPTS(ci, opts)               \
251     do {                                        \
252         u_char *ptr = ci; /* u_char[4] */       \
253                                                 \
254         opts = 0;                               \
255                                                 \
256         /* H bit */                             \
257         if (!(ptr[0] & MPPE_H_BIT))             \
258             opts |= MPPE_OPT_STATEFUL;          \
259                                                 \
260         /* S,L bits */                          \
261         if (ptr[3] & MPPE_S_BIT)                \
262             opts |= MPPE_OPT_128;               \
263         if (ptr[3] & MPPE_L_BIT)                \
264             opts |= MPPE_OPT_40;                \
265                                                 \
266         /* M,D,C bits */                        \
267         if (ptr[3] & MPPE_M_BIT)                \
268             opts |= MPPE_OPT_56;                \
269         if (ptr[3] & MPPE_D_BIT)                \
270             opts |= MPPE_OPT_D;                 \
271         if (ptr[3] & MPPE_C_BIT)                \
272             opts |= MPPE_OPT_MPPC;              \
273                                                 \
274         /* Other bits */                        \
275         if (ptr[0] & ~MPPE_H_BIT)               \
276             opts |= MPPE_OPT_UNKNOWN;           \
277         if (ptr[1] || ptr[2])                   \
278             opts |= MPPE_OPT_UNKNOWN;           \
279         if (ptr[3] & ~MPPE_ALL_BITS)            \
280             opts |= MPPE_OPT_UNKNOWN;           \
281     } while (/* CONSTCOND */ 0)
282
283 /*
284  * Definitions for other, as yet unsupported, compression methods.
285  */
286
287 #define CI_PREDICTOR_1          1       /* config option for Predictor-1 */
288 #define CILEN_PREDICTOR_1       2       /* length of its config option */
289 #define CI_PREDICTOR_2          2       /* config option for Predictor-2 */
290 #define CILEN_PREDICTOR_2       2       /* length of its config option */
291
292 #ifdef __KERNEL__
293 extern int ppp_register_compressor(struct compressor *);
294 extern void ppp_unregister_compressor(struct compressor *);
295 #endif /* __KERNEL__ */
296
297 #endif /* _NET_PPP_COMP_H */