Home | History | Annotate | Line # | Download | only in net
ppp-comp.h revision 1.2
      1 /*	$NetBSD: ppp-comp.h,v 1.2 1996/03/15 02:28:07 paulus Exp $	*/
      2 
      3 /*
      4  * ppp-comp.h - Definitions for doing PPP packet compression.
      5  *
      6  * Copyright (c) 1994 The Australian National University.
      7  * All rights reserved.
      8  *
      9  * Permission to use, copy, modify, and distribute this software and its
     10  * documentation is hereby granted, provided that the above copyright
     11  * notice appears in all copies.  This software is provided without any
     12  * warranty, express or implied. The Australian National University
     13  * makes no representations about the suitability of this software for
     14  * any purpose.
     15  *
     16  * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
     17  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
     18  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
     19  * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
     20  * OF SUCH DAMAGE.
     21  *
     22  * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
     23  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
     24  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
     25  * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
     26  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
     27  * OR MODIFICATIONS.
     28  *
     29  */
     30 
     31 #ifndef _NET_PPP_COMP_H
     32 #define _NET_PPP_COMP_H
     33 
     34 /*
     35  * The following symbols control whether we include code for
     36  * various compression methods.
     37  */
     38 #ifndef DO_BSD_COMPRESS
     39 #define DO_BSD_COMPRESS	1	/* by default, include BSD-Compress */
     40 #endif
     41 #ifndef DO_DEFLATE
     42 #define DO_DEFLATE	1	/* by default, include Deflate */
     43 #endif
     44 #define DO_PREDICTOR_1	0
     45 #define DO_PREDICTOR_2	0
     46 
     47 /*
     48  * Structure giving methods for compression/decompression.
     49  */
     50 #ifdef PACKETPTR
     51 struct compressor {
     52 	int	compress_proto;	/* CCP compression protocol number */
     53 
     54 	/* Allocate space for a compressor (transmit side) */
     55 	void	*(*comp_alloc) __P((u_char *options, int opt_len));
     56 	/* Free space used by a compressor */
     57 	void	(*comp_free) __P((void *state));
     58 	/* Initialize a compressor */
     59 	int	(*comp_init) __P((void *state, u_char *options, int opt_len,
     60 				  int unit, int hdrlen, int debug));
     61 	/* Reset a compressor */
     62 	void	(*comp_reset) __P((void *state));
     63 	/* Compress a packet */
     64 	int	(*compress) __P((void *state, PACKETPTR *mret,
     65 				 PACKETPTR mp, int orig_len, int max_len));
     66 	/* Return compression statistics */
     67 	void	(*comp_stat) __P((void *state, struct compstat *stats));
     68 
     69 	/* Allocate space for a decompressor (receive side) */
     70 	void	*(*decomp_alloc) __P((u_char *options, int opt_len));
     71 	/* Free space used by a decompressor */
     72 	void	(*decomp_free) __P((void *state));
     73 	/* Initialize a decompressor */
     74 	int	(*decomp_init) __P((void *state, u_char *options, int opt_len,
     75 				    int unit, int hdrlen, int mru, int debug));
     76 	/* Reset a decompressor */
     77 	void	(*decomp_reset) __P((void *state));
     78 	/* Decompress a packet. */
     79 	int	(*decompress) __P((void *state, PACKETPTR mp,
     80 				   PACKETPTR *dmpp));
     81 	/* Update state for an incompressible packet received */
     82 	void	(*incomp) __P((void *state, PACKETPTR mp));
     83 	/* Return decompression statistics */
     84 	void	(*decomp_stat) __P((void *state, struct compstat *stats));
     85 };
     86 #endif /* PACKETPTR */
     87 
     88 /*
     89  * Return values for decompress routine.
     90  * We need to make these distinctions so that we can disable certain
     91  * useful functionality, namely sending a CCP reset-request as a result
     92  * of an error detected after decompression.  This is to avoid infringing
     93  * a patent held by Motorola.
     94  * Don't you just lurve software patents.
     95  */
     96 #define DECOMP_OK		0	/* everything went OK */
     97 #define DECOMP_ERROR		1	/* error detected before decomp. */
     98 #define DECOMP_FATALERROR	2	/* error detected after decomp. */
     99 
    100 /*
    101  * CCP codes.
    102  */
    103 #define CCP_CONFREQ	1
    104 #define CCP_CONFACK	2
    105 #define CCP_TERMREQ	5
    106 #define CCP_TERMACK	6
    107 #define CCP_RESETREQ	14
    108 #define CCP_RESETACK	15
    109 
    110 /*
    111  * Max # bytes for a CCP option
    112  */
    113 #define CCP_MAX_OPTION_LENGTH	32
    114 
    115 /*
    116  * Parts of a CCP packet.
    117  */
    118 #define CCP_CODE(dp)		((dp)[0])
    119 #define CCP_ID(dp)		((dp)[1])
    120 #define CCP_LENGTH(dp)		(((dp)[2] << 8) + (dp)[3])
    121 #define CCP_HDRLEN		4
    122 
    123 #define CCP_OPT_CODE(dp)	((dp)[0])
    124 #define CCP_OPT_LENGTH(dp)	((dp)[1])
    125 #define CCP_OPT_MINLEN		2
    126 
    127 /*
    128  * Definitions for BSD-Compress.
    129  */
    130 #define CI_BSD_COMPRESS		21	/* config. option for BSD-Compress */
    131 #define CILEN_BSD_COMPRESS	3	/* length of config. option */
    132 
    133 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
    134 #define BSD_NBITS(x)		((x) & 0x1F)	/* number of bits requested */
    135 #define BSD_VERSION(x)		((x) >> 5)	/* version of option format */
    136 #define BSD_CURRENT_VERSION	1		/* current version number */
    137 #define BSD_MAKE_OPT(v, n)	(((v) << 5) | (n))
    138 
    139 #define BSD_MIN_BITS		9	/* smallest code size supported */
    140 #define BSD_MAX_BITS		15	/* largest code size supported */
    141 
    142 /*
    143  * Definitions for other, as yet unsupported, compression methods.
    144  */
    145 #define CI_PREDICTOR_1		1	/* config option for Predictor-1 */
    146 #define CILEN_PREDICTOR_1	2	/* length of its config option */
    147 #define CI_PREDICTOR_2		2	/* config option for Predictor-2 */
    148 #define CILEN_PREDICTOR_2	2	/* length of its config option */
    149 
    150 #define CI_DEFLATE		24	/* config option for Deflate */
    151 #define CILEN_DEFLATE		4	/* length of its config option */
    152 
    153 #define DEFLATE_MIN_SIZE	8
    154 #define DEFLATE_MAX_SIZE	15
    155 #define DEFLATE_METHOD_VAL	8
    156 #define DEFLATE_SIZE(x)		(((x) >> 4) + DEFLATE_MIN_SIZE)
    157 #define DEFLATE_METHOD(x)	((x) & 0x0F)
    158 #define DEFLATE_MAKE_OPT(w)	((((w) - DEFLATE_MIN_SIZE) << 4) \
    159 				 + DEFLATE_METHOD_VAL)
    160 #define DEFLATE_CHK_SEQUENCE	0
    161 
    162 #endif /* _NET_PPP_COMP_H */
    163