]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/ppp_comp.h
xnu-1504.3.12.tar.gz
[apple/xnu.git] / bsd / net / ppp_comp.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * ppp_comp.h - Definitions for doing PPP packet compression.
30 *
31 * Copyright (c) 1994 The Australian National University.
32 * All rights reserved.
33 *
34 * Permission to use, copy, modify, and distribute this software and its
35 * documentation is hereby granted, provided that the above copyright
36 * notice appears in all copies. This software is provided without any
37 * warranty, express or implied. The Australian National University
38 * makes no representations about the suitability of this software for
39 * any purpose.
40 *
41 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
42 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
43 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
44 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
45 * OF SUCH DAMAGE.
46 *
47 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
48 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
49 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
50 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
51 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
52 * OR MODIFICATIONS.
53 *
54 */
55
56 #ifndef _NET_PPP_COMP_H
57 #define _NET_PPP_COMP_H
58 #ifdef KERNEL_PRIVATE
59 /*
60 * The following symbols control whether we include code for
61 * various compression methods.
62 */
63 #ifndef DO_BSD_COMPRESS
64 #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
65 #endif
66 #ifndef DO_DEFLATE
67 #define DO_DEFLATE 1 /* by default, include Deflate */
68 #endif
69 #define DO_PREDICTOR_1 0
70 #define DO_PREDICTOR_2 0
71
72 /*
73 * Structure giving methods for compression/decompression.
74 */
75 #if PACKETPTR
76 struct compressor {
77 int compress_proto; /* CCP compression protocol number */
78
79 /* Allocate space for a compressor (transmit side) */
80 void *(*comp_alloc)(u_char *options, int opt_len);
81 /* Free space used by a compressor */
82 void (*comp_free)(void *state);
83 /* Initialize a compressor */
84 int (*comp_init)(void *state, u_char *options, int opt_len,
85 int unit, int hdrlen, int debug);
86 /* Reset a compressor */
87 void (*comp_reset)(void *state);
88 /* Compress a packet */
89 int (*compress)(void *state, PACKETPTR *mret,
90 PACKETPTR mp, int orig_len, int max_len);
91 /* Return compression statistics */
92 void (*comp_stat)(void *state, struct compstat *stats);
93
94 /* Allocate space for a decompressor (receive side) */
95 void *(*decomp_alloc)(u_char *options, int opt_len);
96 /* Free space used by a decompressor */
97 void (*decomp_free)(void *state);
98 /* Initialize a decompressor */
99 int (*decomp_init)(void *state, u_char *options, int opt_len,
100 int unit, int hdrlen, int mru, int debug);
101 /* Reset a decompressor */
102 void (*decomp_reset)(void *state);
103 /* Decompress a packet. */
104 int (*decompress)(void *state, PACKETPTR mp, PACKETPTR *dmpp);
105 /* Update state for an incompressible packet received */
106 void (*incomp)(void *state, PACKETPTR mp);
107 /* Return decompression statistics */
108 void (*decomp_stat)(void *state, struct compstat *stats);
109 };
110 #endif /* PACKETPTR */
111
112 /*
113 * Return values for decompress routine.
114 * We need to make these distinctions so that we can disable certain
115 * useful functionality, namely sending a CCP reset-request as a result
116 * of an error detected after decompression. This is to avoid infringing
117 * a patent held by Motorola.
118 * Don't you just lurve software patents.
119 */
120 #define DECOMP_OK 0 /* everything went OK */
121 #define DECOMP_ERROR 1 /* error detected before decomp. */
122 #define DECOMP_FATALERROR 2 /* error detected after decomp. */
123
124 /*
125 * CCP codes.
126 */
127 #define CCP_CONFREQ 1
128 #define CCP_CONFACK 2
129 #define CCP_TERMREQ 5
130 #define CCP_TERMACK 6
131 #define CCP_RESETREQ 14
132 #define CCP_RESETACK 15
133
134 /*
135 * Max # bytes for a CCP option
136 */
137 #define CCP_MAX_OPTION_LENGTH 32
138
139 /*
140 * Parts of a CCP packet.
141 */
142 #define CCP_CODE(dp) ((dp)[0])
143 #define CCP_ID(dp) ((dp)[1])
144 #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
145 #define CCP_HDRLEN 4
146
147 #define CCP_OPT_CODE(dp) ((dp)[0])
148 #define CCP_OPT_LENGTH(dp) ((dp)[1])
149 #define CCP_OPT_MINLEN 2
150
151 /*
152 * Definitions for BSD-Compress.
153 */
154 #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
155 #define CILEN_BSD_COMPRESS 3 /* length of config. option */
156
157 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
158 #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
159 #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
160 #define BSD_CURRENT_VERSION 1 /* current version number */
161 #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
162
163 #define BSD_MIN_BITS 9 /* smallest code size supported */
164 #define BSD_MAX_BITS 15 /* largest code size supported */
165
166 /*
167 * Definitions for Deflate.
168 */
169 #define CI_DEFLATE 26 /* config option for Deflate */
170 #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
171 #define CILEN_DEFLATE 4 /* length of its config option */
172
173 #define DEFLATE_MIN_SIZE 8
174 #define DEFLATE_MAX_SIZE 15
175 #define DEFLATE_METHOD_VAL 8
176 #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
177 #define DEFLATE_METHOD(x) ((x) & 0x0F)
178 #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
179 + DEFLATE_METHOD_VAL)
180 #define DEFLATE_CHK_SEQUENCE 0
181
182 /*
183 * Definitions for other, as yet unsupported, compression methods.
184 */
185 #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
186 #define CILEN_PREDICTOR_1 2 /* length of its config option */
187 #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
188 #define CILEN_PREDICTOR_2 2 /* length of its config option */
189
190 #endif /* KERNEL_PRIVATE */
191 #endif /* _NET_PPP_COMP_H */