]> git.ozlabs.org Git - ppp.git/blob - include/net/ppp-comp.h
added definitions for Deflate and Predictor
[ppp.git] / include / net / 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.8 1995/10/27 03:36:32 paulus Exp $
28  */
29
30 #ifndef _NET_PPP_COMP_H
31 #define _NET_PPP_COMP_H
32
33 /*
34  * The following symbols control whether we include code for
35  * various compression methods.
36  */
37 #ifndef DO_BSD_COMPRESS
38 #define DO_BSD_COMPRESS 1       /* by default, include BSD-Compress */
39 #endif
40 #define DO_PREDICTOR_1  0
41 #define DO_PREDICTOR_2  0
42 #define DO_DEFLATE      0
43
44 /*
45  * Structure giving methods for compression/decompression.
46  */
47 #ifdef PACKETPTR
48 struct compressor {
49         int     compress_proto; /* CCP compression protocol number */
50
51         /* Allocate space for a compressor (transmit side) */
52         void    *(*comp_alloc) __P((u_char *options, int opt_len));
53         /* Free space used by a compressor */
54         void    (*comp_free) __P((void *state));
55         /* Initialize a compressor */
56         int     (*comp_init) __P((void *state, u_char *options, int opt_len,
57                                   int unit, int hdrlen, int debug));
58         /* Reset a compressor */
59         void    (*comp_reset) __P((void *state));
60         /* Compress a packet */
61         int     (*compress) __P((void *state, PACKETPTR *mret,
62                                  PACKETPTR mp, int orig_len, int max_len));
63         /* Return compression statistics */
64         void    (*comp_stat) __P((void *state, struct compstat *stats));
65
66         /* Allocate space for a decompressor (receive side) */
67         void    *(*decomp_alloc) __P((u_char *options, int opt_len));
68         /* Free space used by a decompressor */
69         void    (*decomp_free) __P((void *state));
70         /* Initialize a decompressor */
71         int     (*decomp_init) __P((void *state, u_char *options, int opt_len,
72                                     int unit, int hdrlen, int mru, int debug));
73         /* Reset a decompressor */
74         void    (*decomp_reset) __P((void *state));
75         /* Decompress a packet. */
76         int     (*decompress) __P((void *state, PACKETPTR mp,
77                                    PACKETPTR *dmpp));
78         /* Update state for an incompressible packet received */
79         void    (*incomp) __P((void *state, PACKETPTR mp));
80         /* Return decompression statistics */
81         void    (*decomp_stat) __P((void *state, struct compstat *stats));
82 };
83 #endif /* PACKETPTR */
84
85 /*
86  * Return values for decompress routine.
87  * We need to make these distinctions so that we can disable certain
88  * useful functionality, namely sending a CCP reset-request as a result
89  * of an error detected after decompression.  This is to avoid infringing
90  * a patent held by Motorola.
91  * Don't you just lurve software patents.
92  */
93 #define DECOMP_OK               0       /* everything went OK */
94 #define DECOMP_ERROR            1       /* error detected before decomp. */
95 #define DECOMP_FATALERROR       2       /* error detected after decomp. */
96
97 /*
98  * CCP codes.
99  */
100 #define CCP_CONFREQ     1
101 #define CCP_CONFACK     2
102 #define CCP_TERMREQ     5
103 #define CCP_TERMACK     6
104 #define CCP_RESETREQ    14
105 #define CCP_RESETACK    15
106
107 /*
108  * Max # bytes for a CCP option
109  */
110 #define CCP_MAX_OPTION_LENGTH   32
111
112 /*
113  * Parts of a CCP packet.
114  */
115 #define CCP_CODE(dp)            ((dp)[0])
116 #define CCP_ID(dp)              ((dp)[1])
117 #define CCP_LENGTH(dp)          (((dp)[2] << 8) + (dp)[3])
118 #define CCP_HDRLEN              4
119
120 #define CCP_OPT_CODE(dp)        ((dp)[0])
121 #define CCP_OPT_LENGTH(dp)      ((dp)[1])
122 #define CCP_OPT_MINLEN          2
123
124 /*
125  * Definitions for BSD-Compress.
126  */
127 #define CI_BSD_COMPRESS         21      /* config. option for BSD-Compress */
128 #define CILEN_BSD_COMPRESS      3       /* length of config. option */
129
130 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
131 #define BSD_NBITS(x)            ((x) & 0x1F)    /* number of bits requested */
132 #define BSD_VERSION(x)          ((x) >> 5)      /* version of option format */
133 #define BSD_CURRENT_VERSION     1               /* current version number */
134 #define BSD_MAKE_OPT(v, n)      (((v) << 5) | (n))
135
136 #define BSD_MIN_BITS            9       /* smallest code size supported */
137 #define BSD_MAX_BITS            15      /* largest code size supported */
138
139 /*
140  * Definitions for other, as yet unsupported, compression methods.
141  */
142 #define CI_PREDICTOR_1          1       /* config option for Predictor-1 */
143 #define CILEN_PREDICTOR_1       2       /* length of its config option */
144 #define CI_PREDICTOR_2          2       /* config option for Predictor-2 */
145 #define CILEN_PREDICTOR_2       2       /* length of its config option */
146
147 #define CI_DEFLATE              24      /* config option for Deflate */
148 #define CILEN_DEFLATE           4       /* length of its config option */
149
150 #define DEFLATE_MIN_SIZE        8
151 #define DEFLATE_MAX_SIZE        15
152 #define DEFLATE_METHOD_VAL      8
153 #define DEFLATE_SIZE(x)         (((x) >> 4) + DEFLATE_MIN_SIZE)
154 #define DEFLATE_METHOD(x)       ((x) & 0x0F)
155 #define DEFLATE_MAKE_OPT(w)     ((((w) - DEFLATE_MIN_SIZE) << 4) \
156                                  + DEFLATE_METHOD_VAL)
157 #define DEFLATE_CHK_SEQUENCE    0
158
159 #endif /* _NET_PPP_COMP_H */