00001 /* 00002 * Copyright 2011,2012,2013 Didier Barvaux 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00017 */ 00018 00019 /** 00020 * @file interval.h 00021 * @brief Compute the interpretation interval for LSB and W-LSB encoding 00022 * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com> 00023 */ 00024 00025 #ifndef ROHC_COMMON_INTERVAL_H 00026 #define ROHC_COMMON_INTERVAL_H 00027 00028 #include <stdlib.h> 00029 #include <stdint.h> 00030 #include <assert.h> 00031 00032 00033 /** 00034 * @brief the different values of the shift parameter of the LSB algorithm 00035 * 00036 * The shift parameter is also named 'p' in some RFCs. 00037 * 00038 * Some values are the real values to use directly. Some others are code 00039 * that means that the real value to use shall be computed from the number 00040 * of least significant bits that are transmitted. 00041 */ 00042 typedef enum 00043 { 00044 ROHC_LSB_SHIFT_SN = -1, /**< real value for non-RTP SN */ 00045 #define ROHC_LSB_SHIFT_TCP_TS_1B ROHC_LSB_SHIFT_SN /**< real value for TCP TS */ 00046 #define ROHC_LSB_SHIFT_TCP_TS_2B ROHC_LSB_SHIFT_SN /**< real value for TCP TS */ 00047 ROHC_LSB_SHIFT_IP_ID = 0, /**< real value for IP-ID */ 00048 ROHC_LSB_SHIFT_TCP_TTL = 3, /**< real value for TCP TTL/HL */ 00049 #define ROHC_LSB_SHIFT_TCP_ACK_SCALED ROHC_LSB_SHIFT_TCP_TTL 00050 ROHC_LSB_SHIFT_TCP_SN = 4, /**< real value for TCP MSN */ 00051 ROHC_LSB_SHIFT_TCP_SEQ_SCALED = 7, /**< real value for TCP seq/ack scaled */ 00052 ROHC_LSB_SHIFT_RTP_TS = 100, /**< need to compute real value for RTP TS */ 00053 ROHC_LSB_SHIFT_RTP_SN = 101, /**< need to compute real value for RTP SN */ 00054 ROHC_LSB_SHIFT_ESP_SN = 102, /**< need to compute real value for ESP SN */ 00055 ROHC_LSB_SHIFT_VAR = 103, /**< real value is variable */ 00056 ROHC_LSB_SHIFT_TCP_WINDOW = 16383, /**< real value for TCP window */ 00057 ROHC_LSB_SHIFT_TCP_TS_3B = 0x00040000, /**< real value for TCP TS */ 00058 ROHC_LSB_SHIFT_TCP_TS_4B = 0x04000000, /**< real value for TCP TS */ 00059 } rohc_lsb_shift_t; 00060 00061 00062 /** 00063 * @brief An interval of 8-bit values 00064 * 00065 * Lower and upper bound values are always included in the interval. 00066 * 00067 * The upper bound may be greater that the lower bound of the interval if the 00068 * interval straddles the interval boundaries. 00069 * 00070 * Example of interval that does not straddle field boundaries: 00071 * [1, 3] 00072 * 00073 * Example of interval that straddles field boundaries (8-bit field): 00074 * [250, 4] 00075 */ 00076 struct rohc_interval8 00077 { 00078 uint8_t min; /**< The lower bound of the interval */ 00079 uint8_t max; /**< The upper bound of the interval */ 00080 }; 00081 00082 00083 /** 00084 * @brief An interval of 16-bit values 00085 * 00086 * Lower and upper bound values are always included in the interval. 00087 * 00088 * The upper bound may be greater that the lower bound of the interval if the 00089 * interval straddles the interval boundaries. 00090 * 00091 * Example of interval that does not straddle field boundaries: 00092 * [1, 3] 00093 * 00094 * Example of interval that straddles field boundaries (16-bit field): 00095 * [65530, 4] 00096 */ 00097 struct rohc_interval16 00098 { 00099 uint16_t min; /**< The lower bound of the interval */ 00100 uint16_t max; /**< The upper bound of the interval */ 00101 }; 00102 00103 00104 /** 00105 * @brief An interval of 32-bit values 00106 * 00107 * Lower and upper bound values are always included in the interval. 00108 * 00109 * The upper bound may be greater that the lower bound of the interval if the 00110 * interval straddles the interval boundaries. 00111 * 00112 * Example of interval that does not straddle field boundaries: 00113 * [1, 3] 00114 * 00115 * Example of interval that straddles field boundaries (32-bit field): 00116 * [65530, 4] 00117 */ 00118 struct rohc_interval32 00119 { 00120 uint32_t min; /**< The lower bound of the interval */ 00121 uint32_t max; /**< The upper bound of the interval */ 00122 }; 00123 00124 00125 /* 00126 * Public function prototypes: 00127 */ 00128 00129 static inline int32_t rohc_interval_compute_p(const size_t k, 00130 const rohc_lsb_shift_t p) 00131 __attribute__((warn_unused_result, const)); 00132 00133 struct rohc_interval8 rohc_f_8bits(const uint8_t v_ref, 00134 const size_t k, 00135 const rohc_lsb_shift_t p) 00136 __attribute__((warn_unused_result)); 00137 00138 struct rohc_interval16 rohc_f_16bits(const uint16_t v_ref, 00139 const size_t k, 00140 const rohc_lsb_shift_t p) 00141 __attribute__((warn_unused_result)); 00142 00143 struct rohc_interval32 rohc_f_32bits(const uint32_t v_ref, 00144 const size_t k, 00145 const rohc_lsb_shift_t p) 00146 __attribute__((warn_unused_result)); 00147 00148 00149 /** 00150 * @brief Compute the shift parameter p for the f function 00151 * 00152 * @param k The number of least significant bits of the value that are 00153 * transmitted 00154 * @param p The shift parameter (may be negative) 00155 * @return The computed shift parameter p 00156 */ 00157 static inline int32_t rohc_interval_compute_p(const size_t k, 00158 const rohc_lsb_shift_t p) 00159 { 00160 int32_t computed_p; 00161 00162 /* determine the real p value to use */ 00163 switch(p) 00164 { 00165 case ROHC_LSB_SHIFT_RTP_TS: /* special computation for RTP TS encoding */ 00166 { 00167 if(k <= 2) 00168 { 00169 computed_p = 0; 00170 } 00171 else 00172 { 00173 computed_p = (1 << (k - 2)) - 1; 00174 } 00175 } 00176 break; 00177 00178 /* special computation for RTP and ESP SN encoding */ 00179 case ROHC_LSB_SHIFT_RTP_SN: 00180 case ROHC_LSB_SHIFT_ESP_SN: 00181 { 00182 if(k <= 4) 00183 { 00184 computed_p = 1; 00185 } 00186 else 00187 { 00188 computed_p = (1 << (k - 5)) - 1; 00189 } 00190 } 00191 break; 00192 00193 case ROHC_LSB_SHIFT_VAR: 00194 assert(0); /* should not happen */ 00195 computed_p = p; 00196 break; 00197 00198 case ROHC_LSB_SHIFT_SN: 00199 case ROHC_LSB_SHIFT_IP_ID: 00200 case ROHC_LSB_SHIFT_TCP_TTL: 00201 case ROHC_LSB_SHIFT_TCP_SN: 00202 case ROHC_LSB_SHIFT_TCP_SEQ_SCALED: 00203 case ROHC_LSB_SHIFT_TCP_WINDOW: 00204 case ROHC_LSB_SHIFT_TCP_TS_3B: 00205 case ROHC_LSB_SHIFT_TCP_TS_4B: 00206 default: /* otherwise: use the p value given as parameter */ 00207 { 00208 computed_p = p; 00209 } 00210 } 00211 00212 return computed_p; 00213 } 00214 00215 #endif 00216
1.6.1