xref: /linux-6.15/include/linux/ppp-comp.h (revision 8e4627dd)
1 /*
2  * ppp-comp.h - Definitions for doing PPP packet compression.
3  *
4  * Copyright 1994-1998 Paul Mackerras.
5  *
6  *  This program is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU General Public License
8  *  version 2 as published by the Free Software Foundation.
9  */
10 #ifndef _NET_PPP_COMP_H
11 #define _NET_PPP_COMP_H
12 
13 #ifdef __KERNEL__
14 
15 struct module;
16 
17 /*
18  * The following symbols control whether we include code for
19  * various compression methods.
20  */
21 
22 #ifndef DO_BSD_COMPRESS
23 #define DO_BSD_COMPRESS	1	/* by default, include BSD-Compress */
24 #endif
25 #ifndef DO_DEFLATE
26 #define DO_DEFLATE	1	/* by default, include Deflate */
27 #endif
28 #define DO_PREDICTOR_1	0
29 #define DO_PREDICTOR_2	0
30 
31 /*
32  * Structure giving methods for compression/decompression.
33  */
34 
35 struct compressor {
36 	int	compress_proto;	/* CCP compression protocol number */
37 
38 	/* Allocate space for a compressor (transmit side) */
39 	void	*(*comp_alloc) (unsigned char *options, int opt_len);
40 
41 	/* Free space used by a compressor */
42 	void	(*comp_free) (void *state);
43 
44 	/* Initialize a compressor */
45 	int	(*comp_init) (void *state, unsigned char *options,
46 			      int opt_len, int unit, int opthdr, int debug);
47 
48 	/* Reset a compressor */
49 	void	(*comp_reset) (void *state);
50 
51 	/* Compress a packet */
52 	int     (*compress) (void *state, unsigned char *rptr,
53 			      unsigned char *obuf, int isize, int osize);
54 
55 	/* Return compression statistics */
56 	void	(*comp_stat) (void *state, struct compstat *stats);
57 
58 	/* Allocate space for a decompressor (receive side) */
59 	void	*(*decomp_alloc) (unsigned char *options, int opt_len);
60 
61 	/* Free space used by a decompressor */
62 	void	(*decomp_free) (void *state);
63 
64 	/* Initialize a decompressor */
65 	int	(*decomp_init) (void *state, unsigned char *options,
66 				int opt_len, int unit, int opthdr, int mru,
67 				int debug);
68 
69 	/* Reset a decompressor */
70 	void	(*decomp_reset) (void *state);
71 
72 	/* Decompress a packet. */
73 	int	(*decompress) (void *state, unsigned char *ibuf, int isize,
74 				unsigned char *obuf, int osize);
75 
76 	/* Update state for an incompressible packet received */
77 	void	(*incomp) (void *state, unsigned char *ibuf, int icnt);
78 
79 	/* Return decompression statistics */
80 	void	(*decomp_stat) (void *state, struct compstat *stats);
81 
82 	/* Used in locking compressor modules */
83 	struct module *owner;
84 	/* Extra skb space needed by the compressor algorithm */
85 	unsigned int comp_extra;
86 };
87 
88 /*
89  * The return value from decompress routine is the length of the
90  * decompressed packet if successful, otherwise DECOMP_ERROR
91  * or DECOMP_FATALERROR if an error occurred.
92  *
93  * We need to make this distinction so that we can disable certain
94  * useful functionality, namely sending a CCP reset-request as a result
95  * of an error detected after decompression.  This is to avoid infringing
96  * a patent held by Motorola.
97  * Don't you just lurve software patents.
98  */
99 
100 #define DECOMP_ERROR		-1	/* error detected before decomp. */
101 #define DECOMP_FATALERROR	-2	/* error detected after decomp. */
102 
103 #endif /* __KERNEL__ */
104 
105 /*
106  * CCP codes.
107  */
108 
109 #define CCP_CONFREQ	1
110 #define CCP_CONFACK	2
111 #define CCP_TERMREQ	5
112 #define CCP_TERMACK	6
113 #define CCP_RESETREQ	14
114 #define CCP_RESETACK	15
115 
116 /*
117  * Max # bytes for a CCP option
118  */
119 
120 #define CCP_MAX_OPTION_LENGTH	32
121 
122 /*
123  * Parts of a CCP packet.
124  */
125 
126 #define CCP_CODE(dp)		((dp)[0])
127 #define CCP_ID(dp)		((dp)[1])
128 #define CCP_LENGTH(dp)		(((dp)[2] << 8) + (dp)[3])
129 #define CCP_HDRLEN		4
130 
131 #define CCP_OPT_CODE(dp)	((dp)[0])
132 #define CCP_OPT_LENGTH(dp)	((dp)[1])
133 #define CCP_OPT_MINLEN		2
134 
135 /*
136  * Definitions for BSD-Compress.
137  */
138 
139 #define CI_BSD_COMPRESS		21	/* config. option for BSD-Compress */
140 #define CILEN_BSD_COMPRESS	3	/* length of config. option */
141 
142 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
143 #define BSD_NBITS(x)		((x) & 0x1F)	/* number of bits requested */
144 #define BSD_VERSION(x)		((x) >> 5)	/* version of option format */
145 #define BSD_CURRENT_VERSION	1		/* current version number */
146 #define BSD_MAKE_OPT(v, n)	(((v) << 5) | (n))
147 
148 #define BSD_MIN_BITS		9	/* smallest code size supported */
149 #define BSD_MAX_BITS		15	/* largest code size supported */
150 
151 /*
152  * Definitions for Deflate.
153  */
154 
155 #define CI_DEFLATE		26	/* config option for Deflate */
156 #define CI_DEFLATE_DRAFT	24	/* value used in original draft RFC */
157 #define CILEN_DEFLATE		4	/* length of its config option */
158 
159 #define DEFLATE_MIN_SIZE	9
160 #define DEFLATE_MAX_SIZE	15
161 #define DEFLATE_METHOD_VAL	8
162 #define DEFLATE_SIZE(x)		(((x) >> 4) + 8)
163 #define DEFLATE_METHOD(x)	((x) & 0x0F)
164 #define DEFLATE_MAKE_OPT(w)	((((w) - 8) << 4) + DEFLATE_METHOD_VAL)
165 #define DEFLATE_CHK_SEQUENCE	0
166 
167 /*
168  * Definitions for MPPE.
169  */
170 
171 #define CI_MPPE                18      /* config option for MPPE */
172 #define CILEN_MPPE              6      /* length of config option */
173 
174 /*
175  * Definitions for other, as yet unsupported, compression methods.
176  */
177 
178 #define CI_PREDICTOR_1		1	/* config option for Predictor-1 */
179 #define CILEN_PREDICTOR_1	2	/* length of its config option */
180 #define CI_PREDICTOR_2		2	/* config option for Predictor-2 */
181 #define CILEN_PREDICTOR_2	2	/* length of its config option */
182 
183 #ifdef __KERNEL__
184 extern int ppp_register_compressor(struct compressor *);
185 extern void ppp_unregister_compressor(struct compressor *);
186 #endif /* __KERNEL__ */
187 
188 #endif /* _NET_PPP_COMP_H */
189