ppp-comp.h revision 1.10 1 1.10 itojun /* $NetBSD: ppp-comp.h,v 1.10 2003/07/08 07:13:52 itojun 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.10 itojun void *(*comp_alloc) __P((u_char *, int));
70 1.1 paulus /* Free space used by a compressor */
71 1.10 itojun void (*comp_free) __P((void *));
72 1.1 paulus /* Initialize a compressor */
73 1.10 itojun int (*comp_init) __P((void *, u_char *, int, int, int, int));
74 1.1 paulus /* Reset a compressor */
75 1.10 itojun void (*comp_reset) __P((void *));
76 1.1 paulus /* Compress a packet */
77 1.10 itojun int (*compress) __P((void *, PACKETPTR *, PACKETPTR, int, int));
78 1.1 paulus /* Return compression statistics */
79 1.10 itojun void (*comp_stat) __P((void *, struct compstat *));
80 1.1 paulus
81 1.1 paulus /* Allocate space for a decompressor (receive side) */
82 1.10 itojun void *(*decomp_alloc) __P((u_char *, int));
83 1.1 paulus /* Free space used by a decompressor */
84 1.10 itojun void (*decomp_free) __P((void *));
85 1.1 paulus /* Initialize a decompressor */
86 1.10 itojun int (*decomp_init) __P((void *, u_char *, int, int, int, int, int));
87 1.1 paulus /* Reset a decompressor */
88 1.10 itojun void (*decomp_reset) __P((void *));
89 1.1 paulus /* Decompress a packet. */
90 1.10 itojun int (*decompress) __P((void *, PACKETPTR, PACKETPTR *));
91 1.1 paulus /* Update state for an incompressible packet received */
92 1.10 itojun void (*incomp) __P((void *, PACKETPTR));
93 1.1 paulus /* Return decompression statistics */
94 1.10 itojun void (*decomp_stat) __P((void *, struct compstat *));
95 1.1 paulus };
96 1.1 paulus #endif /* PACKETPTR */
97 1.1 paulus
98 1.1 paulus /*
99 1.1 paulus * Return values for decompress routine.
100 1.1 paulus * We need to make these distinctions so that we can disable certain
101 1.1 paulus * useful functionality, namely sending a CCP reset-request as a result
102 1.1 paulus * of an error detected after decompression. This is to avoid infringing
103 1.1 paulus * a patent held by Motorola.
104 1.1 paulus * Don't you just lurve software patents.
105 1.1 paulus */
106 1.1 paulus #define DECOMP_OK 0 /* everything went OK */
107 1.1 paulus #define DECOMP_ERROR 1 /* error detected before decomp. */
108 1.1 paulus #define DECOMP_FATALERROR 2 /* error detected after decomp. */
109 1.1 paulus
110 1.1 paulus /*
111 1.1 paulus * CCP codes.
112 1.1 paulus */
113 1.1 paulus #define CCP_CONFREQ 1
114 1.1 paulus #define CCP_CONFACK 2
115 1.6 christos #define CCP_CONFNAK 3
116 1.6 christos #define CCP_CONFREJ 4
117 1.1 paulus #define CCP_TERMREQ 5
118 1.1 paulus #define CCP_TERMACK 6
119 1.1 paulus #define CCP_RESETREQ 14
120 1.1 paulus #define CCP_RESETACK 15
121 1.1 paulus
122 1.1 paulus /*
123 1.1 paulus * Max # bytes for a CCP option
124 1.1 paulus */
125 1.5 christos #define CCP_MAX_OPTION_LENGTH 64
126 1.1 paulus
127 1.1 paulus /*
128 1.1 paulus * Parts of a CCP packet.
129 1.1 paulus */
130 1.1 paulus #define CCP_CODE(dp) ((dp)[0])
131 1.1 paulus #define CCP_ID(dp) ((dp)[1])
132 1.1 paulus #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
133 1.1 paulus #define CCP_HDRLEN 4
134 1.1 paulus
135 1.1 paulus #define CCP_OPT_CODE(dp) ((dp)[0])
136 1.1 paulus #define CCP_OPT_LENGTH(dp) ((dp)[1])
137 1.1 paulus #define CCP_OPT_MINLEN 2
138 1.1 paulus
139 1.1 paulus /*
140 1.1 paulus * Definitions for BSD-Compress.
141 1.1 paulus */
142 1.1 paulus #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
143 1.1 paulus #define CILEN_BSD_COMPRESS 3 /* length of config. option */
144 1.1 paulus
145 1.1 paulus /* Macros for handling the 3rd byte of the BSD-Compress config option. */
146 1.1 paulus #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
147 1.1 paulus #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
148 1.1 paulus #define BSD_CURRENT_VERSION 1 /* current version number */
149 1.1 paulus #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
150 1.1 paulus
151 1.1 paulus #define BSD_MIN_BITS 9 /* smallest code size supported */
152 1.1 paulus #define BSD_MAX_BITS 15 /* largest code size supported */
153 1.2 paulus
154 1.2 paulus /*
155 1.3 christos * Definitions for Deflate.
156 1.2 paulus */
157 1.4 christos #define CI_DEFLATE 26 /* config option for Deflate */
158 1.4 christos #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
159 1.4 christos
160 1.2 paulus #define CILEN_DEFLATE 4 /* length of its config option */
161 1.2 paulus
162 1.2 paulus #define DEFLATE_MIN_SIZE 8
163 1.2 paulus #define DEFLATE_MAX_SIZE 15
164 1.2 paulus #define DEFLATE_METHOD_VAL 8
165 1.2 paulus #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
166 1.2 paulus #define DEFLATE_METHOD(x) ((x) & 0x0F)
167 1.2 paulus #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
168 1.2 paulus + DEFLATE_METHOD_VAL)
169 1.2 paulus #define DEFLATE_CHK_SEQUENCE 0
170 1.3 christos
171 1.3 christos /*
172 1.3 christos * Definitions for other, as yet unsupported, compression methods.
173 1.3 christos */
174 1.3 christos #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
175 1.3 christos #define CILEN_PREDICTOR_1 2 /* length of its config option */
176 1.3 christos #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
177 1.3 christos #define CILEN_PREDICTOR_2 2 /* length of its config option */
178 1.1 paulus
179 1.1 paulus #endif /* _NET_PPP_COMP_H */
180