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 00025 #ifndef C_GENERIC_H 00026 #define C_GENERIC_H 00027 00028 #include <netinet/ip.h> 00029 #include <string.h> 00030 00031 #include "rohc_comp.h" 00032 #include "comp_list.h" 00033 00034 00039 #define IPID_MAX_DELTA 20 00040 00042 #define MAX_ITEM 15 00043 00046 #define L 5 00047 00057 struct ipv4_header_info 00058 { 00060 struct c_wlsb *ip_id_window; 00061 00063 struct iphdr old_ip; 00064 00066 int df_count; 00069 int rnd_count; 00072 int nbo_count; 00073 00075 int rnd; 00077 int nbo; 00080 int old_rnd; 00083 int old_nbo; 00084 00086 int id_delta; 00087 }; 00088 00089 00099 struct ipv6_header_info 00100 { 00102 struct ip6_hdr old_ip; 00104 struct list_comp * ext_comp; 00105 }; 00106 00107 00112 struct ip_header_info 00113 { 00114 ip_version version; 00115 00117 int tos_count; 00119 int ttl_count; 00122 int protocol_count; 00123 00124 union 00125 { 00126 struct ipv4_header_info v4; 00127 struct ipv6_header_info v6; 00128 } info; 00129 }; 00130 00131 00142 struct generic_tmp_variables 00143 { 00145 int nr_of_ip_hdr; 00146 00148 unsigned short changed_fields; 00150 unsigned short changed_fields2; 00152 int send_static; 00154 int send_dynamic; 00155 00157 int nr_sn_bits; 00159 int nr_ip_id_bits; 00161 int nr_ip_id_bits2; 00162 00164 int packet_type; 00165 00167 int max_size; 00168 }; 00169 00170 00178 struct c_generic_context 00179 { 00181 unsigned int sn; 00183 struct c_wlsb *sn_window; 00184 00186 int ir_count; 00188 int fo_count; 00190 int so_count; 00191 00195 int go_back_fo_count; 00199 int go_back_ir_count; 00202 int ir_dyn_count; 00203 00205 struct ip_header_info ip_flags; 00207 struct ip_header_info ip2_flags; 00209 int is_ip2_initialized; 00210 00212 struct generic_tmp_variables tmp_variables; 00213 00214 /* below are some information and handlers to manage the next header 00215 * (if any) located just after the IP headers (1 or 2 IP headers) */ 00216 00218 unsigned int next_header_proto; 00220 unsigned int next_header_len; 00221 00224 void (*decide_state)(struct c_context *context); 00225 00227 void (*init_at_IR)(struct c_context *context, 00228 const unsigned char *next_header); 00229 00232 int (*code_static_part)(struct c_context *context, 00233 const unsigned char *next_header, 00234 unsigned char *dest, int counter); 00235 00238 int (*code_dynamic_part)(struct c_context *context, 00239 const unsigned char *next_header, 00240 unsigned char *dest, int counter); 00241 00244 int (*code_UO_packet_head)(struct c_context *context, 00245 const unsigned char *next_header, 00246 unsigned char *dest, int counter, 00247 int *first_position); 00248 00251 int (*code_UO_packet_tail)(struct c_context *context, 00252 const unsigned char *next_header, 00253 unsigned char *dest, int counter); 00254 00256 unsigned int (*compute_crc_static)(const unsigned char *ip, 00257 const unsigned char *ip2, 00258 const unsigned char *next_header, 00259 unsigned int crc_type, 00260 unsigned int init_val); 00261 00263 unsigned int (*compute_crc_dynamic)(const unsigned char *ip, 00264 const unsigned char *ip2, 00265 const unsigned char *next_header, 00266 unsigned int crc_type, 00267 unsigned int init_val); 00268 00270 void *specific; 00271 }; 00272 00276 struct list_comp 00277 { 00279 struct c_list * ref_list; 00281 struct c_list * curr_list; 00283 int counter; 00285 struct item based_table[MAX_ITEM]; 00287 struct c_translation trans_table[MAX_ITEM]; 00289 int update_done; 00291 int list_compress; 00293 int islist; 00295 unsigned char *(*get_extension)(const struct ip_packet ip,int index); 00296 00298 int (*get_index_table)(const struct ip_packet ip, int index); 00299 00301 int (*get_size)(unsigned char * ext); 00302 00304 int (*compare)(unsigned char * ext,struct list_comp * comp,int size, int index_table); 00305 00308 void (*create_item)(unsigned char *ext, int index_table, int size, 00309 struct list_comp * comp); 00311 void (*free_table)(struct list_comp * comp); 00312 }; 00313 00314 00315 /* 00316 * Function prototypes. 00317 */ 00318 00319 int c_generic_create(struct c_context *context, const struct ip_packet ip); 00320 void c_generic_destroy(struct c_context *context); 00321 00322 void change_mode(struct c_context *context, rohc_mode new_mode); 00323 void change_state(struct c_context *context, rohc_c_state new_state); 00324 00325 void ip6_c_init_table(struct list_comp * comp); 00326 int c_algo_list_compress(struct list_comp * comp, const struct ip_packet ip); 00327 int c_create_current_list(int index, struct list_comp * comp, unsigned char * ext, int index_table); 00328 int decide_type(struct list_comp * comp); 00329 int encode_list(struct list_comp * comp, unsigned char * dest, int counter, int ps, int size); 00330 int encode_type_0(struct list_comp * comp, unsigned char * dest, int counter, int ps); 00331 int encode_type_1(struct list_comp * comp, unsigned char * dest, int counter, int ps); 00332 int encode_type_3(struct list_comp * comp, unsigned char * dest, int counter, int ps); 00333 int encode_type_2(struct list_comp * comp, unsigned char * dest, int counter, int ps); 00334 int c_generic_encode(struct c_context *context, 00335 const struct ip_packet ip, 00336 int packet_size, 00337 unsigned char *dest, 00338 int dest_size, 00339 int *payload_offset); 00340 00341 void c_generic_feedback(struct c_context *context, struct c_feedback *feedback); 00342 00343 void decide_state(struct c_context *context); 00344 00345 00346 #endif 00347