ppp-comp.h revision 1.3 1 /* $NetBSD: ppp-comp.h,v 1.3 1997/03/12 20:26:55 christos Exp $ */
2
3 /*
4 * ppp-comp.h - Definitions for doing PPP packet compression.
5 *
6 * Copyright (c) 1994 The Australian National University.
7 * All rights reserved.
8 *
9 * Permission to use, copy, modify, and distribute this software and its
10 * documentation is hereby granted, provided that the above copyright
11 * notice appears in all copies. This software is provided without any
12 * warranty, express or implied. The Australian National University
13 * makes no representations about the suitability of this software for
14 * any purpose.
15 *
16 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
17 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
18 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
19 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
20 * OF SUCH DAMAGE.
21 *
22 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
25 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
26 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
27 * OR MODIFICATIONS.
28 *
29 * Id: ppp-comp.h,v 1.10 1996/09/26 06:30:11 paulus Exp
30 */
31
32 #ifndef _NET_PPP_COMP_H
33 #define _NET_PPP_COMP_H
34
35 /*
36 * The following symbols control whether we include code for
37 * various compression methods.
38 */
39 #ifndef DO_BSD_COMPRESS
40 #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
41 #endif
42 #ifndef DO_DEFLATE
43 #define DO_DEFLATE 1 /* by default, include Deflate */
44 #endif
45 #define DO_PREDICTOR_1 0
46 #define DO_PREDICTOR_2 0
47
48 /*
49 * Structure giving methods for compression/decompression.
50 */
51 #ifdef PACKETPTR
52 struct compressor {
53 int compress_proto; /* CCP compression protocol number */
54
55 /* Allocate space for a compressor (transmit side) */
56 void *(*comp_alloc) __P((u_char *options, int opt_len));
57 /* Free space used by a compressor */
58 void (*comp_free) __P((void *state));
59 /* Initialize a compressor */
60 int (*comp_init) __P((void *state, u_char *options, int opt_len,
61 int unit, int hdrlen, int debug));
62 /* Reset a compressor */
63 void (*comp_reset) __P((void *state));
64 /* Compress a packet */
65 int (*compress) __P((void *state, PACKETPTR *mret,
66 PACKETPTR mp, int orig_len, int max_len));
67 /* Return compression statistics */
68 void (*comp_stat) __P((void *state, struct compstat *stats));
69
70 /* Allocate space for a decompressor (receive side) */
71 void *(*decomp_alloc) __P((u_char *options, int opt_len));
72 /* Free space used by a decompressor */
73 void (*decomp_free) __P((void *state));
74 /* Initialize a decompressor */
75 int (*decomp_init) __P((void *state, u_char *options, int opt_len,
76 int unit, int hdrlen, int mru, int debug));
77 /* Reset a decompressor */
78 void (*decomp_reset) __P((void *state));
79 /* Decompress a packet. */
80 int (*decompress) __P((void *state, PACKETPTR mp,
81 PACKETPTR *dmpp));
82 /* Update state for an incompressible packet received */
83 void (*incomp) __P((void *state, PACKETPTR mp));
84 /* Return decompression statistics */
85 void (*decomp_stat) __P((void *state, struct compstat *stats));
86 };
87 #endif /* PACKETPTR */
88
89 /*
90 * Return values for decompress routine.
91 * We need to make these distinctions so that we can disable certain
92 * useful functionality, namely sending a CCP reset-request as a result
93 * of an error detected after decompression. This is to avoid infringing
94 * a patent held by Motorola.
95 * Don't you just lurve software patents.
96 */
97 #define DECOMP_OK 0 /* everything went OK */
98 #define DECOMP_ERROR 1 /* error detected before decomp. */
99 #define DECOMP_FATALERROR 2 /* error detected after decomp. */
100
101 /*
102 * CCP codes.
103 */
104 #define CCP_CONFREQ 1
105 #define CCP_CONFACK 2
106 #define CCP_TERMREQ 5
107 #define CCP_TERMACK 6
108 #define CCP_RESETREQ 14
109 #define CCP_RESETACK 15
110
111 /*
112 * Max # bytes for a CCP option
113 */
114 #define CCP_MAX_OPTION_LENGTH 32
115
116 /*
117 * Parts of a CCP packet.
118 */
119 #define CCP_CODE(dp) ((dp)[0])
120 #define CCP_ID(dp) ((dp)[1])
121 #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
122 #define CCP_HDRLEN 4
123
124 #define CCP_OPT_CODE(dp) ((dp)[0])
125 #define CCP_OPT_LENGTH(dp) ((dp)[1])
126 #define CCP_OPT_MINLEN 2
127
128 /*
129 * Definitions for BSD-Compress.
130 */
131 #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
132 #define CILEN_BSD_COMPRESS 3 /* length of config. option */
133
134 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
135 #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
136 #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
137 #define BSD_CURRENT_VERSION 1 /* current version number */
138 #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
139
140 #define BSD_MIN_BITS 9 /* smallest code size supported */
141 #define BSD_MAX_BITS 15 /* largest code size supported */
142
143 /*
144 * Definitions for Deflate.
145 */
146 #define CI_DEFLATE 24 /* config option for Deflate */
147 #define CILEN_DEFLATE 4 /* length of its config option */
148
149 #define DEFLATE_MIN_SIZE 8
150 #define DEFLATE_MAX_SIZE 15
151 #define DEFLATE_METHOD_VAL 8
152 #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
153 #define DEFLATE_METHOD(x) ((x) & 0x0F)
154 #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
155 + DEFLATE_METHOD_VAL)
156 #define DEFLATE_CHK_SEQUENCE 0
157
158 /*
159 * Definitions for other, as yet unsupported, compression methods.
160 */
161 #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
162 #define CILEN_PREDICTOR_1 2 /* length of its config option */
163 #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
164 #define CILEN_PREDICTOR_2 2 /* length of its config option */
165
166 #endif /* _NET_PPP_COMP_H */
167