ROHC compression/decompression library
rfc4996.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012,2013,2014 Didier Barvaux
00003  * Copyright 2012 WBX
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 /**
00021  * @file   src/comp/schemes/rfc4996.h
00022  * @brief  Library of encoding methods from RFC4997 and RFC4996
00023  * @author FWX <rohc_team@dialine.fr>
00024  * @author Didier Barvaux <didier@barvaux.org>
00025  */
00026 
00027 #ifndef ROHC_COMP_SCHEMES_RFC4996_H
00028 #define ROHC_COMP_SCHEMES_RFC4996_H
00029 
00030 #include "protocols/tcp.h"
00031 #include "schemes/wlsb.h"
00032 
00033 #include <stdint.h>
00034 
00035 #include "dllexport.h"
00036 
00037 
00038 struct rohc_comp_ctxt;
00039 
00040 extern unsigned int ROHC_EXPORT lsb_xor_masks[];
00041 
00042 
00043 /**
00044  * @brief Define union of different compressed datas pointers
00045  */
00046 typedef union
00047 {
00048         unsigned int uint;
00049         uint8_t *uint8;
00050         uint16_t *uint16;
00051         uint32_t *uint32;
00052 
00053         ip_opt_static_t *ip_opt_static;
00054         ip_opt_dynamic_t *ip_opt_dynamic;
00055 
00056         ip_dest_opt_static_t *ip_dest_opt_static;
00057         ip_dest_opt_dynamic_t *ip_dest_opt_dynamic;
00058         ip_hop_opt_static_t *ip_hop_opt_static;
00059         ip_hop_opt_dynamic_t *ip_hop_opt_dynamic;
00060         ip_rout_opt_static_t *ip_rout_opt_static;
00061         ip_gre_opt_static_t *ip_gre_opt_static;
00062         ip_mime_opt_static_t *ip_mime_opt_static;
00063         ip_ah_opt_static_t *ip_ah_opt_static;
00064         ip_ah_opt_dynamic_t *ip_ah_opt_dynamic;
00065 
00066         ipv4_static_t *ipv4_static;
00067         ipv4_dynamic1_t *ipv4_dynamic1;
00068         ipv4_dynamic2_t *ipv4_dynamic2;
00069         ipv4_replicate_t *ipv4_replicate;
00070         ipv6_static1_t *ipv6_static1;
00071         ipv6_static2_t *ipv6_static2;
00072         ipv6_dynamic_t *ipv6_dynamic;
00073         ipv6_replicate1_t *ipv6_replicate1;
00074         ipv6_replicate2_t *ipv6_replicate2;
00075         tcp_static_t *tcp_static;
00076         tcp_dynamic_t *tcp_dynamic;
00077         tcp_replicate_t *tcp_replicate;
00078         co_common_t *co_common;
00079         rnd_1_t *rnd1;
00080         rnd_2_t *rnd2;
00081         rnd_3_t *rnd3;
00082         rnd_4_t *rnd4;
00083         rnd_5_t *rnd5;
00084         rnd_6_t *rnd6;
00085         rnd_7_t *rnd7;
00086         rnd_8_t *rnd8;
00087         seq_1_t *seq1;
00088         seq_2_t *seq2;
00089         seq_3_t *seq3;
00090         seq_4_t *seq4;
00091         seq_5_t *seq5;
00092         seq_6_t *seq6;
00093         seq_7_t *seq7;
00094         seq_8_t *seq8;
00095 } multi_ptr_t;
00096 
00097 
00098 
00099 // RFC4997 page 27
00100 uint32_t ROHC_EXPORT c_lsb(const struct rohc_comp_ctxt *const context,
00101                            int num_lsbs_param,
00102                            unsigned int offset_param,
00103                            unsigned int context_value,
00104                            unsigned int original_value);
00105 
00106 /* static_or_irreg encoding for 8-bit and 16-bit values */
00107 int c_static_or_irreg8(const uint8_t context_value,
00108                        const uint8_t packet_value,
00109                        uint8_t *const rohc_data,
00110                        int *const indicator)
00111         __attribute__((warn_unused_result, nonnull(3, 4)));
00112 int c_static_or_irreg16(const uint16_t context_value,
00113                         const uint16_t packet_value,
00114                         uint8_t *const rohc_data,
00115                         int *const indicator)
00116         __attribute__((warn_unused_result, nonnull(3, 4)));
00117 
00118 /* zero_or_irreg encoding for 8-bit, 16-bit and 32-bit values */
00119 int c_zero_or_irreg8(const uint8_t packet_value,
00120                      uint8_t *const rohc_data,
00121                      int *const indicator)
00122         __attribute__((warn_unused_result, nonnull(2, 3)));
00123 int c_zero_or_irreg16(const uint16_t packet_value,
00124                       uint8_t *const rohc_data,
00125                       int *const indicator)
00126         __attribute__((warn_unused_result, nonnull(2, 3)));
00127 int c_zero_or_irreg32(const uint32_t packet_value,
00128                       uint8_t *const rohc_data,
00129                       int *const indicator)
00130         __attribute__((warn_unused_result, nonnull(2, 3)));
00131 
00132 /* variable_length_32_enc encoding method */
00133 size_t ROHC_EXPORT variable_length_32_enc(const uint32_t old_value,
00134                                           const uint32_t new_value,
00135                                           const size_t nr_bits_63,
00136                                           const size_t nr_bits_16383,
00137                                           uint8_t *const rohc_data,
00138                                           int *const indicator)
00139         __attribute__((nonnull(5, 6), warn_unused_result));
00140 
00141 /* optional32 encoding method */
00142 int c_optional32(const int indicator,
00143                  const uint32_t packet_value,
00144                  uint8_t *const rohc_data)
00145         __attribute__((warn_unused_result, nonnull(3)));
00146 
00147 /* lsb_7_or_31 encoding method */
00148 int c_lsb_7_or_31(const uint32_t context_value,
00149                   const uint32_t packet_value,
00150                   uint8_t *const rohc_data)
00151         __attribute__((warn_unused_result, nonnull(3)));
00152 
00153 /* RFC4996 page 49 */
00154 void c_field_scaling(uint32_t *const scaled_value,
00155                      uint32_t *const residue_field,
00156                      const uint32_t scaling_factor,
00157                      const uint32_t unscaled_value)
00158         __attribute__((nonnull(1, 2)));
00159 
00160 // RFC4996 page 71
00161 unsigned int rsf_index_enc(const struct rohc_comp_ctxt *const context,
00162                            unsigned int rsf_flags);
00163 // RFC4996 page 75
00164 uint16_t c_ip_id_lsb(const struct rohc_comp_ctxt *const context,
00165                      const int behavior,
00166                      const unsigned int k,
00167                      const unsigned int p,
00168                      const uint16_t context_ip_id,
00169                      const uint16_t ip_id,
00170                      const uint16_t msn)
00171         __attribute__((warn_unused_result, nonnull(1)));
00172 
00173 /* optional_ip_id_lsb encoding method */
00174 int c_optional_ip_id_lsb(const struct rohc_comp_ctxt *const context,
00175                          const int behavior,
00176                          const uint16_t context_ip_id,
00177                          const uint16_t ip_id,
00178                          const uint16_t msn,
00179                          uint8_t *const rohc_data,
00180                          int *const indicator)
00181         __attribute__((warn_unused_result, nonnull(1, 6, 7)));
00182 
00183 // RFC4996 page 75
00184 unsigned int dscp_encode(multi_ptr_t *pmptr,
00185                          const uint8_t context_value,
00186                          const uint8_t value)
00187         __attribute__((warn_unused_result, nonnull(1)));
00188 
00189 #endif /* ROHC_COMP_RFC4996_ENCODING_H */
00190