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_comp_internals.h 00019 * @brief Internal structures for ROHC compression 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 */ 00024 00025 #ifndef ROHC_COMP_INTERNALS_H 00026 #define ROHC_COMP_INTERNALS_H 00027 00028 #include "rohc.h" /* for struct medium */ 00029 #include "rohc_packets.h" 00030 #include "rohc_comp.h" 00031 #include "wlsb.h" 00032 #include "ip.h" 00033 00034 #ifdef __KERNEL__ 00035 # include <linux/types.h> 00036 #else 00037 # include <stdbool.h> 00038 #endif 00039 00040 00041 /* 00042 * Constants and macros 00043 */ 00044 00045 /** The number of ROHC profiles ready to be used */ 00046 #define C_NUM_PROFILES 6 00047 00048 /** The maximal number of outgoing feedbacks that can be queued */ 00049 #define FEEDBACK_RING_SIZE 1000 00050 00051 /** The default maximal number of packets sent in > IR states (= FO and SO 00052 * states) before changing back the state to IR (periodic refreshes) */ 00053 #define CHANGE_TO_IR_COUNT 1700 00054 00055 /** The default maximal number of packets sent in > FO states (= SO state) 00056 * before changing back the state to FO (periodic refreshes) */ 00057 #define CHANGE_TO_FO_COUNT 700 00058 00059 /** The minimal number of packets that must be sent while in IR state before 00060 * being able to switch to the FO state */ 00061 #define MAX_IR_COUNT 3 00062 00063 /** The minimal number of packets that must be sent while in FO state before 00064 * being able to switch to the SO state */ 00065 #define MAX_FO_COUNT 3 00066 00067 /** The minimal number of packets that must be sent while in INIT_STRIDE 00068 * state before being able to switch to the SEND_SCALED state */ 00069 #define ROHC_INIT_TS_STRIDE_MIN 3U 00070 00071 /** Print a debug trace for the given compression context */ 00072 #define rohc_comp_debug(context, format, ...) \ 00073 rohc_debug((context)->compressor, ROHC_TRACE_COMP, \ 00074 (context)->profile->id, \ 00075 format, ##__VA_ARGS__) 00076 00077 00078 /* 00079 * Declare ROHC compression structures that are defined at the end of this 00080 * file but used by other structures at the beginning of the file. 00081 */ 00082 00083 struct c_feedback; 00084 struct c_context; 00085 00086 00087 /* 00088 * Definitions of ROHC compression structures 00089 */ 00090 00091 00092 /** The key to help identify (not quaranted unique) a compression context */ 00093 typedef uint32_t rohc_ctxt_key_t; 00094 00095 00096 /** 00097 * @brief Information on ROHC feedback data 00098 */ 00099 struct rohc_feedback 00100 { 00101 /** The feedback data */ 00102 unsigned char *data; 00103 /** The length (in bytes) of the feedback data */ 00104 size_t length; 00105 /** Whether the feedback data was locked during packet build? */ 00106 bool is_locked; 00107 }; 00108 00109 00110 /** 00111 * @brief The ROHC compressor 00112 */ 00113 struct rohc_comp 00114 { 00115 /** 00116 * @brief Whether the compressor is enabled or not 00117 * 00118 * The compressor is enabled by default and may be disabled by user. 00119 */ 00120 int enabled; 00121 00122 /** The medium associated with the decompressor */ 00123 struct medium medium; 00124 00125 /** The array of compression contexts that use the compressor */ 00126 struct c_context *contexts; 00127 /** The number of compression contexts in use in the array */ 00128 int num_contexts_used; 00129 00130 /** 00131 * @brief Which profiles are enabled and with one are not? 00132 * 00133 * A value of 1 means that profile is enabled, 0 means disabled. 00134 */ 00135 int profiles[C_NUM_PROFILES]; 00136 00137 00138 /* CRC-related variables: */ 00139 00140 /** The table to enable fast CRC-2 computation */ 00141 unsigned char crc_table_2[256]; 00142 /** The table to enable fast CRC-3 computation */ 00143 unsigned char crc_table_3[256]; 00144 /** The table to enable fast CRC-6 computation */ 00145 unsigned char crc_table_6[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 /* feedback-related variables: */ 00153 00154 /** The ring of outgoing feedbacks */ 00155 struct rohc_feedback feedbacks[FEEDBACK_RING_SIZE]; 00156 /** The index of the oldest feedback in the feedback ring */ 00157 size_t feedbacks_first; 00158 /** The index of the oldest unlocked feedback in the feedback ring */ 00159 size_t feedbacks_first_unlocked; 00160 /** @brief The index of the next empty location in the feedback ring */ 00161 size_t feedbacks_next; 00162 00163 00164 /* segment-related variables */ 00165 00166 /** The maximal value for MRRU */ 00167 #define ROHC_MAX_MRRU 65535 00168 /** The remaining bytes of the Reconstructed Reception Unit (RRU) waiting 00169 * to be split into segments */ 00170 unsigned char rru[ROHC_MAX_MRRU]; 00171 /** The offset of the remaining bytes in the RRU buffer */ 00172 size_t rru_off; 00173 /** The number of the remaining bytes in the RRU buffer */ 00174 size_t rru_len; 00175 00176 00177 /* variables related to RTP detection */ 00178 00179 /** The maximal number of RTP ports (shall be > 2) */ 00180 #define MAX_RTP_PORTS 15 00181 /** The RTP ports table */ 00182 unsigned int rtp_ports[MAX_RTP_PORTS]; 00183 00184 /** The callback function used to detect RTP packet */ 00185 rohc_rtp_detection_callback_t rtp_callback; 00186 /** Pointer to an external memory area provided/used by the callback user */ 00187 void *rtp_private; 00188 00189 00190 /* some statistics about the compression process: */ 00191 00192 /** The number of sent packets */ 00193 int num_packets; 00194 /** The size of all the received uncompressed IP packets */ 00195 int total_uncompressed_size; 00196 /** The size of all the sent compressed ROHC packets */ 00197 int total_compressed_size; 00198 00199 /** The last context used by the compressor */ 00200 struct c_context *last_context; 00201 00202 00203 /* random callback */ 00204 00205 /** The user-defined callback for random numbers */ 00206 rohc_comp_random_cb_t random_cb; 00207 /** Private data that will be given to the callback for random numbers */ 00208 void *random_cb_ctxt; 00209 00210 00211 /* user interaction variables: */ 00212 00213 /** The width of the W-LSB sliding window */ 00214 size_t wlsb_window_width; 00215 /** The maximal number of packets sent in > IR states (= FO and SO 00216 * states) before changing back the state to IR (periodic refreshes) */ 00217 size_t periodic_refreshes_ir_timeout; 00218 /** The maximal number of packets sent in > FO states (= SO state) 00219 * before changing back the state to FO (periodic refreshes) */ 00220 size_t periodic_refreshes_fo_timeout; 00221 /** Maximum Reconstructed Reception Unit (currently not used) */ 00222 size_t mrru; 00223 /** Maximum header size that will be compressed (currently not used) */ 00224 int max_header_size; 00225 /** The connection type (currently not used) */ 00226 int connection_type; 00227 00228 /** The callback function used to manage traces */ 00229 rohc_trace_callback_t trace_callback; 00230 }; 00231 00232 00233 /** 00234 * @brief The ROHC compression profile 00235 * 00236 * The object defines a ROHC profile. Each field must be filled in 00237 * for each new profile. 00238 */ 00239 struct c_profile 00240 { 00241 /** 00242 * @brief The IP protocol ID used to find out which profile is able to 00243 * compress an IP packet 00244 */ 00245 const unsigned short protocol; 00246 00247 /** The profile ID as reserved by IANA */ 00248 const unsigned short id; 00249 00250 /** A string that describes the profile */ 00251 const char *description; 00252 00253 /** 00254 * @brief The handler used to create the profile-specific part of the 00255 * compression context 00256 */ 00257 int (*create)(struct c_context *const context, 00258 const struct ip_packet *packet); 00259 00260 /** 00261 * @brief The handler used to destroy the profile-specific part of the 00262 * compression context 00263 */ 00264 void (*destroy)(struct c_context *const context); 00265 00266 /** 00267 * @brief The handler used to check whether an uncompressed IP packet 00268 * fits the current profile or not 00269 */ 00270 bool (*check_profile)(const struct rohc_comp *const comp, 00271 const struct ip_packet *const outer_ip, 00272 const struct ip_packet *const inner_ip, 00273 const uint8_t protocol, 00274 rohc_ctxt_key_t *const ctxt_key); 00275 00276 /** 00277 * @brief The handler used to check whether an uncompressed IP packet 00278 * belongs to a context or not 00279 */ 00280 bool (*check_context)(const struct c_context *context, 00281 const struct ip_packet *packet); 00282 00283 /** 00284 * @brief The handler used to encode uncompressed IP packets 00285 */ 00286 int (*encode)(struct c_context *const context, 00287 const struct ip_packet *packet, 00288 const size_t packet_size, 00289 unsigned char *const dest, 00290 const size_t dest_size, 00291 rohc_packet_t *const packet_type, 00292 int *const payload_offset); 00293 00294 /** 00295 * @brief The handler used to re-initialize a context 00296 */ 00297 bool (*reinit_context)(struct c_context *const context) 00298 __attribute__((nonnull(1), warn_unused_result)); 00299 00300 /** 00301 * @brief The handler used to warn the profile-specific part of the 00302 * context about the arrival of feedback data 00303 */ 00304 void (*feedback)(struct c_context *const context, 00305 const struct c_feedback *feedback); 00306 00307 /** 00308 * @brief The handler used to detect if a UDP port is used by the profile 00309 */ 00310 bool (*use_udp_port)(const struct c_context *const context, 00311 const unsigned int port); 00312 }; 00313 00314 00315 /** 00316 * @brief The ROHC compression context 00317 */ 00318 struct c_context 00319 { 00320 /** Whether the context is in use or not */ 00321 int used; 00322 /** The time when the context was created */ 00323 unsigned int latest_used; 00324 /** The time when the context was last used */ 00325 unsigned int first_used; 00326 00327 /** The context unique ID (CID) */ 00328 int cid; 00329 00330 /** The key to help finding the context associated with a packet */ 00331 rohc_ctxt_key_t key; /* may not be unique */ 00332 00333 /** The associated compressor */ 00334 struct rohc_comp *compressor; 00335 00336 /** The associated profile */ 00337 const struct c_profile *profile; 00338 /** Profile-specific data, defined by the profiles */ 00339 void *specific; 00340 00341 /** The operation mode in which the context operates: U_MODE, O_MODE, R_MODE */ 00342 rohc_mode mode; 00343 /** The operation state in which the context operates: IR, FO, SO */ 00344 rohc_c_state state; 00345 00346 /* below are some statistics */ 00347 00348 /* The type of ROHC packet created for the last compressed packet */ 00349 rohc_packet_t packet_type; 00350 00351 /** The average size of the uncompressed packets */ 00352 int total_uncompressed_size; 00353 /** The average size of the compressed packets */ 00354 int total_compressed_size; 00355 /** The average size of the uncompressed headers */ 00356 int header_uncompressed_size; 00357 /** The average size of the compressed headers */ 00358 int header_compressed_size; 00359 00360 /** The total size of the last uncompressed packet */ 00361 int total_last_uncompressed_size; 00362 /** The total size of the last compressed packet */ 00363 int total_last_compressed_size; 00364 /** The header size of the last uncompressed packet */ 00365 int header_last_uncompressed_size; 00366 /** The header size of the last compressed packet */ 00367 int header_last_compressed_size; 00368 00369 /** The number of sent packets */ 00370 int num_sent_packets; 00371 /** The number of sent IR packets */ 00372 int num_sent_ir; 00373 /** The number of sent IR-DYN packets */ 00374 int num_sent_ir_dyn; 00375 /** The number of received feedbacks */ 00376 int num_recv_feedbacks; 00377 00378 /** The size of the last 16 uncompressed packets */ 00379 struct c_wlsb *total_16_uncompressed; 00380 /** The size of the last 16 compressed packets */ 00381 struct c_wlsb *total_16_compressed; 00382 /** The size of the last 16 uncompressed headers */ 00383 struct c_wlsb *header_16_uncompressed; 00384 /** The size of the last 16 compressed headers */ 00385 struct c_wlsb *header_16_compressed; 00386 }; 00387 00388 00389 /** 00390 * @brief The feedback packet 00391 */ 00392 struct c_feedback 00393 { 00394 /** The Context ID to which the feedback packet is related */ 00395 int cid; 00396 00397 /** 00398 * @brief The type of feedback packet 00399 * 00400 * A value of 1 means FEEDBACK-1, value 2 means FEEDBACK-2. 00401 */ 00402 int type; 00403 00404 /** The feedback data (ie. the packet excluding the first type octet) */ 00405 unsigned char *data; 00406 /** The size of the feedback data */ 00407 unsigned char size; 00408 00409 /** 00410 * @brief The offset that indicates the beginning of the profile-specific 00411 * data in the feedback data 00412 */ 00413 int specific_offset; 00414 /** The size of the profile-specific data */ 00415 int specific_size; 00416 00417 /** The type of acknowledgement (FEEDBACK-2 only) */ 00418 enum 00419 { 00420 /** The classical ACKnowledgement */ 00421 ACK, 00422 /** The Negative ACKnowledgement */ 00423 NACK, 00424 /** The Negative STATIC ACKnowledgement */ 00425 STATIC_NACK, 00426 /** Currently unused acknowledgement type */ 00427 RESERVED 00428 } acktype; 00429 }; 00430 00431 #endif 00432