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