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