ROHC compression/decompression library
rohc_decomp_internals.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012,2013,2014 Didier Barvaux
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 /**
00020  * @file    rohc_decomp_internals.h
00021  * @brief   Internal structures for ROHC decompression
00022  * @author  Didier Barvaux <didier.barvaux@toulouse.viveris.com>
00023  * @author  Didier Barvaux <didier@barvaux.org>
00024  * @author  David Moreau from TAS
00025  */
00026 
00027 #ifndef ROHC_DECOMP_INTERNALS_H
00028 #define ROHC_DECOMP_INTERNALS_H
00029 
00030 #include "rohc_internal.h"
00031 #include "rohc_decomp.h"
00032 #include "rohc_stats.h"
00033 
00034 
00035 
00036 /*
00037  * Constants and macros
00038  */
00039 
00040 
00041 /** The number of ROHC profiles ready to be used */
00042 #define D_NUM_PROFILES 7U
00043 
00044 
00045 /** Print a warning trace for the given decompression context */
00046 #define rohc_decomp_warn(context, format, ...) \
00047         rohc_warning((context)->decompressor, ROHC_TRACE_DECOMP, \
00048                      (context)->profile->id, \
00049                      format, ##__VA_ARGS__)
00050 
00051 /** Print a debug trace for the given decompression context */
00052 #define rohc_decomp_debug(context, format, ...) \
00053         rohc_debug((context)->decompressor, ROHC_TRACE_DECOMP, \
00054                    (context)->profile->id, \
00055                    format, ##__VA_ARGS__)
00056 
00057 
00058 /*
00059  * Definitions of ROHC compression structures
00060  */
00061 
00062 
00063 /**
00064  * @brief Some compressor statistics
00065  */
00066 struct d_statistics
00067 {
00068         /* The number of received packets */
00069         unsigned long received;
00070         /* The number of bad decompressions due to wrong CRC */
00071         unsigned long failed_crc;
00072         /* The number of bad decompressions due to being in the No Context state */
00073         unsigned long failed_no_context;
00074         /* The number of bad decompressions */
00075         unsigned long failed_decomp;
00076 
00077         /** The cumulative size of the compressed packets */
00078         unsigned long total_compressed_size;
00079         /** The cumulative size of the uncompressed packets */
00080         unsigned long total_uncompressed_size;
00081 };
00082 
00083 
00084 /**
00085  * @brief The ROHC decompressor
00086  */
00087 struct rohc_decomp
00088 {
00089 #if !defined(ROHC_ENABLE_DEPRECATED_API) || ROHC_ENABLE_DEPRECATED_API == 1
00090         /** The compressor associated with the decompressor */
00091         struct rohc_comp *compressor;
00092         /** Whether to handle feedback delivery internally for compatibility with
00093          *  pre-1.7.0 versions */
00094         bool do_auto_feedback_delivery;
00095 #endif /* !ROHC_ENABLE_DEPRECATED_API */
00096 
00097         /** The medium associated with the decompressor */
00098         struct rohc_medium medium;
00099 
00100         /** Enabled/disabled features for the decompressor */
00101         rohc_decomp_features_t features;
00102 
00103         /** Which profiles are enabled and with one are not? */
00104         bool enabled_profiles[D_NUM_PROFILES];
00105 
00106         /** The array of decompression contexts that use the decompressor */
00107         struct rohc_decomp_ctxt **contexts;
00108         /** The number of decompression contexts in use */
00109         size_t num_contexts_used;
00110         /** The last decompression context used by the decompressor */
00111         struct rohc_decomp_ctxt *last_context;
00112 
00113         /**
00114          * @brief The feedback interval limits
00115          *
00116          * maxval can be updated by the user thanks to the user_interactions
00117          * function.
00118          *
00119          * @see user_interactions
00120          */
00121         unsigned int maxval;
00122         /** Variable related to the feedback interval */
00123         unsigned int errval;
00124         /** Variable related to the feedback interval */
00125         unsigned int okval;
00126         /** Variable related to the feedback interval */
00127         int curval;
00128 
00129 
00130         /* segment-related variables */
00131 
00132 /** The maximal value for MRRU */
00133 #define ROHC_MAX_MRRU 65535
00134         /** The Reconstructed Reception Unit */
00135         unsigned char rru[ROHC_MAX_MRRU];
00136         /** The length (in bytes) of the Reconstructed Reception Unit */
00137         size_t rru_len;
00138         /** The Maximum Reconstructed Reception Unit (MRRU) */
00139         size_t mrru;
00140 
00141 
00142         /* CRC-related variables: */
00143 
00144         /** The table to enable fast CRC-3 computation */
00145         unsigned char crc_table_3[256];
00146         /** The table to enable fast CRC-7 computation */
00147         unsigned char crc_table_7[256];
00148         /** The table to enable fast CRC-8 computation */
00149         unsigned char crc_table_8[256];
00150 
00151 
00152         /** Some statistics about the decompression processes */
00153         struct d_statistics stats;
00154 
00155 #if !defined(ROHC_ENABLE_DEPRECATED_API) || ROHC_ENABLE_DEPRECATED_API == 1
00156         /** The old callback function used to manage traces */
00157         rohc_trace_callback_t trace_callback;
00158 #endif
00159         /** The new callback function used to manage traces */
00160         rohc_trace_callback2_t trace_callback2;
00161         /** The private context of the callback function used to manage traces */
00162         void *trace_callback_priv;
00163 };
00164 
00165 
00166 /**
00167  * @brief The ROHC decompression context
00168  */
00169 struct rohc_decomp_ctxt
00170 {
00171         /** The Context IDentifier (CID) */
00172         rohc_cid_t cid;
00173 
00174         /** The associated decompressor */
00175         struct rohc_decomp *decompressor;
00176 
00177         /** The associated profile */
00178         const struct rohc_decomp_profile *profile;
00179         /** Profile-specific data, defined by the profiles */
00180         void *specific;
00181 
00182         /** The operation mode in which the context operates */
00183         rohc_mode_t mode;
00184         /** The operation state in which the context operates */
00185         rohc_decomp_state_t state;
00186 
00187         /** Whether the operation modes at compressor and decompressor mismatch */
00188         bool do_change_mode;
00189 
00190         /** Usage timestamp */
00191         unsigned int latest_used;
00192         /** Usage timestamp */
00193         unsigned int first_used;
00194 
00195         /** Variable related to feedback interval */
00196         int curval;
00197 
00198         /* below are some statistics */
00199 
00200         /** The type of the last decompressed ROHC packet */
00201         rohc_packet_t packet_type;
00202 
00203         /** The average size of the uncompressed packets */
00204         int total_uncompressed_size;
00205         /** The average size of the compressed packets */
00206         int total_compressed_size;
00207         /** The average size of the uncompressed headers */
00208         int header_uncompressed_size;
00209         /** The average size of the compressed headers */
00210         int header_compressed_size;
00211 
00212         /* The number of received packets */
00213         int num_recv_packets;
00214 #if !defined(ROHC_ENABLE_DEPRECATED_API) || ROHC_ENABLE_DEPRECATED_API == 1
00215         /* The number of received IR packets */
00216         int num_recv_ir;
00217         /* The number of received IR-DYN packets */
00218         int num_recv_ir_dyn;
00219         /* The number of sent feedbacks */
00220         int num_sent_feedbacks;
00221 
00222         /* The number of decompression failures */
00223         int num_decomp_failures;
00224 #endif
00225         /** The number of successful corrections upon CRC failure */
00226         unsigned long corrected_crc_failures;
00227         /** The number of successful corrections of SN wraparound upon CRC failure */
00228         unsigned long corrected_sn_wraparounds;
00229         /** The number of successful corrections of incorrect SN updates upon CRC
00230          *  failure */
00231         unsigned long corrected_wrong_sn_updates;
00232 
00233 #if !defined(ROHC_ENABLE_DEPRECATED_API) || ROHC_ENABLE_DEPRECATED_API == 1
00234         /* The size of the last 16 uncompressed packets */
00235         struct rohc_stats total_16_uncompressed;
00236         /* The size of the last 16 compressed packets */
00237         struct rohc_stats total_16_compressed;
00238         /* The size of the last 16 uncompressed headers */
00239         struct rohc_stats header_16_uncompressed;
00240         /* The size of the last 16 compressed headers */
00241         struct rohc_stats header_16_compressed;
00242 #endif
00243 
00244         /** The number of (possible) lost packet(s) before last packet */
00245         unsigned long nr_lost_packets;
00246         /** The number of packet(s) before the last packet if late */
00247         unsigned long nr_misordered_packets;
00248         /** Is last packet a (possible) duplicated packet? */
00249         bool is_duplicated;
00250 };
00251 
00252 
00253 /**
00254  * @brief The ROHC decompression profile.
00255  *
00256  * The object defines a ROHC profile. Each field must be filled in
00257  * for each new profile.
00258  */
00259 struct rohc_decomp_profile
00260 {
00261         /* The profile ID as reserved by IANA */
00262         const rohc_profile_t id;
00263 
00264         /* @brief The handler used to create the profile-specific part of the
00265          *        decompression context */
00266         void * (*new_context)(const struct rohc_decomp_ctxt *const context);
00267 
00268         /* @brief The handler used to destroy the profile-specific part of the
00269          *        decompression context */
00270         void (*free_context)(void *const context);
00271 
00272         /* The handler used to decode a ROHC packet */
00273         rohc_status_t (*decode)(struct rohc_decomp *const decomp,
00274                                 struct rohc_decomp_ctxt *const context,
00275                                 const struct rohc_buf rohc_packet,
00276                                 const size_t add_cid_len,
00277                                 const size_t large_cid_len,
00278                                 struct rohc_buf *const uncomp_packet,
00279                                 rohc_packet_t *const packet_type)
00280                 __attribute__((warn_unused_result, nonnull(1, 2, 6, 7)));
00281 
00282         /** The handler used to detect the type of the ROHC packet */
00283         rohc_packet_t (*detect_pkt_type)(const struct rohc_decomp_ctxt *const context,
00284                                          const uint8_t *const rohc_packet,
00285                                          const size_t rohc_length,
00286                                          const size_t large_cid_len)
00287                 __attribute__((warn_unused_result, nonnull(1, 2)));
00288 
00289         /* The handler used to retrieve the Sequence Number (SN) */
00290         uint32_t (*get_sn)(const struct rohc_decomp_ctxt *const context);
00291 };
00292 
00293 
00294 #endif
00295