ROHC compression/decompression library
|
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 5 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 Decompression-related data. 00049 * 00050 * This object stores the information related to the decompression of one 00051 * ROHC packet (CID and context for example). The lifetime of this object is 00052 * the time needed to decompress one single packet. 00053 */ 00054 struct d_decode_data 00055 { 00056 /// The Context ID of the context to which the packet is related 00057 int cid; 00058 /// Whether the ROHC packet uses add-CID or not 00059 int addcidUsed; 00060 /// Whether the ROHC packet uses large CID or not 00061 int largecidUsed; 00062 /// The size (in bytes) of the large CID field 00063 unsigned int large_cid_size; 00064 /// The context to which the packet is related 00065 struct d_context *active; 00066 }; 00067 00068 00069 /** 00070 * @brief Some compressor statistics. 00071 */ 00072 struct d_statistics 00073 { 00074 /// The number of received packets 00075 unsigned int packets_received; 00076 /// The number of bad decompressions due to wrong CRC 00077 unsigned int packets_failed_crc; 00078 /// The number of bad decompressions due to being in the No Context state 00079 unsigned int packets_failed_no_context; 00080 /// The number of bad decompressions 00081 unsigned int packets_failed_decompression; 00082 /// The number of feedback packets sent to the associated compressor 00083 unsigned int packets_feedback; 00084 }; 00085 00086 00087 /** 00088 * @brief The ROHC decompressor. 00089 */ 00090 struct rohc_decomp 00091 { 00092 /// The compressor associated with the decompressor 00093 struct rohc_comp *compressor; 00094 00095 /// The medium associated with the decompressor 00096 struct medium *medium; 00097 00098 /// The array of decompression contexts that use the decompressor 00099 struct d_context **contexts; 00100 /// The number of decompression contexts stored in the array 00101 int num_contexts; 00102 /// The last decompression context used by the decompressor 00103 struct d_context *last_context; 00104 00105 /** 00106 * @brief The feedback interval limits 00107 * 00108 * maxval can be updated by the user thanks to the user_interactions 00109 * function. 00110 * 00111 * @see user_interactions 00112 */ 00113 unsigned int maxval; 00114 /// Variable related to the feedback interval 00115 unsigned int errval; 00116 /// Variable related to the feedback interval 00117 unsigned int okval; 00118 /// Variable related to the feedback interval 00119 int curval; 00120 00121 00122 /* CRC-related variables: */ 00123 00124 /** The table to enable fast CRC-2 computation */ 00125 unsigned char crc_table_2[256]; 00126 /** The table to enable fast CRC-3 computation */ 00127 unsigned char crc_table_3[256]; 00128 /** The table to enable fast CRC-6 computation */ 00129 unsigned char crc_table_6[256]; 00130 /** The table to enable fast CRC-7 computation */ 00131 unsigned char crc_table_7[256]; 00132 /** The table to enable fast CRC-8 computation */ 00133 unsigned char crc_table_8[256]; 00134 00135 00136 /// Some statistics about the decompression processes 00137 struct d_statistics statistics; 00138 }; 00139 00140 00141 /** 00142 * @brief The ROHC decompression context. 00143 */ 00144 struct d_context 00145 { 00146 /// The associated profile 00147 struct d_profile *profile; 00148 /// Profile-specific data, defined by the profiles 00149 void *specific; 00150 00151 /// The operation mode in which the context operates: U_MODE, O_MODE, R_MODE 00152 rohc_mode mode; 00153 /// @brief The operation state in which the context operates: NO_CONTEXT, 00154 /// STATIC_CONTEXT, FULL_CONTEXT 00155 rohc_d_state state; 00156 00157 /// Usage timestamp 00158 unsigned int latest_used; 00159 /// Usage timestamp 00160 unsigned int first_used; 00161 00162 /// Variable related to feedback interval 00163 int curval; 00164 00165 /* below are some statistics */ 00166 00167 /// The average size of the uncompressed packets 00168 int total_uncompressed_size; 00169 /// The average size of the compressed packets 00170 int total_compressed_size; 00171 /// The average size of the uncompressed headers 00172 int header_uncompressed_size; 00173 /// The average size of the compressed headers 00174 int header_compressed_size; 00175 00176 /// The number of received packets 00177 int num_recv_packets; 00178 /// The number of received IR packets 00179 int num_recv_ir; 00180 /// The number of received IR-DYN packets 00181 int num_recv_ir_dyn; 00182 /// The number of sent feedbacks 00183 int num_sent_feedbacks; 00184 00185 /// The number of compression failures 00186 int num_decomp_failures; 00187 /// The number of decompression failures 00188 int num_decomp_repairs; 00189 00190 /// The size of the last 16 uncompressed packets 00191 struct c_wlsb *total_16_uncompressed; 00192 /// The size of the last 16 compressed packets 00193 struct c_wlsb *total_16_compressed; 00194 /// The size of the last 16 uncompressed headers 00195 struct c_wlsb *header_16_uncompressed; 00196 /// The size of the last 16 compressed headers 00197 struct c_wlsb *header_16_compressed; 00198 }; 00199 00200 00201 /** 00202 * @brief The ROHC decompression profile. 00203 * 00204 * The object defines a ROHC profile. Each field must be filled in 00205 * for each new profile. 00206 */ 00207 struct d_profile 00208 { 00209 /// The profile ID as reserved by IANA 00210 int id; 00211 00212 /// A string that describes the profile 00213 char *description; 00214 00215 /// The handler used to decode IR-DYN and UO* packets 00216 int (*decode)(struct rohc_decomp *decomp, 00217 struct d_context *context, 00218 const unsigned char *const rohc_packet, 00219 const unsigned int rohc_length, 00220 int second_byte, 00221 unsigned char *dest); 00222 00223 /// The handler used to decode the IR packets 00224 int (*decode_ir)(struct rohc_decomp *decomp, 00225 struct d_context *context, 00226 const unsigned char *const rohc_packet, 00227 const unsigned int rohc_length, 00228 int large_cid_len, 00229 int is_addcid_used, 00230 unsigned char *dest); 00231 00232 /// @brief The handler used to create the profile-specific part of the 00233 /// decompression context 00234 void * (*allocate_decode_data)(void); 00235 00236 /// @brief The handler used to destroy the profile-specific part of the 00237 /// decompression context 00238 void (*free_decode_data)(void *); 00239 00240 /// The handler used to find out the size of IR packets 00241 unsigned int (*detect_ir_size)(struct d_context *context, 00242 unsigned char *packet, 00243 unsigned int plen, 00244 unsigned int large_cid_len); 00245 00246 /// The handler used to find out the size of IR-DYN packets 00247 unsigned int (*detect_ir_dyn_size)(struct d_context *context, 00248 unsigned char *packet, 00249 unsigned int plen, 00250 unsigned int large_cid_len); 00251 00252 /// The handler used to get the size of the specific static part of IR packets 00253 int (*get_static_part)(void); 00254 00255 /// The handler used to retrieve the Sequence Number (SN) 00256 int (*get_sn)(struct d_context *context); 00257 }; 00258 00259 /* 00260 * Functions related to decompressor: 00261 */ 00262 00263 void context_array_increase(struct rohc_decomp *decomp, int highestcid); 00264 void context_array_decrease(struct rohc_decomp *decomp); 00265 00266 struct rohc_decomp * rohc_alloc_decompressor(struct rohc_comp *compressor); 00267 void rohc_free_decompressor(struct rohc_decomp *decomp); 00268 00269 int rohc_decompress(struct rohc_decomp *decomp, unsigned char *ibuf, int isize, 00270 unsigned char *obuf, int osize); 00271 int rohc_decompress_both(struct rohc_decomp *decomp, unsigned char *ibuf, 00272 int isize, unsigned char *obuf, int osize, int large); 00273 int d_decode_header(struct rohc_decomp *decomp, unsigned char *ibuf, int isize, 00274 unsigned char *obuf, int osize, 00275 struct d_decode_data *ddata); 00276 00277 /* 00278 * Functions related to context: 00279 */ 00280 00281 struct d_context * find_context(struct rohc_decomp *decomp, int cid); 00282 struct d_context * context_create(struct rohc_decomp *decomp, 00283 int with_cid, 00284 struct d_profile *profile); 00285 void context_free(struct d_context *context); 00286 00287 00288 /* 00289 * Functions related to feedback: 00290 */ 00291 00292 void d_operation_mode_feedback(struct rohc_decomp *decomp, int rohc_status, int cid, 00293 int addcidUsed, int largecidUsed, int mode, 00294 struct d_context *context); 00295 void d_change_mode_feedback(struct rohc_decomp *decomp, struct d_context *context); 00296 00297 00298 /* 00299 * Functions related to statistics: 00300 */ 00301 00302 int rohc_d_statistics(struct rohc_decomp *decomp, unsigned int indent, 00303 char *buffer); 00304 int rohc_d_context(struct rohc_decomp *decomp, int index, unsigned int indent, 00305 char *buffer); 00306 void clear_statistics(struct rohc_decomp *decomp); 00307 00308 00309 /* 00310 * Functions related to user interaction: 00311 */ 00312 00313 void user_interactions(struct rohc_decomp *decomp, int feedback_maxval); 00314 00315 00316 #endif 00317