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