ppp-comp.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * ppp-comp.h - Definitions for doing PPP packet compression.
  3. *
  4. * Copyright (c) 1984 Paul Mackerras. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. *
  18. * 3. The name(s) of the authors of this software must not be used to
  19. * endorse or promote products derived from this software without
  20. * prior written permission.
  21. *
  22. * 4. Redistributions of any form whatsoever must retain the following
  23. * acknowledgment:
  24. * "This product includes software developed by Paul Mackerras
  25. * <paulus@samba.org>".
  26. *
  27. * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  28. * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  29. * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
  30. * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  31. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  32. * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  33. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * $Id: ppp-comp.h,v 1.10 2002/12/06 09:49:15 paulus Exp $
  36. */
  37. /*
  38. * ==FILEVERSION 20020319==
  39. *
  40. * NOTE TO MAINTAINERS:
  41. * If you modify this file at all, please set the above date.
  42. * ppp-comp.h is shipped with a PPP distribution as well as with the kernel;
  43. * if everyone increases the FILEVERSION number above, then scripts
  44. * can do the right thing when deciding whether to install a new ppp-comp.h
  45. * file. Don't change the format of that line otherwise, so the
  46. * installation script can recognize it.
  47. */
  48. #ifndef _NET_PPP_COMP_H
  49. #define _NET_PPP_COMP_H
  50. /*
  51. * The following symbols control whether we include code for
  52. * various compression methods.
  53. */
  54. #ifndef DO_BSD_COMPRESS
  55. #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
  56. #endif
  57. #ifndef DO_DEFLATE
  58. #define DO_DEFLATE 1 /* by default, include Deflate */
  59. #endif
  60. #define DO_PREDICTOR_1 0
  61. #define DO_PREDICTOR_2 0
  62. /*
  63. * Structure giving methods for compression/decompression.
  64. */
  65. struct compressor {
  66. int compress_proto; /* CCP compression protocol number */
  67. /* Allocate space for a compressor (transmit side) */
  68. void *(*comp_alloc) (unsigned char *options, int opt_len);
  69. /* Free space used by a compressor */
  70. void (*comp_free) (void *state);
  71. /* Initialize a compressor */
  72. int (*comp_init) (void *state, unsigned char *options,
  73. int opt_len, int unit, int opthdr, int debug);
  74. /* Reset a compressor */
  75. void (*comp_reset) (void *state);
  76. /* Compress a packet */
  77. int (*compress) (void *state, unsigned char *rptr,
  78. unsigned char *obuf, int isize, int osize);
  79. /* Return compression statistics */
  80. void (*comp_stat) (void *state, struct compstat *stats);
  81. /* Allocate space for a decompressor (receive side) */
  82. void *(*decomp_alloc) (unsigned char *options, int opt_len);
  83. /* Free space used by a decompressor */
  84. void (*decomp_free) (void *state);
  85. /* Initialize a decompressor */
  86. int (*decomp_init) (void *state, unsigned char *options,
  87. int opt_len, int unit, int opthdr, int mru,
  88. int debug);
  89. /* Reset a decompressor */
  90. void (*decomp_reset) (void *state);
  91. /* Decompress a packet. */
  92. int (*decompress) (void *state, unsigned char *ibuf, int isize,
  93. unsigned char *obuf, int osize);
  94. /* Update state for an incompressible packet received */
  95. void (*incomp) (void *state, unsigned char *ibuf, int icnt);
  96. /* Return decompression statistics */
  97. void (*decomp_stat) (void *state, struct compstat *stats);
  98. };
  99. /*
  100. * The return value from decompress routine is the length of the
  101. * decompressed packet if successful, otherwise DECOMP_ERROR
  102. * or DECOMP_FATALERROR if an error occurred.
  103. *
  104. * We need to make this distinction so that we can disable certain
  105. * useful functionality, namely sending a CCP reset-request as a result
  106. * of an error detected after decompression. This is to avoid infringing
  107. * a patent held by Motorola.
  108. * Don't you just lurve software patents.
  109. */
  110. #define DECOMP_ERROR -1 /* error detected before decomp. */
  111. #define DECOMP_FATALERROR -2 /* error detected after decomp. */
  112. /*
  113. * CCP codes.
  114. */
  115. #define CCP_CONFREQ 1
  116. #define CCP_CONFACK 2
  117. #define CCP_TERMREQ 5
  118. #define CCP_TERMACK 6
  119. #define CCP_RESETREQ 14
  120. #define CCP_RESETACK 15
  121. /*
  122. * Max # bytes for a CCP option
  123. */
  124. #define CCP_MAX_OPTION_LENGTH 32
  125. /*
  126. * Parts of a CCP packet.
  127. */
  128. #define CCP_CODE(dp) ((dp)[0])
  129. #define CCP_ID(dp) ((dp)[1])
  130. #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
  131. #define CCP_HDRLEN 4
  132. #define CCP_OPT_CODE(dp) ((dp)[0])
  133. #define CCP_OPT_LENGTH(dp) ((dp)[1])
  134. #define CCP_OPT_MINLEN 2
  135. /*
  136. * Definitions for BSD-Compress.
  137. */
  138. #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
  139. #define CILEN_BSD_COMPRESS 3 /* length of config. option */
  140. /* Macros for handling the 3rd byte of the BSD-Compress config option. */
  141. #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
  142. #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
  143. #define BSD_CURRENT_VERSION 1 /* current version number */
  144. #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
  145. #define BSD_MIN_BITS 9 /* smallest code size supported */
  146. #define BSD_MAX_BITS 15 /* largest code size supported */
  147. /*
  148. * Definitions for Deflate.
  149. */
  150. #define CI_DEFLATE 26 /* config option for Deflate */
  151. #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
  152. #define CILEN_DEFLATE 4 /* length of its config option */
  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. * Definitions for MPPE.
  163. */
  164. #define CI_MPPE 18 /* config option for MPPE */
  165. #define CILEN_MPPE 6 /* length of config option */
  166. /*
  167. * Definitions for other, as yet unsupported, compression methods.
  168. */
  169. #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
  170. #define CILEN_PREDICTOR_1 2 /* length of its config option */
  171. #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
  172. #define CILEN_PREDICTOR_2 2 /* length of its config option */
  173. #endif /* _NET_PPP_COMP_H */