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 d_generic.h 00019 * @brief ROHC generic decompression context for IP-only, UDP and UDP Lite 00020 * profiles. 00021 * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com> 00022 * @author Didier Barvaux <didier@barvaux.org> 00023 * @author The hackers from ROHC for Linux 00024 * @author David Moreau from TAS 00025 */ 00026 00027 #ifndef D_GENERIC_H 00028 #define D_GENERIC_H 00029 00030 #include "rohc_decomp.h" 00031 #include "rohc_packets.h" 00032 #include "comp_list.h" 00033 #include "lsb.h" 00034 #include "ip_id.h" 00035 #include "ip.h" 00036 00037 #include <stddef.h> 00038 #include <stdbool.h> 00039 00040 00041 #define MAX_ITEM 15 00042 #if MAX_ITEM <= 7 00043 #error "translation table must be larger enough for indexes stored on 3 bits" 00044 #endif 00045 00046 #define LIST_COMP_WINDOW 100 00047 00048 #define L 5 00049 00050 /** 00051 * @brief Store information about an IP header between the different 00052 * decompressions of IP packets. 00053 * 00054 * Defines an object that contains flags and structures related to an IP header 00055 * and that need to be saved between the different decompressions of packets. A 00056 * decompression context owns objects like this for the two first IP headers. 00057 */ 00058 struct d_generic_changes 00059 { 00060 /// The IP header 00061 struct ip_packet ip; 00062 00063 /// Whether the IP-ID is considered as random or not (IPv4 only) 00064 int rnd; 00065 /// Whether the IP-ID is considered as coded in NBO or not (IPv4 only) 00066 int nbo; 00067 00068 /// Whether the compression list is used or not(IPv6 only) 00069 int complist; 00070 /// The size of the list 00071 int size_list; 00072 00073 /// The next header located after the IP header(s) 00074 unsigned char *next_header; 00075 /// The length of the next header 00076 unsigned int next_header_len; 00077 }; 00078 00079 00080 /** 00081 * @brief The generic decompression context 00082 * 00083 * The object defines the generic context that manages IP(/nextheader) and 00084 * IP/IP(/nextheader) packets. nextheader is managed by the profile-specific 00085 * part of the context. 00086 */ 00087 struct d_generic_context 00088 { 00089 /// Information about the previous outer IP header 00090 struct d_generic_changes *last1; 00091 /// Information about the previous inner IP header 00092 struct d_generic_changes *last2; 00093 /// Information about the current outer IP header 00094 struct d_generic_changes *active1; 00095 /// Information about the current inner IP header 00096 struct d_generic_changes *active2; 00097 00098 /// Whether at least packet was already processed by the context or not 00099 int first_packet_processed; 00100 00101 /// The LSB-encoded Sequence Number (SN) 00102 struct d_lsb_decode sn; 00103 /// The IP-ID of the outer IP header 00104 struct d_ip_id_decode ip_id1; 00105 /// The IP-ID of the inner IP header 00106 struct d_ip_id_decode ip_id2; 00107 00108 /// The list decompressor of the outer IP header 00109 struct list_decomp *list_decomp1; 00110 /// The list decompressor of the inner IP header 00111 struct list_decomp *list_decomp2; 00112 00113 /// Whether the decompressed packet contains a 2nd IP header 00114 int multiple_ip; 00115 00116 /// The type of packet the decompressor may receive: IR, IR-DYN, UO* 00117 rohc_packet_t packet_type; 00118 00119 /* below are some information and handlers to manage the next header 00120 * (if any) located just after the IP headers (1 or 2 IP headers) */ 00121 00122 /// The IP protocol ID of the protocol the context is able to decompress 00123 unsigned short next_header_proto; 00124 00125 /// The length of the next header 00126 unsigned int next_header_len; 00127 00128 /// @brief The handler used to build the uncompressed next header thanks 00129 /// to context information 00130 int (*build_next_header)(struct d_generic_context *context, 00131 struct d_generic_changes *active, 00132 unsigned char *dest, 00133 int payload_size); 00134 00135 /// @brief The handler used to decode the static part of the next header 00136 /// in the ROHC packet 00137 int (*decode_static_next_header)(struct d_generic_context *context, 00138 const unsigned char *packet, 00139 unsigned int length, 00140 unsigned char *dest); 00141 00142 /// @brief The handler used to decode the dynamic part of the next header 00143 /// in the ROHC packet 00144 int (*decode_dynamic_next_header)(struct d_generic_context *context, 00145 const unsigned char *packet, 00146 unsigned int length, 00147 unsigned char *dest); 00148 00149 /// The handler used to decode the tail of the UO* ROHC packet 00150 int (*decode_uo_tail)(struct d_generic_context *context, 00151 const unsigned char *packet, 00152 unsigned int length, 00153 unsigned char *dest); 00154 00155 /// @brief The handler used to compute the CRC-STATIC value 00156 unsigned int (*compute_crc_static)(const unsigned char *const ip, 00157 const unsigned char *const ip2, 00158 const unsigned char *const next_header, 00159 const unsigned int crc_type, 00160 const unsigned int init_val, 00161 const unsigned char *const crc_table); 00162 00163 /// @brief The handler used to compute the CRC-DYNAMIC value 00164 unsigned int (*compute_crc_dynamic)(const unsigned char *const ip, 00165 const unsigned char *const ip2, 00166 const unsigned char *const next_header, 00167 const unsigned int crc_type, 00168 const unsigned int init_val, 00169 const unsigned char *const crc_table); 00170 00171 /// Profile-specific data 00172 void *specific; 00173 00174 /// Correction counter (see e and f in 5.3.2.2.4 of the RFC 3095) 00175 unsigned int correction_counter; 00176 00177 /// The timestamp of the last CRC-approved packet 00178 unsigned int last_packet_time; 00179 /// The timestamp of the current packet (not yet CRC-tested) 00180 unsigned int current_packet_time; 00181 /// The average inter-packet time over the last few packets 00182 unsigned int inter_arrival_time; 00183 }; 00184 00185 /** 00186 * @brief The list decompressor 00187 */ 00188 struct list_decomp 00189 { 00190 /// The reference list 00191 struct c_list *ref_list; 00192 /// The table of lists 00193 struct c_list *list_table[LIST_COMP_WINDOW]; 00194 /// The compression based table 00195 struct rohc_list_item based_table[MAX_ITEM]; 00196 /// The translation table 00197 struct d_translation trans_table[MAX_ITEM]; 00198 /// counter in list table 00199 int counter_list; 00200 /// counter which indicates if the list is reference list 00201 int counter; 00202 /// boolean which indicates if there is a list to decompress 00203 int list_decomp; 00204 /// boolean which indicates if the ref list must be decompressed 00205 int ref_ok; 00206 /// Size of the last list extension received 00207 int size_ext; 00208 00209 /// The handler used to free the based table 00210 void (*free_table)(struct list_decomp *decomp); 00211 /// The handler used to add the extension to IP packet 00212 int (*encode_extension)(struct d_generic_changes *active, 00213 struct list_decomp *decomp, 00214 unsigned char *dest); 00215 /// The handler used to check if the index 00216 /// corresponds to an existing item 00217 int (*check_index)(struct list_decomp *decomp, int index); 00218 /// The handler used to create the item at 00219 /// the corresponding index of the based table 00220 bool (*create_item)(const unsigned char *data, 00221 int length, 00222 int index, 00223 struct list_decomp *decomp); 00224 /// The handler used to get the size of an extension 00225 int (*get_ext_size)(const unsigned char *data, const size_t data_len); 00226 }; 00227 00228 00229 /* 00230 * Public function prototypes. 00231 */ 00232 00233 void * d_generic_create(void); 00234 00235 void d_generic_destroy(void *context); 00236 00237 int d_generic_decode(struct rohc_decomp *decomp, 00238 struct d_context *context, 00239 const unsigned char *const rohc_packet, 00240 const unsigned int rohc_length, 00241 int second_byte, 00242 unsigned char *dest); 00243 00244 int d_generic_decode_ir(struct rohc_decomp *decomp, 00245 struct d_context *context, 00246 const unsigned char *const rohc_packet, 00247 const unsigned int rohc_length, 00248 int large_cid_len, 00249 int is_addcid_used, 00250 unsigned char *dest); 00251 00252 unsigned int d_generic_detect_ir_size(struct d_context *context, 00253 unsigned char *packet, 00254 unsigned int plen, 00255 unsigned int large_cid_len); 00256 00257 unsigned int d_generic_detect_ir_dyn_size(struct d_context *context, 00258 unsigned char *first_byte, 00259 unsigned int plen, 00260 unsigned int large_cid_len); 00261 00262 int d_generic_get_sn(struct d_context *context); 00263 00264 rohc_packet_t find_packet_type(struct rohc_decomp *decomp, 00265 struct d_context *context, 00266 const unsigned char *packet, 00267 const size_t rohc_length, 00268 int second_byte); 00269 00270 #endif 00271