ppp-comp.h revision 1.9 1 1.9 christos /* $NetBSD: ppp-comp.h,v 1.9 2003/03/27 17:50:28 christos Exp $ */
2 1.1 paulus
3 1.1 paulus /*
4 1.1 paulus * ppp-comp.h - Definitions for doing PPP packet compression.
5 1.1 paulus *
6 1.8 itojun * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved.
7 1.1 paulus *
8 1.8 itojun * Redistribution and use in source and binary forms, with or without
9 1.8 itojun * modification, are permitted provided that the following conditions
10 1.8 itojun * are met:
11 1.8 itojun *
12 1.8 itojun * 1. Redistributions of source code must retain the above copyright
13 1.8 itojun * notice, this list of conditions and the following disclaimer.
14 1.8 itojun *
15 1.8 itojun * 2. Redistributions in binary form must reproduce the above copyright
16 1.8 itojun * notice, this list of conditions and the following disclaimer in
17 1.8 itojun * the documentation and/or other materials provided with the
18 1.8 itojun * distribution.
19 1.8 itojun *
20 1.8 itojun * 3. The name(s) of the authors of this software must not be used to
21 1.8 itojun * endorse or promote products derived from this software without
22 1.8 itojun * prior written permission.
23 1.8 itojun *
24 1.8 itojun * 4. Redistributions of any form whatsoever must retain the following
25 1.8 itojun * acknowledgment:
26 1.8 itojun * "This product includes software developed by Paul Mackerras
27 1.8 itojun * <paulus (at) samba.org>".
28 1.8 itojun *
29 1.8 itojun * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
30 1.8 itojun * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
31 1.8 itojun * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
32 1.8 itojun * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
33 1.8 itojun * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
34 1.8 itojun * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
35 1.8 itojun * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
36 1.1 paulus */
37 1.1 paulus
38 1.1 paulus #ifndef _NET_PPP_COMP_H
39 1.1 paulus #define _NET_PPP_COMP_H
40 1.1 paulus
41 1.1 paulus /*
42 1.1 paulus * The following symbols control whether we include code for
43 1.1 paulus * various compression methods.
44 1.1 paulus */
45 1.1 paulus #ifndef DO_BSD_COMPRESS
46 1.1 paulus #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
47 1.1 paulus #endif
48 1.2 paulus #ifndef DO_DEFLATE
49 1.2 paulus #define DO_DEFLATE 1 /* by default, include Deflate */
50 1.2 paulus #endif
51 1.2 paulus #define DO_PREDICTOR_1 0
52 1.2 paulus #define DO_PREDICTOR_2 0
53 1.9 christos
54 1.9 christos /*
55 1.9 christos * How many entries to make available in the compressors table
56 1.9 christos */
57 1.9 christos #ifndef PPP_COMPRESSORS_MAX
58 1.9 christos #define PPP_COMPRESSORS_MAX 8
59 1.9 christos #endif
60 1.1 paulus
61 1.1 paulus /*
62 1.1 paulus * Structure giving methods for compression/decompression.
63 1.1 paulus */
64 1.1 paulus #ifdef PACKETPTR
65 1.1 paulus struct compressor {
66 1.1 paulus int compress_proto; /* CCP compression protocol number */
67 1.1 paulus
68 1.1 paulus /* Allocate space for a compressor (transmit side) */
69 1.1 paulus void *(*comp_alloc) __P((u_char *options, int opt_len));
70 1.1 paulus /* Free space used by a compressor */
71 1.1 paulus void (*comp_free) __P((void *state));
72 1.1 paulus /* Initialize a compressor */
73 1.1 paulus int (*comp_init) __P((void *state, u_char *options, int opt_len,
74 1.1 paulus int unit, int hdrlen, int debug));
75 1.1 paulus /* Reset a compressor */
76 1.1 paulus void (*comp_reset) __P((void *state));
77 1.1 paulus /* Compress a packet */
78 1.1 paulus int (*compress) __P((void *state, PACKETPTR *mret,
79 1.1 paulus PACKETPTR mp, int orig_len, int max_len));
80 1.1 paulus /* Return compression statistics */
81 1.1 paulus void (*comp_stat) __P((void *state, struct compstat *stats));
82 1.1 paulus
83 1.1 paulus /* Allocate space for a decompressor (receive side) */
84 1.1 paulus void *(*decomp_alloc) __P((u_char *options, int opt_len));
85 1.1 paulus /* Free space used by a decompressor */
86 1.1 paulus void (*decomp_free) __P((void *state));
87 1.1 paulus /* Initialize a decompressor */
88 1.1 paulus int (*decomp_init) __P((void *state, u_char *options, int opt_len,
89 1.1 paulus int unit, int hdrlen, int mru, int debug));
90 1.1 paulus /* Reset a decompressor */
91 1.1 paulus void (*decomp_reset) __P((void *state));
92 1.1 paulus /* Decompress a packet. */
93 1.1 paulus int (*decompress) __P((void *state, PACKETPTR mp,
94 1.1 paulus PACKETPTR *dmpp));
95 1.1 paulus /* Update state for an incompressible packet received */
96 1.1 paulus void (*incomp) __P((void *state, PACKETPTR mp));
97 1.1 paulus /* Return decompression statistics */
98 1.1 paulus void (*decomp_stat) __P((void *state, struct compstat *stats));
99 1.1 paulus };
100 1.1 paulus #endif /* PACKETPTR */
101 1.1 paulus
102 1.1 paulus /*
103 1.1 paulus * Return values for decompress routine.
104 1.1 paulus * We need to make these distinctions so that we can disable certain
105 1.1 paulus * useful functionality, namely sending a CCP reset-request as a result
106 1.1 paulus * of an error detected after decompression. This is to avoid infringing
107 1.1 paulus * a patent held by Motorola.
108 1.1 paulus * Don't you just lurve software patents.
109 1.1 paulus */
110 1.1 paulus #define DECOMP_OK 0 /* everything went OK */
111 1.1 paulus #define DECOMP_ERROR 1 /* error detected before decomp. */
112 1.1 paulus #define DECOMP_FATALERROR 2 /* error detected after decomp. */
113 1.1 paulus
114 1.1 paulus /*
115 1.1 paulus * CCP codes.
116 1.1 paulus */
117 1.1 paulus #define CCP_CONFREQ 1
118 1.1 paulus #define CCP_CONFACK 2
119 1.6 christos #define CCP_CONFNAK 3
120 1.6 christos #define CCP_CONFREJ 4
121 1.1 paulus #define CCP_TERMREQ 5
122 1.1 paulus #define CCP_TERMACK 6
123 1.1 paulus #define CCP_RESETREQ 14
124 1.1 paulus #define CCP_RESETACK 15
125 1.1 paulus
126 1.1 paulus /*
127 1.1 paulus * Max # bytes for a CCP option
128 1.1 paulus */
129 1.5 christos #define CCP_MAX_OPTION_LENGTH 64
130 1.1 paulus
131 1.1 paulus /*
132 1.1 paulus * Parts of a CCP packet.
133 1.1 paulus */
134 1.1 paulus #define CCP_CODE(dp) ((dp)[0])
135 1.1 paulus #define CCP_ID(dp) ((dp)[1])
136 1.1 paulus #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
137 1.1 paulus #define CCP_HDRLEN 4
138 1.1 paulus
139 1.1 paulus #define CCP_OPT_CODE(dp) ((dp)[0])
140 1.1 paulus #define CCP_OPT_LENGTH(dp) ((dp)[1])
141 1.1 paulus #define CCP_OPT_MINLEN 2
142 1.1 paulus
143 1.1 paulus /*
144 1.1 paulus * Definitions for BSD-Compress.
145 1.1 paulus */
146 1.1 paulus #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
147 1.1 paulus #define CILEN_BSD_COMPRESS 3 /* length of config. option */
148 1.1 paulus
149 1.1 paulus /* Macros for handling the 3rd byte of the BSD-Compress config option. */
150 1.1 paulus #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
151 1.1 paulus #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
152 1.1 paulus #define BSD_CURRENT_VERSION 1 /* current version number */
153 1.1 paulus #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
154 1.1 paulus
155 1.1 paulus #define BSD_MIN_BITS 9 /* smallest code size supported */
156 1.1 paulus #define BSD_MAX_BITS 15 /* largest code size supported */
157 1.2 paulus
158 1.2 paulus /*
159 1.3 christos * Definitions for Deflate.
160 1.2 paulus */
161 1.4 christos #define CI_DEFLATE 26 /* config option for Deflate */
162 1.4 christos #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
163 1.4 christos
164 1.2 paulus #define CILEN_DEFLATE 4 /* length of its config option */
165 1.2 paulus
166 1.2 paulus #define DEFLATE_MIN_SIZE 8
167 1.2 paulus #define DEFLATE_MAX_SIZE 15
168 1.2 paulus #define DEFLATE_METHOD_VAL 8
169 1.2 paulus #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
170 1.2 paulus #define DEFLATE_METHOD(x) ((x) & 0x0F)
171 1.2 paulus #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
172 1.2 paulus + DEFLATE_METHOD_VAL)
173 1.2 paulus #define DEFLATE_CHK_SEQUENCE 0
174 1.3 christos
175 1.3 christos /*
176 1.3 christos * Definitions for other, as yet unsupported, compression methods.
177 1.3 christos */
178 1.3 christos #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
179 1.3 christos #define CILEN_PREDICTOR_1 2 /* length of its config option */
180 1.3 christos #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
181 1.3 christos #define CILEN_PREDICTOR_2 2 /* length of its config option */
182 1.1 paulus
183 1.1 paulus #endif /* _NET_PPP_COMP_H */
184