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 5
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         /* user interaction variables: */
00146 
00147         /** Maximum Reconstructed Reception Unit (currently not used) */
00148         int mrru;
00149         /** Maximum header size that will be compressed (currently not used) */
00150         int max_header_size;
00151         /** The connection type (currently not used) */
00152         int connection_type;
00153         /** Whether to use jamming or not (option enabled/disabled by user) */
00154         int jam_use;
00155         /** The size (in bytes) of the adaptation packets */
00156         int adapt_size;
00157         /** The size (in bytes) of the encapsulation packets */
00158         int encap_size;
00159 };
00160 
00161 
00162 /**
00163  * @brief The ROHC compression profile
00164  *
00165  * The object defines a ROHC profile. Each field must be filled in
00166  * for each new profile.
00167  */
00168 struct c_profile
00169 {
00170         /**
00171          * @brief The IP protocol ID used to find out which profile is able to
00172          *        compress an IP packet
00173          */
00174         const unsigned short protocol;
00175 
00176         /**
00177          * @brief The UDP ports associated with this profile
00178          *
00179          * Only used with UDP as transport protocol. The pointer can be NULL if no
00180          * port is specified. If defined, the list must be terminated by 0.
00181          * example: { 5000, 5001, 0 }
00182          */
00183         const int *ports;
00184 
00185         /** The profile ID as reserved by IANA */
00186         const unsigned short id;
00187 
00188         /** A string that describes the profile */
00189         const char *description;
00190 
00191         /**
00192          * @brief The handler used to create the profile-specific part of the
00193          *        compression context
00194          */
00195         int (*create)(struct c_context *const context,
00196                       const struct ip_packet *packet);
00197 
00198         /**
00199          * @brief The handler used to destroy the profile-specific part of the
00200          *        compression context
00201          */
00202         void (*destroy)(struct c_context *const context);
00203 
00204         /**
00205          * @brief The handler used to check whether an uncompressed IP packet
00206          *        belongs to a context or not
00207          */
00208         int (*check_context)(const struct c_context *context,
00209                              const struct ip_packet *packet);
00210 
00211         /**
00212          * @brief The handler used to encode uncompressed IP packets
00213          */
00214         int (*encode)(struct c_context *const context,
00215                       const struct ip_packet *packet,
00216                       const int packet_size,
00217                       unsigned char *const dest,
00218                       const int dest_size,
00219                       rohc_packet_t *const packet_type,
00220                       int *const payload_offset);
00221 
00222         /**
00223          * @brief The handler used to warn the profile-specific part of the
00224          *        context about the arrival of feedback data
00225          */
00226         void (*feedback)(struct c_context *const context,
00227                          const struct c_feedback *feedback);
00228 };
00229 
00230 
00231 /**
00232  * @brief The ROHC compression context
00233  */
00234 struct c_context
00235 {
00236         /** Whether the context is in use or not */
00237         int used;
00238         /** The time when the context was created */
00239         unsigned int latest_used;
00240         /** The time when the context was last used */
00241         unsigned int first_used;
00242 
00243         /** The context unique ID (CID) */
00244         int cid;
00245 
00246         /** The associated compressor */
00247         struct rohc_comp *compressor;
00248 
00249         /** The associated profile */
00250         const struct c_profile *profile;
00251         /** Profile-specific data, defined by the profiles */
00252         void *specific;
00253 
00254         /** The operation mode in which the context operates: U_MODE, O_MODE, R_MODE */
00255         rohc_mode mode;
00256         /** The operation state in which the context operates: IR, FO, SO */
00257         rohc_c_state state;
00258 
00259         /* below are some statistics */
00260 
00261         /* The type of ROHC packet created for the last compressed packet */
00262         rohc_packet_t packet_type;
00263 
00264         /** The average size of the uncompressed packets */
00265         int total_uncompressed_size;
00266         /** The average size of the compressed packets */
00267         int total_compressed_size;
00268         /** The average size of the uncompressed headers */
00269         int header_uncompressed_size;
00270         /** The average size of the compressed headers */
00271         int header_compressed_size;
00272 
00273         /** The total size of the last uncompressed packet */
00274         int total_last_uncompressed_size;
00275         /** The total size of the last compressed packet */
00276         int total_last_compressed_size;
00277         /** The header size of the last uncompressed packet */
00278         int header_last_uncompressed_size;
00279         /** The header size of the last compressed packet */
00280         int header_last_compressed_size;
00281 
00282         /** The number of sent packets */
00283         int num_sent_packets;
00284         /** The number of sent IR packets */
00285         int num_sent_ir;
00286         /** The number of sent IR-DYN packets */
00287         int num_sent_ir_dyn;
00288         /** The number of received feedbacks */
00289         int num_recv_feedbacks;
00290 
00291         /** The size of the last 16 uncompressed packets */
00292         struct c_wlsb *total_16_uncompressed;
00293         /** The size of the last 16 compressed packets */
00294         struct c_wlsb *total_16_compressed;
00295         /** The size of the last 16 uncompressed headers */
00296         struct c_wlsb *header_16_uncompressed;
00297         /** The size of the last 16 compressed headers */
00298         struct c_wlsb *header_16_compressed;
00299 };
00300 
00301 
00302 /**
00303  * @brief The feedback packet
00304  */
00305 struct c_feedback
00306 {
00307         /** The Context ID to which the feedback packet is related */
00308         int cid;
00309 
00310         /**
00311          * @brief The type of feedback packet
00312          *
00313          * A value of 1 means FEEDBACK-1, value 2 means FEEDBACK-2.
00314          */
00315         int type;
00316 
00317         /** The feedback data (ie. the packet excluding the first type octet) */
00318         unsigned char *data;
00319         /** The size of the feedback data */
00320         unsigned char size;
00321 
00322         /**
00323          * @brief The offset that indicates the beginning of the profile-specific
00324          *        data in the feedback data
00325          */
00326         int specific_offset;
00327         /** The size of the profile-specific data */
00328         int specific_size;
00329 
00330         /** The type of acknowledgement (FEEDBACK-2 only) */
00331         enum
00332         {
00333                 /** The classical ACKnowledgement */
00334                 ACK,
00335                 /** The Negative ACKnowledgement */
00336                 NACK,
00337                 /** The Negative STATIC ACKnowledgement */
00338                 STATIC_NACK,
00339                 /** Currently unused acknowledgement type */
00340                 RESERVED
00341         } acktype;
00342 };
00343 
00344 #endif
00345