ROHC compression/decompression library
rohc_decomp.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.h
00019  * @brief ROHC decompression routines
00020  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
00021  * @author The hackers from ROHC for Linux
00022  * @author David Moreau from TAS
00023  */
00024 
00025 #ifndef DECOMP_H
00026 #define DECOMP_H
00027 
00028 #include "rohc.h"
00029 #include "rohc_comp.h"
00030 
00031 /// The number of ROHC profiles ready to be used
00032 #define D_NUM_PROFILES 6
00033 
00034 
00035 /// ROHC decompressor states (see 4.3.2 in the RFC 3095)
00036 typedef enum
00037 {
00038         /// The No Context state
00039         NO_CONTEXT = 1,
00040         /// The Static Context state
00041         STATIC_CONTEXT = 2,
00042         /// The Full Context state
00043         FULL_CONTEXT = 3,
00044 } rohc_d_state;
00045 
00046 
00047 /**
00048  * @brief Some compressor statistics.
00049  */
00050 struct d_statistics
00051 {
00052         /// The number of received packets
00053         unsigned int received;
00054         /// The number of bad decompressions due to wrong CRC
00055         unsigned int failed_crc;
00056         /// The number of bad decompressions due to being in the No Context state
00057         unsigned int failed_no_context;
00058         /// The number of bad decompressions
00059         unsigned int failed_decomp;
00060         /// The number of feedback packets sent to the associated compressor
00061         unsigned int feedbacks;
00062 };
00063 
00064 
00065 /**
00066  * @brief The ROHC decompressor.
00067  */
00068 struct rohc_decomp
00069 {
00070         /// The compressor associated with the decompressor
00071         struct rohc_comp *compressor;
00072 
00073         /// The medium associated with the decompressor
00074         struct medium medium;
00075 
00076         /// The array of decompression contexts that use the decompressor
00077         struct d_context **contexts;
00078         /// The last decompression context used by the decompressor
00079         struct d_context *last_context;
00080 
00081         /**
00082          * @brief The feedback interval limits
00083          *
00084          * maxval can be updated by the user thanks to the user_interactions
00085          * function.
00086          *
00087          * @see user_interactions
00088          */
00089         unsigned int maxval;
00090         /// Variable related to the feedback interval
00091         unsigned int errval;
00092         /// Variable related to the feedback interval
00093         unsigned int okval;
00094         /// Variable related to the feedback interval
00095         int curval;
00096 
00097 
00098         /* CRC-related variables: */
00099 
00100         /** The table to enable fast CRC-2 computation */
00101         unsigned char crc_table_2[256];
00102         /** The table to enable fast CRC-3 computation */
00103         unsigned char crc_table_3[256];
00104         /** The table to enable fast CRC-6 computation */
00105         unsigned char crc_table_6[256];
00106         /** The table to enable fast CRC-7 computation */
00107         unsigned char crc_table_7[256];
00108         /** The table to enable fast CRC-8 computation */
00109         unsigned char crc_table_8[256];
00110 
00111 
00112         /// Some statistics about the decompression processes
00113         struct d_statistics stats;
00114 };
00115 
00116 
00117 /**
00118  * @brief The ROHC decompression context.
00119  */
00120 struct d_context
00121 {
00122         /// The associated profile
00123         struct d_profile *profile;
00124         /// Profile-specific data, defined by the profiles
00125         void *specific;
00126 
00127         /// The operation mode in which the context operates: U_MODE, O_MODE, R_MODE
00128         rohc_mode mode;
00129         /// @brief The operation state in which the context operates: NO_CONTEXT,
00130         ///        STATIC_CONTEXT, FULL_CONTEXT
00131         rohc_d_state state;
00132 
00133         /// Usage timestamp
00134         unsigned int latest_used;
00135         /// Usage timestamp
00136         unsigned int first_used;
00137 
00138         /// Variable related to feedback interval
00139         int curval;
00140 
00141         /* below are some statistics */
00142 
00143         /// The average size of the uncompressed packets
00144         int total_uncompressed_size;
00145         /// The average size of the compressed packets
00146         int total_compressed_size;
00147         /// The average size of the uncompressed headers
00148         int header_uncompressed_size;
00149         /// The average size of the compressed headers
00150         int header_compressed_size;
00151 
00152         /// The number of received packets
00153         int num_recv_packets;
00154         /// The number of received IR packets
00155         int num_recv_ir;
00156         /// The number of received IR-DYN packets
00157         int num_recv_ir_dyn;
00158         /// The number of sent feedbacks
00159         int num_sent_feedbacks;
00160 
00161         /// The number of compression failures
00162         int num_decomp_failures;
00163         /// The number of decompression failures
00164         int num_decomp_repairs;
00165 
00166         /// The size of the last 16 uncompressed packets
00167         struct c_wlsb *total_16_uncompressed;
00168         /// The size of the last 16 compressed packets
00169         struct c_wlsb *total_16_compressed;
00170         /// The size of the last 16 uncompressed headers
00171         struct c_wlsb *header_16_uncompressed;
00172         /// The size of the last 16 compressed headers
00173         struct c_wlsb *header_16_compressed;
00174 };
00175 
00176 
00177 /**
00178  * @brief The ROHC decompression profile.
00179  *
00180  * The object defines a ROHC profile. Each field must be filled in
00181  * for each new profile.
00182  */
00183 struct d_profile
00184 {
00185         /// The profile ID as reserved by IANA
00186         int id;
00187 
00188         /// A string that describes the profile
00189         char *description;
00190 
00191         /// The handler used to decode one IR, IR-DYN and UO* packets
00192         int (*decode)(struct rohc_decomp *decomp,
00193                       struct d_context *context,
00194                       const unsigned char *const rohc_packet,
00195                       const unsigned int rohc_length,
00196                       const size_t add_cid_len,
00197                       const size_t large_cid_len,
00198                       unsigned char *dest);
00199 
00200         /// @brief The handler used to create the profile-specific part of the
00201         ///        decompression context
00202         void * (*allocate_decode_data)(void);
00203 
00204         /// @brief The handler used to destroy the profile-specific part of the
00205         ///        decompression context
00206         void (*free_decode_data)(void *);
00207 
00208         /// The handler used to retrieve the Sequence Number (SN)
00209         int (*get_sn)(struct d_context *context);
00210 };
00211 
00212 
00213 /*
00214  * Functions related to decompressor:
00215  */
00216 
00217 struct rohc_decomp * rohc_alloc_decompressor(struct rohc_comp *compressor);
00218 void rohc_free_decompressor(struct rohc_decomp *decomp);
00219 
00220 int rohc_decompress(struct rohc_decomp *decomp, unsigned char *ibuf, int isize,
00221                     unsigned char *obuf, int osize);
00222 int rohc_decompress_both(struct rohc_decomp *decomp, unsigned char *ibuf,
00223                          int isize, unsigned char *obuf, int osize, int large)
00224         ROHC_DEPRECATED("please do not use this function anymore, use "
00225                         "rohc_decomp_set_cid_type() and rohc_decomp_set_max_cid() "
00226                         "instead");
00227 
00228 
00229 /*
00230  * Functions related to context:
00231  */
00232 
00233 struct d_context * find_context(struct rohc_decomp *decomp, int cid);
00234 struct d_context * context_create(struct rohc_decomp *decomp,
00235                                   int with_cid,
00236                                   struct d_profile *profile);
00237 void context_free(struct d_context *context);
00238 
00239 
00240 /*
00241  * Functions related to feedback:
00242  */
00243 
00244 void d_change_mode_feedback(struct rohc_decomp *decomp, struct d_context *context);
00245 
00246 
00247 /*
00248  * Functions related to statistics:
00249  */
00250 
00251 int rohc_d_statistics(struct rohc_decomp *decomp, unsigned int indent,
00252                       char *buffer);
00253 int rohc_d_context(struct rohc_decomp *decomp, int index, unsigned int indent,
00254                    char *buffer);
00255 void clear_statistics(struct rohc_decomp *decomp);
00256 const char * rohc_decomp_get_state_descr(const rohc_d_state state);
00257 
00258 
00259 /*
00260  * Functions related to user interaction:
00261  */
00262 
00263 void user_interactions(struct rohc_decomp *decomp, int feedback_maxval);
00264 
00265 bool rohc_decomp_set_cid_type(struct rohc_decomp *const decomp,
00266                               const rohc_cid_type_t cid_type)
00267         __attribute__((nonnull(1), warn_unused_result));
00268 
00269 
00270 bool rohc_decomp_set_max_cid(struct rohc_decomp *const decomp,
00271                              const size_t max_cid)
00272         __attribute__((nonnull(1), warn_unused_result));
00273 
00274 #endif
00275