ROHC compression/decompression library
rohc_decomp_internals.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_decomp_internals.h
00019  * @brief   Internal structures for ROHC decompression
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  * @author  David Moreau from TAS
00024  */
00025 
00026 #ifndef ROHC_DECOMP_INTERNALS_H
00027 #define ROHC_DECOMP_INTERNALS_H
00028 
00029 #include "rohc.h" /* for struct medium */
00030 #include "rohc_comp.h"
00031 
00032 
00033 
00034 /*
00035  * Constants and macros
00036  */
00037 
00038 
00039 /** The number of ROHC profiles ready to be used */
00040 #define D_NUM_PROFILES 6
00041 
00042 /** Print a debug trace for the given decompression context */
00043 #define rohc_decomp_debug(context, format, ...) \
00044         rohc_debug((context)->decompressor, ROHC_TRACE_DECOMP, \
00045                    (context)->profile->id, \
00046                    format, ##__VA_ARGS__)
00047 
00048 
00049 /*
00050  * Definitions of ROHC compression structures
00051  */
00052 
00053 
00054 /**
00055  * @brief Some compressor statistics
00056  */
00057 struct d_statistics
00058 {
00059         /* The number of received packets */
00060         unsigned int received;
00061         /* The number of bad decompressions due to wrong CRC */
00062         unsigned int failed_crc;
00063         /* The number of bad decompressions due to being in the No Context state */
00064         unsigned int failed_no_context;
00065         /* The number of bad decompressions */
00066         unsigned int failed_decomp;
00067         /* The number of feedback packets sent to the associated compressor */
00068         unsigned int feedbacks;
00069 };
00070 
00071 
00072 /**
00073  * @brief The ROHC decompressor
00074  */
00075 struct rohc_decomp
00076 {
00077         /** The compressor associated with the decompressor */
00078         struct rohc_comp *compressor;
00079 
00080         /** The medium associated with the decompressor */
00081         struct medium medium;
00082 
00083         /** The array of decompression contexts that use the decompressor */
00084         struct d_context **contexts;
00085         /** The last decompression context used by the decompressor */
00086         struct d_context *last_context;
00087 
00088         /**
00089          * @brief The feedback interval limits
00090          *
00091          * maxval can be updated by the user thanks to the user_interactions
00092          * function.
00093          *
00094          * @see user_interactions
00095          */
00096         unsigned int maxval;
00097         /** Variable related to the feedback interval */
00098         unsigned int errval;
00099         /** Variable related to the feedback interval */
00100         unsigned int okval;
00101         /** Variable related to the feedback interval */
00102         int curval;
00103 
00104 
00105         /* segment-related variables */
00106 
00107 /** The maximal value for MRRU */
00108 #define ROHC_MAX_MRRU 65535
00109         /** The Reconstructed Reception Unit */
00110         unsigned char rru[ROHC_MAX_MRRU];
00111         /** The length (in bytes) of the Reconstructed Reception Unit */
00112         size_t rru_len;
00113         /** The Maximum Reconstructed Reception Unit (MRRU) */
00114         size_t mrru;
00115 
00116 
00117         /* CRC-related variables: */
00118 
00119         /** The table to enable fast CRC-2 computation */
00120         unsigned char crc_table_2[256];
00121         /** The table to enable fast CRC-3 computation */
00122         unsigned char crc_table_3[256];
00123         /** The table to enable fast CRC-6 computation */
00124         unsigned char crc_table_6[256];
00125         /** The table to enable fast CRC-7 computation */
00126         unsigned char crc_table_7[256];
00127         /** The table to enable fast CRC-8 computation */
00128         unsigned char crc_table_8[256];
00129 
00130 
00131         /** Some statistics about the decompression processes */
00132         struct d_statistics stats;
00133 
00134         /** The callback function used to get log messages */
00135         rohc_trace_callback_t trace_callback;
00136 };
00137 
00138 
00139 /**
00140  * @brief The ROHC decompression context
00141  */
00142 struct d_context
00143 {
00144         /** The Context IDentifier (CID) */
00145         unsigned int cid;
00146 
00147         /** The associated decompressor */
00148         struct rohc_decomp *decompressor;
00149 
00150         /** The associated profile */
00151         struct d_profile *profile;
00152         /** Profile-specific data, defined by the profiles */
00153         void *specific;
00154 
00155         /** The operation mode in which the context operates */
00156         rohc_mode mode;
00157         /** The operation state in which the context operates */
00158         rohc_d_state state;
00159 
00160         /** Usage timestamp */
00161         unsigned int latest_used;
00162         /** Usage timestamp */
00163         unsigned int first_used;
00164 
00165         /** Variable related to feedback interval */
00166         int curval;
00167 
00168         /* below are some statistics */
00169 
00170         /** The average size of the uncompressed packets */
00171         int total_uncompressed_size;
00172         /** The average size of the compressed packets */
00173         int total_compressed_size;
00174         /** The average size of the uncompressed headers */
00175         int header_uncompressed_size;
00176         /** The average size of the compressed headers */
00177         int header_compressed_size;
00178 
00179         /* The number of received packets */
00180         int num_recv_packets;
00181         /* The number of received IR packets */
00182         int num_recv_ir;
00183         /* The number of received IR-DYN packets */
00184         int num_recv_ir_dyn;
00185         /* The number of sent feedbacks */
00186         int num_sent_feedbacks;
00187 
00188         /* The number of compression failures */
00189         int num_decomp_failures;
00190         /* The number of decompression failures */
00191         int num_decomp_repairs;
00192 
00193         /* The size of the last 16 uncompressed packets */
00194         struct c_wlsb *total_16_uncompressed;
00195         /* The size of the last 16 compressed packets */
00196         struct c_wlsb *total_16_compressed;
00197         /* The size of the last 16 uncompressed headers */
00198         struct c_wlsb *header_16_uncompressed;
00199         /* The size of the last 16 compressed headers */
00200         struct c_wlsb *header_16_compressed;
00201 
00202         /** The number of (possible) lost packet(s) before last packet */
00203         unsigned long nr_lost_packets;
00204         /** The number of packet(s) before the last packet if late */
00205         unsigned long nr_misordered_packets;
00206         /** Is last packet a (possible) duplicated packet? */
00207         bool is_duplicated;
00208 };
00209 
00210 
00211 /**
00212  * @brief The ROHC decompression profile.
00213  *
00214  * The object defines a ROHC profile. Each field must be filled in
00215  * for each new profile.
00216  */
00217 struct d_profile
00218 {
00219         /* The profile ID as reserved by IANA */
00220         int id;
00221 
00222         /* A string that describes the profile */
00223         char *description;
00224 
00225         /* The handler used to decode a ROHC packet */
00226         int (*decode)(struct rohc_decomp *decomp,
00227                       struct d_context *context,
00228                       const unsigned char *const rohc_packet,
00229                       const unsigned int rohc_length,
00230                       const size_t add_cid_len,
00231                       const size_t large_cid_len,
00232                       unsigned char *dest);
00233 
00234         /* @brief The handler used to create the profile-specific part of the
00235          *        decompression context */
00236         void * (*allocate_decode_data)(const struct d_context *const context);
00237 
00238         /* @brief The handler used to destroy the profile-specific part of the
00239          *        decompression context */
00240         void (*free_decode_data)(void *const context);
00241 
00242         /* The handler used to retrieve the Sequence Number (SN) */
00243         int (*get_sn)(struct d_context *const context);
00244 };
00245 
00246 
00247 
00248 /*
00249  * Prototypes of library-private functions
00250  */
00251 
00252 void d_change_mode_feedback(struct rohc_decomp *decomp,
00253                             struct d_context *context);
00254 
00255 
00256 #endif
00257