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