00001 /* 00002 * Copyright 2010,2011,2012,2013,2014 Didier Barvaux 00003 * Copyright 2012,2013,2014 Viveris Technologies 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 /** 00021 * @file rohc_comp_internals.h 00022 * @brief Internal structures for ROHC compression 00023 * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com> 00024 * @author Didier Barvaux <didier@barvaux.org> 00025 */ 00026 00027 #ifndef ROHC_COMP_INTERNALS_H 00028 #define ROHC_COMP_INTERNALS_H 00029 00030 #include "rohc_internal.h" 00031 #include "rohc_traces_internal.h" 00032 #include "rohc_packets.h" 00033 #include "rohc_comp.h" 00034 #include "schemes/comp_wlsb.h" 00035 #include "net_pkt.h" 00036 #include "feedback.h" 00037 00038 #ifdef __KERNEL__ 00039 # include <linux/types.h> 00040 #else 00041 # include <stdbool.h> 00042 #endif 00043 00044 00045 /* 00046 * Constants and macros 00047 */ 00048 00049 /** The number of ROHC profiles ready to be used */ 00050 #define C_NUM_PROFILES 7U 00051 00052 /** The default maximal number of packets sent in > IR states (= FO and SO 00053 * states) before changing back the state to IR (periodic refreshes) */ 00054 #define CHANGE_TO_IR_COUNT 1700 00055 00056 /** The default maximal number of packets sent in > FO states (= SO state) 00057 * before changing back the state to FO (periodic refreshes) */ 00058 #define CHANGE_TO_FO_COUNT 700 00059 00060 /** The minimal number of packets that must be sent while in IR state before 00061 * being able to switch to the FO state */ 00062 #define MAX_IR_COUNT 3U 00063 00064 /** The minimal number of packets that must be sent while in FO state before 00065 * being able to switch to the SO state */ 00066 #define MAX_FO_COUNT 3U 00067 00068 /** The minimal number of packets that must be sent while in INIT_STRIDE 00069 * state before being able to switch to the SEND_SCALED state */ 00070 #define ROHC_INIT_TS_STRIDE_MIN 3U 00071 00072 /** 00073 * @brief Default number of transmission for lists to become a reference list 00074 * 00075 * The minimal number of times of compressed list shall be sent to become 00076 * a reference list. L is the name specified in the RFC. 00077 */ 00078 #define ROHC_LIST_DEFAULT_L 5U 00079 00080 00081 /** Print a warning trace for the given compression context */ 00082 #define rohc_comp_warn(context, format, ...) \ 00083 rohc_warning((context)->compressor, ROHC_TRACE_COMP, \ 00084 (context)->profile->id, \ 00085 format, ##__VA_ARGS__) 00086 00087 /** Print a debug trace for the given compression context */ 00088 #define rohc_comp_debug(context, format, ...) \ 00089 rohc_debug((context)->compressor, ROHC_TRACE_COMP, \ 00090 (context)->profile->id, \ 00091 format, ##__VA_ARGS__) 00092 00093 /** Dump a buffer for the given compression context */ 00094 #define rohc_comp_dump_buf(context, descr, buf, buf_len) \ 00095 do { \ 00096 if(((context)->compressor->features & ROHC_COMP_FEATURE_DUMP_PACKETS) != 0) { \ 00097 rohc_dump_buf((context)->compressor->trace_callback, \ 00098 (context)->compressor->trace_callback_priv, \ 00099 ROHC_TRACE_COMP, ROHC_TRACE_DEBUG, \ 00100 descr, buf, buf_len); \ 00101 } \ 00102 } while(0) 00103 00104 00105 /* 00106 * Declare ROHC compression structures that are defined at the end of this 00107 * file but used by other structures at the beginning of the file. 00108 */ 00109 00110 struct rohc_comp_ctxt; 00111 00112 00113 /* 00114 * Definitions of ROHC compression structures 00115 */ 00116 00117 00118 /** 00119 * @brief The ROHC compressor 00120 */ 00121 struct rohc_comp 00122 { 00123 /** The medium associated with the decompressor */ 00124 struct rohc_medium medium; 00125 00126 /** Enabled/disabled features for the compressor */ 00127 rohc_comp_features_t features; 00128 00129 /** The array of compression contexts that use the compressor */ 00130 struct rohc_comp_ctxt *contexts; 00131 /** The number of compression contexts in use in the array */ 00132 size_t num_contexts_used; 00133 00134 /** Which profiles are enabled and with one are not? */ 00135 bool enabled_profiles[C_NUM_PROFILES]; 00136 00137 00138 /* CRC-related variables: */ 00139 00140 /** The table to enable fast CRC-3 computation */ 00141 uint8_t crc_table_3[256]; 00142 /** The table to enable fast CRC-7 computation */ 00143 uint8_t crc_table_7[256]; 00144 /** The table to enable fast CRC-8 computation */ 00145 uint8_t crc_table_8[256]; 00146 00147 00148 /* segment-related variables */ 00149 00150 /** The maximal value for MRRU */ 00151 #define ROHC_MAX_MRRU 65535 00152 /** The remaining bytes of the Reconstructed Reception Unit (RRU) waiting 00153 * to be split into segments */ 00154 uint8_t rru[ROHC_MAX_MRRU]; 00155 /** The offset of the remaining bytes in the RRU buffer */ 00156 size_t rru_off; 00157 /** The number of the remaining bytes in the RRU buffer */ 00158 size_t rru_len; 00159 00160 00161 /* variables related to RTP detection */ 00162 00163 /** The callback function used to detect RTP packet */ 00164 rohc_rtp_detection_callback_t rtp_callback; 00165 /** Pointer to an external memory area provided/used by the callback user */ 00166 void *rtp_private; 00167 00168 00169 /* some statistics about the compression process: */ 00170 00171 /** The number of sent packets */ 00172 int num_packets; 00173 /** The size of all the received uncompressed IP packets */ 00174 int total_uncompressed_size; 00175 /** The size of all the sent compressed ROHC packets */ 00176 int total_compressed_size; 00177 00178 /** The last context used by the compressor */ 00179 struct rohc_comp_ctxt *last_context; 00180 00181 00182 /* random callback */ 00183 00184 /** The user-defined callback for random numbers */ 00185 rohc_comp_random_cb_t random_cb; 00186 /** Private data that will be given to the callback for random numbers */ 00187 void *random_cb_ctxt; 00188 00189 00190 /* user interaction variables: */ 00191 00192 /** The width of the W-LSB sliding window */ 00193 size_t wlsb_window_width; 00194 /** The maximal number of packets sent in > IR states (= FO and SO 00195 * states) before changing back the state to IR (periodic refreshes) */ 00196 size_t periodic_refreshes_ir_timeout; 00197 /** The maximal number of packets sent in > FO states (= SO state) 00198 * before changing back the state to FO (periodic refreshes) */ 00199 size_t periodic_refreshes_fo_timeout; 00200 /** Maximum Reconstructed Reception Unit */ 00201 size_t mrru; 00202 /** The connection type (currently not used) */ 00203 int connection_type; 00204 /** The number of uncompressed transmissions for list compression (L) */ 00205 size_t list_trans_nr; 00206 00207 /** The callback function used to manage traces */ 00208 rohc_trace_callback2_t trace_callback; 00209 /** The private context of the callback function used to manage traces */ 00210 void *trace_callback_priv; 00211 }; 00212 00213 00214 /** 00215 * @brief The ROHC compression profile 00216 * 00217 * The object defines a ROHC profile. Each field must be filled in 00218 * for each new profile. 00219 */ 00220 struct rohc_comp_profile 00221 { 00222 /** The profile ID as reserved by IANA */ 00223 const rohc_profile_t id; 00224 00225 /** 00226 * @brief The IP protocol ID used to find out which profile is able to 00227 * compress an IP packet 00228 */ 00229 const unsigned short protocol; 00230 00231 /** 00232 * @brief The handler used to create the profile-specific part of the 00233 * compression context 00234 */ 00235 bool (*create)(struct rohc_comp_ctxt *const context, 00236 const struct net_pkt *const packet) 00237 __attribute__((warn_unused_result, nonnull(1, 2))); 00238 00239 /** 00240 * @brief The handler used to destroy the profile-specific part of the 00241 * compression context 00242 */ 00243 void (*destroy)(struct rohc_comp_ctxt *const context) 00244 __attribute__((nonnull(1))); 00245 00246 /** 00247 * @brief The handler used to check whether an uncompressed IP packet 00248 * fits the current profile or not 00249 */ 00250 bool (*check_profile)(const struct rohc_comp *const comp, 00251 const struct net_pkt *const packet) 00252 __attribute__((warn_unused_result, nonnull(1, 2))); 00253 00254 /** 00255 * @brief The handler used to check whether an uncompressed IP packet 00256 * belongs to a context or not 00257 */ 00258 bool (*check_context)(const struct rohc_comp_ctxt *const context, 00259 const struct net_pkt *const packet) 00260 __attribute__((warn_unused_result, nonnull(1, 2))); 00261 00262 /** 00263 * @brief The handler used to encode uncompressed IP packets 00264 * 00265 * @param context The compression context 00266 * @param ip The IP packet to encode 00267 * @param packet_size The length of the IP packet to encode 00268 * @param rohc_pkt OUT: The ROHC packet 00269 * @param rohc_pkt_max_len The maximum length of the ROHC packet 00270 * @param packet_type OUT: The type of ROHC packet that is created 00271 * @param payload_offset OUT: The offset for the payload in the IP packet 00272 * @return The length of the ROHC packet if successful, 00273 * -1 otherwise 00274 */ 00275 int (*encode)(struct rohc_comp_ctxt *const context, 00276 const struct net_pkt *const uncomp_pkt, 00277 uint8_t *const rohc_pkt, 00278 const size_t rohc_pkt_max_len, 00279 rohc_packet_t *const packet_type, 00280 size_t *const payload_offset) 00281 __attribute__((warn_unused_result, nonnull(1, 2, 3, 5, 6))); 00282 00283 /** 00284 * @brief The handler used to re-initialize a context 00285 */ 00286 bool (*reinit_context)(struct rohc_comp_ctxt *const context) 00287 __attribute__((nonnull(1), warn_unused_result)); 00288 00289 /** 00290 * @brief The handler used to warn the profile-specific part of the 00291 * context about the arrival of feedback data 00292 */ 00293 bool (*feedback)(struct rohc_comp_ctxt *const context, 00294 const enum rohc_feedback_type feedback_type, 00295 const uint8_t *const packet, 00296 const size_t packet_len, 00297 const uint8_t *const feedback_data, 00298 const size_t feedback_data_len) 00299 __attribute__((warn_unused_result, nonnull(1, 3, 5))); 00300 }; 00301 00302 00303 /** 00304 * @brief The ROHC compression context 00305 */ 00306 struct rohc_comp_ctxt 00307 { 00308 /** Whether the context is in use or not */ 00309 int used; 00310 /** The time when the context was created (in seconds) */ 00311 uint64_t latest_used; 00312 /** The time when the context was last used (in seconds) */ 00313 uint64_t first_used; 00314 00315 /** The context unique ID (CID) */ 00316 rohc_cid_t cid; 00317 00318 /** The key to help finding the context associated with a packet */ 00319 rohc_ctxt_key_t key; /* may not be unique */ 00320 00321 /** The associated compressor */ 00322 struct rohc_comp *compressor; 00323 00324 /** The associated profile */ 00325 const struct rohc_comp_profile *profile; 00326 /** Profile-specific data, defined by the profiles */ 00327 void *specific; 00328 00329 /** The operation mode in which the context operates among: 00330 * ROHC_U_MODE, ROHC_O_MODE, ROHC_R_MODE */ 00331 rohc_mode_t mode; 00332 /** The operation state in which the context operates: IR, FO, SO */ 00333 rohc_comp_state_t state; 00334 00335 /* below are some statistics */ 00336 00337 /* The type of ROHC packet created for the last compressed packet */ 00338 rohc_packet_t packet_type; 00339 00340 /** The number of packets sent while in Initialization & Refresh (IR) state */ 00341 size_t ir_count; 00342 /** The number of packets sent while in First Order (FO) state */ 00343 size_t fo_count; 00344 /** The number of packets sent while in Second Order (SO) state */ 00345 size_t so_count; 00346 00347 /** 00348 * @brief The number of packet sent while in SO state, used for the periodic 00349 * refreshes of the context 00350 * @see rohc_comp_periodic_down_transition 00351 */ 00352 size_t go_back_fo_count; 00353 /** 00354 * @brief The number of packet sent while in FO or SO state, used for the 00355 * periodic refreshes of the context 00356 * @see rohc_comp_periodic_down_transition 00357 */ 00358 size_t go_back_ir_count; 00359 00360 /** The average size of the uncompressed packets */ 00361 int total_uncompressed_size; 00362 /** The average size of the compressed packets */ 00363 int total_compressed_size; 00364 /** The average size of the uncompressed headers */ 00365 int header_uncompressed_size; 00366 /** The average size of the compressed headers */ 00367 int header_compressed_size; 00368 00369 /** The total size of the last uncompressed packet */ 00370 int total_last_uncompressed_size; 00371 /** The total size of the last compressed packet */ 00372 int total_last_compressed_size; 00373 /** The header size of the last uncompressed packet */ 00374 int header_last_uncompressed_size; 00375 /** The header size of the last compressed packet */ 00376 int header_last_compressed_size; 00377 00378 /** The number of sent packets */ 00379 int num_sent_packets; 00380 }; 00381 00382 00383 void rohc_comp_change_mode(struct rohc_comp_ctxt *const context, 00384 const rohc_mode_t new_mode) 00385 __attribute__((nonnull(1))); 00386 00387 void rohc_comp_change_state(struct rohc_comp_ctxt *const context, 00388 const rohc_comp_state_t new_state) 00389 __attribute__((nonnull(1))); 00390 00391 void rohc_comp_periodic_down_transition(struct rohc_comp_ctxt *const context) 00392 __attribute__((nonnull(1))); 00393 00394 bool rohc_comp_reinit_context(struct rohc_comp_ctxt *const context) 00395 __attribute__((warn_unused_result, nonnull(1))); 00396 00397 bool rohc_comp_feedback_parse_opts(const struct rohc_comp_ctxt *const context, 00398 const uint8_t *const packet, 00399 const size_t packet_len, 00400 const uint8_t *const feedback_data, 00401 const size_t feedback_data_len, 00402 size_t opts_present[ROHC_FEEDBACK_OPT_MAX], 00403 uint32_t *const sn_bits, 00404 size_t *const sn_bits_nr, 00405 uint8_t crc_in_packet, 00406 size_t crc_pos_from_end) 00407 __attribute__((warn_unused_result, nonnull(1, 2, 4, 6, 7, 8))); 00408 00409 #endif 00410
1.6.1