ROHC compression/decompression library
rohc.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010,2011,2012,2013,2014 Didier Barvaux
00003  * Copyright 2007,2009,2010,2012 Viveris Technologies
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 /**
00021  * @file rohc.h
00022  * @brief ROHC common definitions and routines
00023  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
00024  * @author Didier Barvaux <didier@barvaux.org>
00025  */
00026 
00027 #ifndef ROHC_H
00028 #define ROHC_H
00029 
00030 #ifdef __cplusplus
00031 extern "C"
00032 {
00033 #endif
00034 
00035 #include <stdlib.h>
00036 #ifndef __KERNEL__
00037 #  include <inttypes.h>
00038 #endif
00039 
00040 
00041 /** Macro that handles deprecated declarations gracefully */
00042 #if defined __GNUC__ && \
00043     (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
00044         /* __attribute__((deprecated(msg))) is supported by GCC 4.5 and later */
00045         #define ROHC_DEPRECATED(msg) __attribute__((deprecated(msg)))
00046 #elif defined __GNUC__ && \
00047       (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00048         /* __attribute__((deprecated)) is supported by GCC 3.1 and later */
00049         #define ROHC_DEPRECATED(msg) __attribute__((deprecated))
00050 #else
00051         /* no support */
00052         #define ROHC_DEPRECATED(msg)
00053 #endif
00054 
00055 
00056 /** Macro that handles DLL export declarations gracefully */
00057 #ifdef DLL_EXPORT /* passed by autotools on command line */
00058         #define ROHC_EXPORT __declspec(dllexport)
00059 #else
00060         #define ROHC_EXPORT 
00061 #endif
00062 
00063 
00064 
00065 /**
00066  * @brief The Ethertype assigned to the ROHC protocol by the IEEE
00067  *
00068  * @see http://standards.ieee.org/regauth/ethertype/eth.txt
00069  *
00070  * @ingroup rohc
00071  */
00072 #define ROHC_ETHERTYPE  0x22f1
00073 
00074 
00075 #if !defined(ROHC_ENABLE_DEPRECATED_API) || ROHC_ENABLE_DEPRECATED_API == 1
00076 
00077 /*
00078  * Below are some return codes:
00079  */
00080 
00081 /**
00082  * @brief Return code: the action was performed without problem
00083  * @ingroup rohc
00084  * @deprecated please do not use this constant anymore,
00085  *             use rohc_compress4() instead
00086  */
00087 #define ROHC_OK                     1
00088 
00089 /**
00090  * @brief Return code: the action failed because no context is defined
00091  * @ingroup rohc
00092  * @deprecated please do not use this constant anymore,
00093  *             use rohc_compress4() instead
00094  */
00095 #define ROHC_ERROR_NO_CONTEXT      -1
00096 
00097 /**
00098  * @brief Return code: the action failed due to an unattended or malformed packet
00099  * @ingroup rohc
00100  * @deprecated please do not use this constant anymore,
00101  *             use rohc_compress4() instead
00102  */
00103 #define ROHC_ERROR_PACKET_FAILED   -2
00104 
00105 /**
00106  * @brief Return code: the action failed because the packet only contains feedback info
00107  * @ingroup rohc
00108  * @deprecated please do not use this constant anymore,
00109  *             use rohc_compress4() instead
00110  */
00111 #define ROHC_FEEDBACK_ONLY         -3
00112 
00113 /**
00114  * @brief Return code: the action failed due to a CRC failure
00115  * @ingroup rohc
00116  * @deprecated please do not use this constant anymore,
00117  *             use rohc_compress4() instead
00118  */
00119 #define ROHC_ERROR_CRC             -4
00120 
00121 /**
00122  * @brief Return code: the action encountered a problem
00123  * @ingroup rohc
00124  * @deprecated please do not use this constant anymore,
00125  *             use rohc_compress4() instead
00126  */
00127 #define ROHC_ERROR                 -5
00128 
00129 /**
00130  * @brief Return code: the packet needs to be parsed again
00131  * @ingroup rohc
00132  * @deprecated please do not use this constant anymore,
00133  *             use rohc_compress4() instead
00134  */
00135 #define ROHC_NEED_REPARSE          -6
00136 
00137 /**
00138  * @brief Return code: the action succeeded but packet needs to be segmented
00139  * @ingroup rohc
00140  * @deprecated please do not use this constant anymore,
00141  *             use rohc_compress4() instead
00142  */
00143 #define ROHC_NEED_SEGMENT          -7
00144 
00145 /**
00146  * @brief Return code: the action succeeded but packet is a non-final segment
00147  * @ingroup rohc
00148  * @deprecated please do not use this constant anymore,
00149  *             use rohc_compress4() instead
00150  */
00151 #define ROHC_NON_FINAL_SEGMENT     -8
00152 
00153 #endif /* !ROHC_ENABLE_DEPRECATED_API */
00154 
00155 
00156 /**
00157  * @brief The status code of several functions in the library API
00158  *
00159  * @ingroup rohc
00160  */
00161 typedef enum
00162 {
00163         /** The action was successful */
00164         ROHC_STATUS_OK                = 0,
00165         /** The action was successful but packet needs to be segmented */
00166         ROHC_STATUS_SEGMENT           = 1,
00167         /** The action failed due to a malformed packet */
00168         ROHC_STATUS_MALFORMED         = 2,
00169         /** The action failed because no matching context exists */
00170         ROHC_STATUS_NO_CONTEXT        = 3,
00171         /** The action failed due to a CRC failure */
00172         ROHC_STATUS_BAD_CRC           = 4,
00173         /** The action failed because output buffer is too small */
00174         ROHC_STATUS_OUTPUT_TOO_SMALL  = 5,
00175         /** The action encountered an undefined problem */
00176         ROHC_STATUS_ERROR             = 6,
00177 
00178 } rohc_status_t;
00179 
00180 
00181 #if !defined(ROHC_ENABLE_DEPRECATED_API) || ROHC_ENABLE_DEPRECATED_API == 1
00182 
00183 /**
00184  * @brief ROHC operation modes (see 4.4 in the RFC 3095)
00185  *
00186  * If you add a new operation mode, please also add the corresponding textual
00187  * description in \ref rohc_get_mode_descr.
00188  *
00189  * @deprecated do not use this type anymore, use \ref rohc_mode_t instead
00190  *
00191  * @ingroup rohc
00192  *
00193  * @see rohc_mode_t
00194  */
00195 typedef enum
00196 {
00197         /// The Unidirectional mode (U-mode)
00198         U_MODE = 1,
00199         /// The Bidirectional Optimistic mode (O-mode)
00200         O_MODE = 2,
00201         /// The Bidirectional Reliable mode (R-mode)
00202         R_MODE = 3,
00203 } rohc_mode
00204         ROHC_DEPRECATED("please do not use this type anymore, "
00205                         "use rohc_mode_t instead");
00206 
00207 #endif /* !ROHC_ENABLE_DEPRECATED_API) */
00208 
00209 /**
00210  * @brief ROHC operation modes
00211  *
00212  * The different ROHC operation modes as defined in section 4.4 of RFC 3095.
00213  *
00214  * If you add a new operation mode, please also add the corresponding textual
00215  * description in \ref rohc_get_mode_descr.
00216  *
00217  * @ingroup rohc
00218  *
00219  * @see rohc_get_mode_descr
00220  */
00221 typedef enum
00222 {
00223         /** The Unidirectional mode (U-mode) */
00224         ROHC_U_MODE = 1,
00225         /** The Bidirectional Optimistic mode (O-mode) */
00226         ROHC_O_MODE = 2,
00227         /** The Bidirectional Reliable mode (R-mode) */
00228         ROHC_R_MODE = 3,
00229 
00230 } rohc_mode_t;
00231 
00232 
00233 /**
00234  * @brief The maximum value for large CIDs
00235  *
00236  * @ingroup rohc
00237  *
00238  * @see rohc_comp_new
00239  * @see rohc_c_set_max_cid
00240  * @see rohc_decomp_set_max_cid
00241  */
00242 #define ROHC_LARGE_CID_MAX  ((1 << 14) - 1) /* 2^14 - 1 = 16383 */
00243 
00244 /**
00245  * @brief The maximum value for small CIDs
00246  *
00247  * @ingroup rohc
00248  *
00249  * @see rohc_comp_new
00250  * @see rohc_c_set_max_cid
00251  * @see rohc_decomp_set_max_cid
00252  *
00253  * \par Example:
00254  * \snippet simple_rohc_program.c define ROHC compressor
00255  * \snippet simple_rohc_program.c create ROHC compressor
00256  */
00257 #define ROHC_SMALL_CID_MAX  15
00258 
00259 
00260 /**
00261  * @brief The different types of Context IDs (CID)
00262  *
00263  * The different types of Context IDs (CID) a ROHC compressor or a ROHC
00264  * decompressor may use.
00265  *
00266  * Possible values are:
00267  *  \li \ref ROHC_LARGE_CID : large CID means that a ROHC compressor or a ROHC
00268  *      decompressor may identify contexts with IDs in the range
00269  *      [0, \ref ROHC_LARGE_CID_MAX ], ie. it may uniquely identify at
00270  *      most \e ROHC_LARGE_CID_MAX + 1 streams.
00271  *  \li \ref ROHC_SMALL_CID : small CID means that a ROHC compressor or a ROHC
00272  *      decompressor may identify contexts with IDs in the range
00273  *      [0, \ref ROHC_SMALL_CID_MAX ], ie. it may uniquely identify at
00274  *      most \e ROHC_SMALL_CID_MAX + 1 streams.
00275  *
00276  * In short, you choose the CID type in function of the number of simultaneous
00277  * streams you have to compress efficiently.
00278  *
00279  * @see ROHC_SMALL_CID_MAX ROHC_LARGE_CID_MAX
00280  *
00281  * @ingroup rohc
00282  */
00283 typedef enum
00284 {
00285         /**
00286          * @brief The context uses large CID
00287          *
00288          * CID values shall be in the range [0, \ref ROHC_LARGE_CID_MAX].
00289          */
00290         ROHC_LARGE_CID,
00291         /**
00292          * @brief The context uses small CID
00293          *
00294          * CID value shall be in the range [0, \ref ROHC_SMALL_CID_MAX].
00295          */
00296         ROHC_SMALL_CID,
00297 
00298 } rohc_cid_type_t;
00299 
00300 
00301 /** A ROHC Context ID (CID) */
00302 typedef size_t rohc_cid_t;
00303 
00304 
00305 /*
00306  * ROHC profiles numbers allocated by the IANA (see 8 in the RFC 3095):
00307  */
00308 
00309 /**
00310  * @brief The different ROHC compression/decompression profiles
00311  *
00312  * If you add a new compression/decompression profile, please also add the
00313  * corresponding textual description in \ref rohc_get_profile_descr.
00314  *
00315  * @ingroup rohc
00316  *
00317  * @see rohc_get_profile_descr
00318  */
00319 typedef enum
00320 {
00321         /** The ROHC Uncompressed profile (RFC 3095, section 5.10) */
00322         ROHC_PROFILE_UNCOMPRESSED = 0x0000,
00323         /** The ROHC RTP profile (RFC 3095, section 8) */
00324         ROHC_PROFILE_RTP          = 0x0001,
00325         /** The ROHC UDP profile (RFC 3095, section 5.11) */
00326         ROHC_PROFILE_UDP          = 0x0002,
00327         /** The ROHC ESP profile (RFC 3095, section 5.12) */
00328         ROHC_PROFILE_ESP          = 0x0003,
00329         /** The ROHC IP-only profile (RFC 3843, section 5) */
00330         ROHC_PROFILE_IP           = 0x0004,
00331         /** The ROHC TCP profile (RFC 4996) */
00332         ROHC_PROFILE_TCP          = 0x0006,
00333         /** The ROHC UDP-Lite profile (RFC 4019, section 7) */
00334         ROHC_PROFILE_UDPLITE      = 0x0008,
00335 
00336 } rohc_profile_t;
00337 
00338 
00339 #if !defined(ROHC_ENABLE_DEPRECATED_API) || ROHC_ENABLE_DEPRECATED_API == 1
00340 
00341 /*
00342  * The different CRC types and tables for ROHC compression/decompression
00343  *
00344  * TODO API: remove these public constants since a private enum was created
00345  */
00346 
00347 /** The CRC-2 type (deprecated) */
00348 #define CRC_TYPE_2 1
00349 /** The CRC-3 type (deprecated) */
00350 #define CRC_TYPE_3 2
00351 /** The CRC-6 type (deprecated) */
00352 #define CRC_TYPE_6 3
00353 /** The CRC-7 type (deprecated) */
00354 #define CRC_TYPE_7 4
00355 /** The CRC-8 type (deprecated) */
00356 #define CRC_TYPE_8 5
00357 
00358 
00359 /* TODO API: remove these variables once compatibility is not needed anymore */
00360 
00361 /** The table to enable fast CRC-2 computation
00362  * @deprecated please do not use this variable anymore */
00363 extern unsigned char ROHC_EXPORT crc_table_2[256]
00364         ROHC_DEPRECATED("please do not use this variable anymore, simply drop it");
00365 
00366 /** The table to enable fast CRC-3 computation
00367  * @deprecated please do not use this variable anymore */
00368 extern unsigned char ROHC_EXPORT crc_table_3[256]
00369         ROHC_DEPRECATED("please do not use this variable anymore, simply drop it");
00370 
00371 /** The table to enable fast CRC-6 computation
00372  * @deprecated please do not use this variable anymore */
00373 extern unsigned char ROHC_EXPORT crc_table_6[256]
00374         ROHC_DEPRECATED("please do not use this variable anymore, simply drop it");
00375 
00376 /** The table to enable fast CRC-7 computation
00377  * @deprecated please do not use this variable anymore */
00378 extern unsigned char ROHC_EXPORT crc_table_7[256]
00379         ROHC_DEPRECATED("please do not use this variable anymore, simply drop it");
00380 
00381 /** The table to enable fast CRC-8 computation
00382  * @deprecated please do not use this variable anymore */
00383 extern unsigned char ROHC_EXPORT crc_table_8[256]
00384         ROHC_DEPRECATED("please do not use this variable anymore, simply drop it");
00385 
00386 #endif /* !ROHC_ENABLE_DEPRECATED_API) */
00387 
00388 
00389 /*
00390  * Prototypes of public up-to-date functions
00391  */
00392 
00393 char * ROHC_EXPORT rohc_version(void);
00394 
00395 const char * ROHC_EXPORT rohc_strerror(const rohc_status_t status)
00396         __attribute__((warn_unused_result));
00397 
00398 const char * ROHC_EXPORT rohc_get_mode_descr(const rohc_mode_t mode);
00399 
00400 const char * ROHC_EXPORT rohc_get_profile_descr(const rohc_profile_t profile)
00401         __attribute__((warn_unused_result));
00402 
00403 
00404 #if !defined(ROHC_ENABLE_DEPRECATED_API) || ROHC_ENABLE_DEPRECATED_API == 1
00405 
00406 /*
00407  * Prototypes of public deprecated functions
00408  *
00409  * TODO API: remove this function once compatibility is not needed anymore
00410  */
00411 
00412 int ROHC_EXPORT crc_get_polynom(int type)
00413         ROHC_DEPRECATED("please do not use this function anymore, simply drop it");
00414 
00415 void ROHC_EXPORT crc_init_table(unsigned char *table, unsigned char polynum)
00416         ROHC_DEPRECATED("please do not use this function anymore, simply drop it");
00417 
00418 #endif /* !ROHC_ENABLE_DEPRECATED_API) */
00419 
00420 
00421 #undef ROHC_EXPORT /* do not pollute outside this header */
00422 
00423 #ifdef __cplusplus
00424 }
00425 #endif
00426 
00427 #endif /* ROHC_H */
00428