blob: b7dc06f7f1d197d238c2a9824f465c694985e7b3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ppp-comp.h - Definitions for doing PPP packet compression.
3 *
Paul Mackerras784db3f2012-03-04 12:54:54 +00004 * Copyright 1994-1998 Paul Mackerras.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Paul Mackerras784db3f2012-03-04 12:54:54 +00006 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#ifndef _NET_PPP_COMP_H
11#define _NET_PPP_COMP_H
12
David Howells8e4627dd2012-10-13 09:58:38 +010013#ifdef __KERNEL__
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015struct 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
35struct 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;
Matt Domschb3f9b922005-11-08 09:40:47 -080084 /* Extra skb space needed by the compressor algorithm */
85 unsigned int comp_extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
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
David Howells8e4627dd2012-10-13 09:58:38 +0100103#endif /* __KERNEL__ */
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105/*
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/*
Matt Domschb3f9b922005-11-08 09:40:47 -0800168 * 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/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 * 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__
184extern int ppp_register_compressor(struct compressor *);
185extern void ppp_unregister_compressor(struct compressor *);
186#endif /* __KERNEL__ */
187
188#endif /* _NET_PPP_COMP_H */