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 00024 #ifndef COMP_H 00025 #define COMP_H 00026 00027 #include <netinet/ip.h> 00028 #include <netinet/udp.h> 00029 #include <string.h> 00030 #include <stdbool.h> 00031 00032 #include "rohc.h" 00033 #include <stdlib.h> 00034 00035 00036 struct c_feedback; 00037 00038 00040 #define C_NUM_PROFILES 5 00041 00042 00044 typedef enum 00045 { 00047 IR = 1, 00049 FO = 2, 00051 SO = 3, 00052 } rohc_c_state; 00053 00054 00058 struct rohc_feedback 00059 { 00061 unsigned char *data; 00063 size_t length; 00065 bool is_locked; 00066 }; 00067 00068 00072 struct rohc_comp 00073 { 00076 int enabled; 00077 00079 struct medium medium; 00080 00082 struct c_context *contexts; 00084 int num_contexts; 00086 int num_contexts_used; 00087 00090 int profiles[C_NUM_PROFILES]; 00091 00092 /* feedback-related variables: */ 00093 00095 #define FEEDBACK_BUFFER_SIZE 10 00096 00098 struct rohc_feedback feedbacks[FEEDBACK_BUFFER_SIZE]; 00100 size_t feedbacks_first; 00102 size_t feedbacks_first_unlocked; 00104 size_t feedbacks_next; 00105 00106 /* some statistics about the compression process: */ 00107 00109 int num_packets; 00111 int total_uncompressed_size; 00113 int total_compressed_size; 00114 00116 struct c_context *last_context; 00117 00118 /* user interaction variables: */ 00119 00121 int mrru; 00123 int max_header_size; 00125 int connection_type; 00127 int jam_use; 00129 int adapt_size; 00131 int encap_size; 00132 }; 00133 00134 00138 struct c_context 00139 { 00141 int used; 00143 unsigned int latest_used; 00145 unsigned int first_used; 00146 00148 int cid; 00149 00151 struct rohc_comp *compressor; 00152 00154 struct c_profile *profile; 00156 void *specific; 00157 00159 rohc_mode mode; 00161 rohc_c_state state; 00162 00163 /* below are some statistics */ 00164 00166 int total_uncompressed_size; 00168 int total_compressed_size; 00170 int header_uncompressed_size; 00172 int header_compressed_size; 00173 00175 int total_last_uncompressed_size; 00177 int total_last_compressed_size; 00179 int header_last_uncompressed_size; 00181 int header_last_compressed_size; 00182 00184 int num_sent_packets; 00186 int num_sent_ir; 00188 int num_sent_ir_dyn; 00190 int num_recv_feedbacks; 00191 00193 struct c_wlsb *total_16_uncompressed; 00195 struct c_wlsb *total_16_compressed; 00197 struct c_wlsb *header_16_uncompressed; 00199 struct c_wlsb *header_16_compressed; 00200 }; 00201 00202 00209 struct c_profile 00210 { 00213 unsigned short protocol; 00214 00219 int *ports; 00220 00222 unsigned short id; 00223 00225 char *version; 00227 char *description; 00228 00231 int (*create)(struct c_context *context, const struct ip_packet packet); 00232 00235 void (*destroy)(struct c_context *context); 00236 00239 int (*check_context)(struct c_context *context, struct ip_packet packet); 00240 00242 int (*encode)(struct c_context *context, const struct ip_packet packet, 00243 int packet_size, unsigned char *dest, int dest_size, 00244 int *payload_offset); 00245 00248 void (*feedback)(struct c_context *context, struct c_feedback *feedback); 00249 }; 00250 00251 00255 struct c_feedback 00256 { 00258 int cid; 00259 00262 int type; 00263 00265 unsigned char *data; 00267 unsigned char size; 00268 00271 int specific_offset; 00273 int specific_size; 00274 00276 enum { 00278 ACK, 00280 NACK, 00282 STATIC_NACK, 00284 RESERVED 00285 } acktype; 00286 }; 00287 00288 00289 /* 00290 * Functions related to compressor: 00291 */ 00292 00293 struct rohc_comp * rohc_alloc_compressor(int max_cid, int jam_use, int adapt_size, int encap_size); 00294 void rohc_free_compressor(struct rohc_comp *comp); 00295 00296 int rohc_compress(struct rohc_comp *comp, unsigned char *ibuf, int isize, 00297 unsigned char *obuf, int osize); 00298 00299 int rohc_c_info(char *buffer); 00300 int rohc_c_statistics(struct rohc_comp *comp, unsigned int indent, 00301 char *buffer); 00302 int rohc_c_context(struct rohc_comp *comp, int cid, unsigned int indent, 00303 char *buffer); 00304 00305 int rohc_c_is_enabled(struct rohc_comp *comp); 00306 int rohc_c_using_small_cid(struct rohc_comp *comp); 00307 00308 00309 /* 00310 * Functions related to context: 00311 */ 00312 00313 struct c_context *c_create_context(struct rohc_comp *, struct c_profile *profile, struct ip_packet ip); 00314 struct c_context *c_find_context(struct rohc_comp *, struct c_profile *profile, struct ip_packet ip); 00315 struct c_context *c_get_context(struct rohc_comp *, int cid); 00316 00317 00318 /* 00319 * Functions related to profile: 00320 */ 00321 00322 struct c_profile * c_get_profile_from_packet(struct rohc_comp *comp, 00323 struct ip_packet *outer_ip, 00324 struct ip_packet *inner_ip, 00325 int protocol); 00326 struct c_profile * c_get_profile_from_id(struct rohc_comp *comp, 00327 int profile_id); 00328 void rohc_activate_profile(struct rohc_comp *comp, int profile); 00329 00330 00331 /* 00332 * Functions related to feedback: 00333 */ 00334 00335 void c_piggyback_feedback(struct rohc_comp *comp, unsigned char *packet, 00336 int size); 00337 void c_deliver_feedback(struct rohc_comp *comp, unsigned char *feedback, 00338 int size); 00339 int rohc_feedback_flush(struct rohc_comp *comp, 00340 unsigned char *obuf, 00341 int osize); 00342 00343 00344 /* 00345 * Functions related to user interaction: 00346 */ 00347 00348 void rohc_c_set_header(struct rohc_comp *compressor, int value); 00349 void rohc_c_set_mrru(struct rohc_comp *compressor, int value); 00350 void rohc_c_set_max_cid(struct rohc_comp *compressor, int value); 00351 void rohc_c_set_large_cid(struct rohc_comp *compressor, int value); 00352 void rohc_c_set_enable(struct rohc_comp *compressor, int value); 00353 00354 00355 /* 00356 * ROHC library includes: 00357 */ 00358 00359 #include "cid.h" 00360 00361 00362 #endif 00363