ROHC compression/decompression library
rohc_comp_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_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 #include <stdbool.h>
00035 
00036 
00037 /*
00038  * Constants and macros
00039  */
00040 
00041 /** The number of ROHC profiles ready to be used */
00042 #define C_NUM_PROFILES 6
00043 
00044 /** The maximal number of outgoing feedbacks that can be queued */
00045 #define FEEDBACK_RING_SIZE 10
00046 
00047 
00048 /*
00049  * Declare ROHC compression structures that are defined at the end of this
00050  * file but used by other structures at the beginning of the file.
00051  */
00052 
00053 struct c_feedback;
00054 struct c_context;
00055 
00056 
00057 /*
00058  * Definitions of ROHC compression structures
00059  */
00060 
00061 
00062 /**
00063  * @brief Information on ROHC feedback data
00064  */
00065 struct rohc_feedback
00066 {
00067         /** The feedback data */
00068         unsigned char *data;
00069         /** The length (in bytes) of the feedback data */
00070         size_t length;
00071         /** Whether the feedback data was locked during packet build? */
00072         bool is_locked;
00073 };
00074 
00075 
00076 /**
00077  * @brief The ROHC compressor
00078  */
00079 struct rohc_comp
00080 {
00081         /**
00082          * @brief Whether the compressor is enabled or not
00083          *
00084          * The compressor is enabled by default and may be disabled by user.
00085          */
00086         int enabled;
00087 
00088         /** The medium associated with the decompressor */
00089         struct medium medium;
00090 
00091         /** The array of compression contexts that use the compressor */
00092         struct c_context *contexts;
00093         /** The number of compression contexts stored in the array */
00094         int num_contexts;
00095         /** The number of compression contexts in use in the array */
00096         int num_contexts_used;
00097 
00098         /**
00099          * @brief Which profiles are enabled and with one are not?
00100          *
00101          * A value of 1 means that profile is enabled, 0 means disabled.
00102          */
00103         int profiles[C_NUM_PROFILES];
00104 
00105 
00106         /* CRC-related variables: */
00107 
00108         /** The table to enable fast CRC-2 computation */
00109         unsigned char crc_table_2[256];
00110         /** The table to enable fast CRC-3 computation */
00111         unsigned char crc_table_3[256];
00112         /** The table to enable fast CRC-6 computation */
00113         unsigned char crc_table_6[256];
00114         /** The table to enable fast CRC-7 computation */
00115         unsigned char crc_table_7[256];
00116         /** The table to enable fast CRC-8 computation */
00117         unsigned char crc_table_8[256];
00118 
00119 
00120         /* feedback-related variables: */
00121 
00122         /** The ring of outgoing feedbacks */
00123         struct rohc_feedback feedbacks[FEEDBACK_RING_SIZE];
00124         /** The index of the oldest feedback in the feedback ring */
00125         size_t feedbacks_first;
00126         /** The index of the oldest unlocked feedback in the feedback ring */
00127         size_t feedbacks_first_unlocked;
00128         /** @brief The index of the next empty location in the feedback ring */
00129         size_t feedbacks_next;
00130 
00131 
00132         /* some statistics about the compression process: */
00133 
00134         /** The number of sent packets */
00135         int num_packets;
00136         /** The size of all the received uncompressed IP packets */
00137         int total_uncompressed_size;
00138         /** The size of all the sent compressed ROHC packets */
00139         int total_compressed_size;
00140 
00141         /** The last context used by the compressor */
00142         struct c_context *last_context;
00143 
00144 
00145         /* random callback */
00146 
00147         /** The user-defined callback for random numbers */
00148         rohc_comp_random_cb_t random_cb;
00149         /** Private data that will be given to the callback for random numbers */
00150         void *random_cb_ctxt;
00151 
00152 
00153         /* user interaction variables: */
00154 
00155         /** The width of the W-LSB sliding window */
00156         size_t wlsb_window_width;
00157         /** The maximal number of packets sent in > IR states (= FO and SO
00158          *  states) before changing back the state to IR (periodic refreshes) */
00159         size_t periodic_refreshes_ir_timeout;
00160         /** The maximal number of packets sent in > FO states (= SO state)
00161          *  before changing back the state to FO (periodic refreshes) */
00162         size_t periodic_refreshes_fo_timeout;
00163         /** Maximum Reconstructed Reception Unit (currently not used) */
00164         int mrru;
00165         /** Maximum header size that will be compressed (currently not used) */
00166         int max_header_size;
00167         /** The connection type (currently not used) */
00168         int connection_type;
00169 };
00170 
00171 
00172 /**
00173  * @brief The ROHC compression profile
00174  *
00175  * The object defines a ROHC profile. Each field must be filled in
00176  * for each new profile.
00177  */
00178 struct c_profile
00179 {
00180         /**
00181          * @brief The IP protocol ID used to find out which profile is able to
00182          *        compress an IP packet
00183          */
00184         const unsigned short protocol;
00185 
00186         /**
00187          * @brief The UDP ports associated with this profile
00188          *
00189          * Only used with UDP as transport protocol. The pointer can be NULL if no
00190          * port is specified. If defined, the list must be terminated by 0.
00191          * example: { 5000, 5001, 0 }
00192          */
00193         const int *ports;
00194 
00195         /** The profile ID as reserved by IANA */
00196         const unsigned short id;
00197 
00198         /** A string that describes the profile */
00199         const char *description;
00200 
00201         /**
00202          * @brief The handler used to create the profile-specific part of the
00203          *        compression context
00204          */
00205         int (*create)(struct c_context *const context,
00206                       const struct ip_packet *packet);
00207 
00208         /**
00209          * @brief The handler used to destroy the profile-specific part of the
00210          *        compression context
00211          */
00212         void (*destroy)(struct c_context *const context);
00213 
00214         /**
00215          * @brief The handler used to check whether an uncompressed IP packet
00216          *        belongs to a context or not
00217          */
00218         int (*check_context)(const struct c_context *context,
00219                              const struct ip_packet *packet);
00220 
00221         /**
00222          * @brief The handler used to encode uncompressed IP packets
00223          */
00224         int (*encode)(struct c_context *const context,
00225                       const struct ip_packet *packet,
00226                       const int packet_size,
00227                       unsigned char *const dest,
00228                       const int dest_size,
00229                       rohc_packet_t *const packet_type,
00230                       int *const payload_offset);
00231 
00232         /**
00233          * @brief The handler used to warn the profile-specific part of the
00234          *        context about the arrival of feedback data
00235          */
00236         void (*feedback)(struct c_context *const context,
00237                          const struct c_feedback *feedback);
00238 };
00239 
00240 
00241 /**
00242  * @brief The ROHC compression context
00243  */
00244 struct c_context
00245 {
00246         /** Whether the context is in use or not */
00247         int used;
00248         /** The time when the context was created */
00249         unsigned int latest_used;
00250         /** The time when the context was last used */
00251         unsigned int first_used;
00252 
00253         /** The context unique ID (CID) */
00254         int cid;
00255 
00256         /** The associated compressor */
00257         struct rohc_comp *compressor;
00258 
00259         /** The associated profile */
00260         const struct c_profile *profile;
00261         /** Profile-specific data, defined by the profiles */
00262         void *specific;
00263 
00264         /** The operation mode in which the context operates: U_MODE, O_MODE, R_MODE */
00265         rohc_mode mode;
00266         /** The operation state in which the context operates: IR, FO, SO */
00267         rohc_c_state state;
00268 
00269         /* below are some statistics */
00270 
00271         /* The type of ROHC packet created for the last compressed packet */
00272         rohc_packet_t packet_type;
00273 
00274         /** The average size of the uncompressed packets */
00275         int total_uncompressed_size;
00276         /** The average size of the compressed packets */
00277         int total_compressed_size;
00278         /** The average size of the uncompressed headers */
00279         int header_uncompressed_size;
00280         /** The average size of the compressed headers */
00281         int header_compressed_size;
00282 
00283         /** The total size of the last uncompressed packet */
00284         int total_last_uncompressed_size;
00285         /** The total size of the last compressed packet */
00286         int total_last_compressed_size;
00287         /** The header size of the last uncompressed packet */
00288         int header_last_uncompressed_size;
00289         /** The header size of the last compressed packet */
00290         int header_last_compressed_size;
00291 
00292         /** The number of sent packets */
00293         int num_sent_packets;
00294         /** The number of sent IR packets */
00295         int num_sent_ir;
00296         /** The number of sent IR-DYN packets */
00297         int num_sent_ir_dyn;
00298         /** The number of received feedbacks */
00299         int num_recv_feedbacks;
00300 
00301         /** The size of the last 16 uncompressed packets */
00302         struct c_wlsb *total_16_uncompressed;
00303         /** The size of the last 16 compressed packets */
00304         struct c_wlsb *total_16_compressed;
00305         /** The size of the last 16 uncompressed headers */
00306         struct c_wlsb *header_16_uncompressed;
00307         /** The size of the last 16 compressed headers */
00308         struct c_wlsb *header_16_compressed;
00309 };
00310 
00311 
00312 /**
00313  * @brief The feedback packet
00314  */
00315 struct c_feedback
00316 {
00317         /** The Context ID to which the feedback packet is related */
00318         int cid;
00319 
00320         /**
00321          * @brief The type of feedback packet
00322          *
00323          * A value of 1 means FEEDBACK-1, value 2 means FEEDBACK-2.
00324          */
00325         int type;
00326 
00327         /** The feedback data (ie. the packet excluding the first type octet) */
00328         unsigned char *data;
00329         /** The size of the feedback data */
00330         unsigned char size;
00331 
00332         /**
00333          * @brief The offset that indicates the beginning of the profile-specific
00334          *        data in the feedback data
00335          */
00336         int specific_offset;
00337         /** The size of the profile-specific data */
00338         int specific_size;
00339 
00340         /** The type of acknowledgement (FEEDBACK-2 only) */
00341         enum
00342         {
00343                 /** The classical ACKnowledgement */
00344                 ACK,
00345                 /** The Negative ACKnowledgement */
00346                 NACK,
00347                 /** The Negative STATIC ACKnowledgement */
00348                 STATIC_NACK,
00349                 /** Currently unused acknowledgement type */
00350                 RESERVED
00351         } acktype;
00352 };
00353 
00354 #endif
00355