ROHC compression/decompression library
rohc.h
Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 2 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * This program is distributed in the hope that it will be useful,
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  * GNU General Public License for more details.
00011  *
00012  * You should have received a copy of the GNU General Public License
00013  * along with this program; if not, write to the Free Software
00014  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  */
00016 
00017 /**
00018  * @file rohc.h
00019  * @brief ROHC common definitions and routines
00020  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
00021  * @author Didier Barvaux <didier@barvaux.org>
00022  * @author The hackers from ROHC for Linux
00023  */
00024 
00025 #ifndef ROHC_H
00026 #define ROHC_H
00027 
00028 /**
00029  * \mainpage
00030  *
00031  * <h2>Introduction</h2>
00032  * <p>The <a href="http://rohc-lib.org/" title="Official website">ROHC library</a>
00033  * provides an easy and robust way for applications to reduce their bandwidth
00034  * usage on network links with limited capacity.  Headers of network packets are
00035  * compressed with the ROHC protocol and algorithms.</p>
00036  * <p><a href="http://rohc-lib.org/wiki/doku.php?id=rohc-protocol"
00037  * title="An introduction to the ROHC protocol">RObust Header Compression
00038  * (ROHC)</a> is a set of standards defined by the <a href="http://www.ietf.org/"
00039  * title="The IETF website">IETF</a>. The ROHC library is a free, opensource and
00040  * efficient implementation of them. The list of features implemented is available
00041  * on a separate page: \ref features</p>
00042  * <ul>
00043  *   <li>Official website: <a href="http://rohc-lib.org/">
00044  *                          http://rohc-lib.org/</a></li>
00045  *   <li>Project page on Launchpad: <a href="http://rohc-lib.org/">
00046  *                          http://rohc-lib.org/</a></li>
00047  *   <li>Mailing list: <a href="mailto:rohc@lists.launchpad.net">
00048  *                      rohc@lists.launchpad.net</a></li>
00049  *   <li>Mailing list archives: <a href="http://lists.launchpad.net/rohc/">
00050  *                               http://lists.launchpad.net/rohc/</a></li>
00051  *   <li>Bugtracker: <a href="http://bugs.launchpad.net/rohc">
00052  *                    http://bugs.launchpad.net/rohc</a></li>
00053  * </ul>
00054  *
00055  * <h2>License</h2>
00056  * <p>The project is licensed under GPL2+.
00057  * See the <a href="http://bazaar.launchpad.net/%7Edidier-barvaux/rohc/main/annotate/head%3A/COPYING">COPYING</a>
00058  * and <a href="http://bazaar.launchpad.net/%7Edidier-barvaux/rohc/main/annotate/head%3A/AUTHORS">AUTHORS</a>
00059  * files for more details.</p>
00060  *
00061  * <h2>Libraries</h2>
00062  * <p>
00063  * The sources are in the src subdirectory. The sources are separated into
00064  * three libraries:
00065  *  <ul>
00066  *   <li>a library that contains the routines used for both the compression
00067  *       and the decompression processes</li>
00068  *   <li>a library that handles the compression process</li>
00069  *   <li>a library that handles the decompression process</li>
00070  *  </ul>
00071  * </p>
00072  * <p>See the <a href="http://bazaar.launchpad.net/%7Edidier-barvaux/rohc/main/annotate/head%3A/INSTALL"> INSTALL file</a>
00073  * to learn to build the libraries.</p>
00074  *
00075  * <h2>API documentation</h2>
00076  * <p>The APIs for ROHC common, compression and decompression are available on
00077  * separate pages:
00078  *  <ul>
00079  *    <li>\ref rohc_common</li>
00080  *    <li>\ref rohc_comp</li>
00081  *    <li>\ref rohc_decomp</li>
00082  *  </ul>
00083  * </p>
00084  *
00085  * <h2>Tests</h2>
00086  * <p>
00087  * Several tests may be run to check the library behaviour. See the
00088  * <a href="http://bazaar.launchpad.net/%7Edidier-barvaux/rohc/main/annotate/head%3A/INSTALL">INSTALL file</a> to learn how to use these tools.
00089  * </p>
00090  *
00091  * <h2>References</h2>
00092  * <dl style="padding-bottom: 1em;">
00093  *  <dt><a href="http://tools.ietf.org/html/rfc3095">RFC&nbsp;3095</a></dt>
00094  *  <dd>ROHC: Framework and four profiles: RTP, UDP, ESP, and uncompressed.</dd>
00095  *  <dt><a href="http://tools.ietf.org/html/rfc3096">RFC&nbsp;3096</a></dt>
00096  *  <dd>Requirements for robust IP/UDP/RTP header compression.</dd>
00097  *  <dt><a href="http://tools.ietf.org/html/rfc3843">RFC&nbsp;3843</a></dt>
00098  *  <dd>ROHC: A Compression Profile for IP.</dd>
00099  *  <dt><a href="http://tools.ietf.org/html/rfc4019">RFC&nbsp;4019</a></dt>
00100  *  <dd>ROHC: Profiles for User Datagram Protocol (UDP) Lite.</dd>
00101  *  <dt><a href="http://rohc-lib.org/">ROHC library</a></dt>
00102  *  <dd>The Open Source ROHC library described by the documentation you are
00103  *      currently reading.</dd>
00104  *  <dt><a href="http://rohc.sourceforge.net/">ROHC Linux</a></dt>
00105  *  <dd>A GPL-licensed implementation of ROHC over PPP for the 2.4 Linux kernel.
00106  *      The ROHC library started as a fork of this project.</dd>
00107  * </dl>
00108  */
00109 
00110 
00111 /**
00112  * \page features Library features
00113  *
00114  * <p>See the <a href="http://rohc-lib.org/wiki/doku.php?id=library-compliance-rfcs">dedicated Wiki page for more details</a>.</p>
00115  */
00116 
00117 
00118 /** Macro that handles deprecated declarations gracefully */
00119 #if defined __GNUC__ && \
00120     (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
00121         /* __attribute__((deprecated(msg))) is supported by GCC 4.5 and later */
00122         #define ROHC_DEPRECATED(msg) __attribute__((deprecated(msg)))
00123 #elif defined __GNUC__ && \
00124       (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00125         /* __attribute__((deprecated)) is supported by GCC 3.1 and later */
00126         #define ROHC_DEPRECATED(msg) __attribute__((deprecated))
00127 #else
00128         /* no support */
00129         #define ROHC_DEPRECATED(msg)
00130 #endif
00131 
00132 
00133 /** Macro that handles DLL export declarations gracefully */
00134 #ifdef DLL_EXPORT /* passed by autotools on command line */
00135         #define ROHC_EXPORT __declspec(dllexport)
00136 #else
00137         #define ROHC_EXPORT 
00138 #endif
00139 
00140 
00141 
00142 /**
00143  * @brief The Ethertype assigned to the ROHC protocol by the IEEE
00144  *
00145  * @see http://standards.ieee.org/regauth/ethertype/eth.txt
00146  */
00147 #define ROHC_ETHERTYPE  0x22f1
00148 
00149 
00150 /*
00151  * Below are some return codes:
00152  */
00153 
00154 /// Return code: the action done without problem
00155 #define ROHC_OK                     1
00156 /// Return code: the action can not proceed because no context is defined
00157 #define ROHC_ERROR_NO_CONTEXT      -1
00158 /// Return code: the action failed due to an unattended or malformed packet
00159 #define ROHC_ERROR_PACKET_FAILED   -2
00160 /// Return code: the action failed because the packet only contains feedback info
00161 #define ROHC_FEEDBACK_ONLY         -3
00162 /// Return code: the action failed due to a CRC failure
00163 #define ROHC_ERROR_CRC             -4
00164 /// Return code: the action encountered a problem
00165 #define ROHC_ERROR                 -5
00166 /// Return code: the packet needs to be parsed again
00167 #define ROHC_NEED_REPARSE          -6
00168 
00169 
00170 /**
00171  * @brief ROHC operation modes (see 4.4 in the RFC 3095)
00172  *
00173  * If you add a new operation mode, please also add the corresponding textual
00174  * description in \ref rohc_get_mode_descr.
00175  */
00176 typedef enum
00177 {
00178         /// The Unidirectional mode (U-mode)
00179         U_MODE = 1,
00180         /// The Bidirectional Optimistic mode (O-mode)
00181         O_MODE = 2,
00182         /// The Bidirectional Reliable mode (R-mode)
00183         R_MODE = 3,
00184 } rohc_mode;
00185 
00186 
00187 /** The maximum value for large CIDs */
00188 #define ROHC_LARGE_CID_MAX  ((1 << 14) - 1) /* 2^14 - 1 = 16383 */
00189 /** The maximum value for small CIDs */
00190 #define ROHC_SMALL_CID_MAX  15
00191 
00192 
00193 /**
00194  * @brief The different types of Context IDs (CID) a stream/context may use
00195  *
00196  * Possible values are: \ref ROHC_LARGE_CID, \ref ROHC_SMALL_CID.
00197  *
00198  * Small CID means CID in the \f$[0-ROHC\_SMALL\_CID\_MAX]\f$ interval.
00199  *
00200  * Large CID means CID in the \f$[0-ROHC\_LARGE\_CID\_MAX]\f$ interval.
00201  *
00202  * @see ROHC_SMALL_CID_MAX ROHC_LARGE_CID_MAX
00203  */
00204 typedef enum
00205 {
00206         /**
00207          * @brief The context uses large CID
00208          *
00209          * Value in the \f$[0-ROHC\_LARGE\_CID\_MAX]\f$ interval.
00210          */
00211         ROHC_LARGE_CID,
00212         /**
00213          * @brief The context uses small CID
00214          *
00215          * Value in the \f$[0-ROHC\_SMALL\_CID\_MAX]\f$ interval.
00216          */
00217         ROHC_SMALL_CID,
00218 } rohc_cid_type_t;
00219 
00220 
00221 /**
00222  * @brief ROHC medium (CID characteristics).
00223  */
00224 struct medium
00225 {
00226         /** The CID type: large or small */
00227         rohc_cid_type_t cid_type;
00228 
00229         /// The maximum CID value
00230         int max_cid;
00231 };
00232 
00233 
00234 /*
00235  * ROHC profiles numbers allocated by the IANA (see 8 in the RFC 3095):
00236  */
00237 
00238 /// The number allocated for the ROHC Uncompressed profile (RFC 3095, 5.10)
00239 #define ROHC_PROFILE_UNCOMPRESSED  0x0000
00240 /// The number allocated for the ROHC RTP profile (RFC 3095, 8)
00241 #define ROHC_PROFILE_RTP           0x0001
00242 /// The number allocated for the ROHC UDP profile (RFC 3095, 5.11)
00243 #define ROHC_PROFILE_UDP           0x0002
00244 /// The number allocated for the ROHC ESP profile (RFC 3095, 5.12)
00245 #define ROHC_PROFILE_ESP           0x0003
00246 /// The number allocated for the ROHC IP-only profile (see 5 in the RFC 3843)
00247 #define ROHC_PROFILE_IP            0x0004
00248 /// The number allocated for the ROHC UDP-Lite profile (see 7 in the RFC 4019)
00249 #define ROHC_PROFILE_UDPLITE       0x0008
00250 
00251 
00252 /*
00253  * The limits for the compressor states changes:
00254  */
00255 
00256 /// @brief The maximal number of packets sent in > IR states (= FO and SO
00257 ///        states) before changing back the state to IR (periodic refreshes)
00258 #define CHANGE_TO_IR_COUNT  1700
00259 
00260 /// @brief The maximal number of packets sent in > FO states (= SO state)
00261 ///        before changing back the state to FO (periodic refreshes)
00262 #define CHANGE_TO_FO_COUNT  700
00263 
00264 /// @brief Defines the minimal number of packets that must be sent while
00265 ///        in IR state before being able to switch to the FO state
00266 #define MAX_IR_COUNT  3
00267 
00268 /// @brief Defines the minimal number of packets that must be sent while
00269 ///        in FO state before being able to switch to the SO state
00270 #define MAX_FO_COUNT  3
00271 
00272 /// @brief Defines the minimal number of packets that must be sent while in
00273 ///        INIT_STRIDE state before being able to switch to the SEND_SCALED
00274 ///        state
00275 #define ROHC_INIT_TS_STRIDE_MIN  3U
00276 
00277 
00278 /*
00279  * The different CRC types and tables for ROHC compression/decompression
00280  *
00281  * TODO API: remove these public constants since a private enum was created
00282  */
00283 
00284 /** The CRC-2 type (deprecated) */
00285 #define CRC_TYPE_2 1
00286 /** The CRC-3 type (deprecated) */
00287 #define CRC_TYPE_3 2
00288 /** The CRC-6 type (deprecated) */
00289 #define CRC_TYPE_6 3
00290 /** The CRC-7 type (deprecated) */
00291 #define CRC_TYPE_7 4
00292 /** The CRC-8 type (deprecated) */
00293 #define CRC_TYPE_8 5
00294 
00295 
00296 /* TODO API: remove these variables once compatibility is not needed anymore */
00297 
00298 /** The table to enable fast CRC-2 computation
00299  * @deprecated please do not use this variable anymore */
00300 extern unsigned char ROHC_EXPORT crc_table_2[256]
00301         ROHC_DEPRECATED("please do not use this variable anymore, simply drop it");
00302 
00303 /** The table to enable fast CRC-3 computation
00304  * @deprecated please do not use this variable anymore */
00305 extern unsigned char ROHC_EXPORT crc_table_3[256]
00306         ROHC_DEPRECATED("please do not use this variable anymore, simply drop it");
00307 
00308 /** The table to enable fast CRC-6 computation
00309  * @deprecated please do not use this variable anymore */
00310 extern unsigned char ROHC_EXPORT crc_table_6[256]
00311         ROHC_DEPRECATED("please do not use this variable anymore, simply drop it");
00312 
00313 /** The table to enable fast CRC-7 computation
00314  * @deprecated please do not use this variable anymore */
00315 extern unsigned char ROHC_EXPORT crc_table_7[256]
00316         ROHC_DEPRECATED("please do not use this variable anymore, simply drop it");
00317 
00318 /** The table to enable fast CRC-8 computation
00319  * @deprecated please do not use this variable anymore */
00320 extern unsigned char ROHC_EXPORT crc_table_8[256]
00321         ROHC_DEPRECATED("please do not use this variable anymore, simply drop it");
00322 
00323 
00324 /*
00325  * Prototypes of public up-to-date functions
00326  */
00327 
00328 char * ROHC_EXPORT rohc_version(void);
00329 
00330 const char * ROHC_EXPORT rohc_get_mode_descr(const rohc_mode mode);
00331 
00332 
00333 /*
00334  * Prototypes of public deprecated functions
00335  *
00336  * TODO API: remove this function once compatibility is not needed anymore
00337  */
00338 
00339 int ROHC_EXPORT crc_get_polynom(int type)
00340         ROHC_DEPRECATED("please do not use this function anymore, simply drop it");
00341 
00342 void ROHC_EXPORT crc_init_table(unsigned char *table, unsigned char polynum)
00343         ROHC_DEPRECATED("please do not use this function anymore, simply drop it");
00344 
00345 
00346 #undef ROHC_EXPORT /* do not pollute outside this header */
00347 
00348 #endif
00349