00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef ROHC_BIT_OPS_H
00028 #define ROHC_BIT_OPS_H
00029
00030 #ifdef __KERNEL__
00031 # include <endian.h>
00032 # include <bitops.h>
00033 #else
00034 # include "config.h"
00035 #endif
00036
00037
00038
00039
00040
00041
00042
00043 #define GET_BIT_0(x) ((*(x)) & 0x01)
00044 #define GET_BIT_1(x) ((*(x)) & 0x02)
00045 #define GET_BIT_2(x) ((*(x)) & 0x04)
00046 #define GET_BIT_3(x) ((*(x)) & 0x08)
00047 #define GET_BIT_4(x) ((*(x)) & 0x10)
00048 #define GET_BIT_5(x) ((*(x)) & 0x20)
00049 #define GET_BIT_6(x) ((*(x)) & 0x40)
00050 #define GET_BIT_7(x) ((*(x)) & 0x80)
00051
00052
00053
00054
00055
00056
00057
00058 #define GET_BIT_0_2(x) ((*(x)) & 0x07)
00059 #define GET_BIT_0_4(x) ((*(x)) & 0x1f)
00060 #define GET_BIT_0_3(x) ((*(x)) & 0x0f)
00061 #define GET_BIT_0_5(x) ((*(x)) & 0x3f)
00062 #define GET_BIT_0_6(x) ((*(x)) & 0x7f)
00063 #define GET_BIT_0_7(x) ((*(x)) & 0xff)
00064
00065
00066
00067
00068
00069
00070
00071 #define GET_BIT_1_7(x) ( ((*(x)) & 0xfe) >> 1 )
00072 #define GET_BIT_3_4(x) ( ((*(x)) & 0x18) >> 3 )
00073 #define GET_BIT_3_5(x) ( ((*(x)) & 0x38) >> 3 )
00074 #define GET_BIT_3_6(x) ( ((*(x)) & 0x78) >> 3 )
00075 #define GET_BIT_3_7(x) ( ((*(x)) & 0xf8) >> 3 )
00076 #define GET_BIT_4_7(x) ( ((*(x)) & 0xf0) >> 4 )
00077 #define GET_BIT_5_7(x) ( ((*(x)) & 0xe0) >> 5 )
00078 #define GET_BIT_6_7(x) ( ((*(x)) & 0xc0) >> 6 )
00079 #define GET_BIT_4_6(x) ( ((*(x)) & 0x70) >> 4 )
00080
00081
00082
00083
00084
00085
00086
00087 #define GET_REAL(x) ((x) ? 1 : 0)
00088
00089
00090
00091
00092
00093
00094
00095 #define GET_BOOL(x) ((x) ? true : false)
00096
00097
00098
00099
00100
00101
00102 #if WORDS_BIGENDIAN == 1
00103 # define GET_NEXT_16_BITS(x) \
00104 ((((*(x)) << 8) & 0xff00) | ((*((x) + 1)) & 0x00ff))
00105 #else
00106 # define GET_NEXT_16_BITS(x) \
00107 ((((*((x) + 1)) << 8) & 0xff00) | ((*(x)) & 0x00ff))
00108 #endif
00109
00110
00111
00112 #define APPEND_BITS(field_descr, ext_no, field, field_nr, bits, bits_nr, max) \
00113 do \
00114 { \
00115 \
00116 const typeof(bits) _bits = (bits); \
00117 const size_t _bits_nr = (bits_nr); \
00118 const size_t _max = (max); \
00119 \
00120 rohc_decomp_debug(context, \
00121 "%zd bits of " #field_descr " found in %s = 0x%x", \
00122 (_bits_nr), rohc_get_ext_descr(ext_no), (_bits)); \
00123 \
00124 if(((field_nr) + (_bits_nr)) <= (_max)) \
00125 { \
00126 \
00127 field <<= (_bits_nr); \
00128 field &= ~((1U << (_bits_nr)) - 1); \
00129 field |= (_bits); \
00130 field_nr += (_bits_nr); \
00131 } \
00132 else \
00133 { \
00134 \
00135 typeof(field) _mask; \
00136 assert((_bits_nr) > 0); \
00137 assert((_bits_nr) <= (_max)); \
00138 \
00139 _mask = (1U << ((_max) - (_bits_nr))) - 1; \
00140 if((field & _mask) != field) \
00141 { \
00142 rohc_info((context)->decompressor, ROHC_TRACE_DECOMP, \
00143 (context)->profile->id, \
00144 "too many bits for " #field_descr ": %zu bits found " \
00145 "in %s, and %zu bits already found before for a " \
00146 "%zu-bit field", (_bits_nr), \
00147 rohc_get_ext_descr(ext_no), (field_nr), (_max)); \
00148 } \
00149 field &= _mask; \
00150 \
00151 field <<= (_bits_nr); \
00152 field &= ~((1U << (_bits_nr)) - 1); \
00153 \
00154 field |= (_bits); \
00155 field_nr = (_max); \
00156 } \
00157 } \
00158 while(0)
00159
00160
00161 #define APPEND_SN_BITS(ext_no, base, bits, bits_nr) \
00162 APPEND_BITS(SN, ext_no, \
00163 (base)->sn, (base)->sn_nr, \
00164 (bits), (bits_nr), 32)
00165
00166
00167 #define APPEND_OUTER_IP_ID_BITS(ext_no, base, bits, bits_nr) \
00168 APPEND_BITS(outer IP-ID, ext_no, \
00169 (base)->outer_ip.id, (base)->outer_ip.id_nr, \
00170 (bits), (bits_nr), 16)
00171
00172
00173 #define APPEND_INNER_IP_ID_BITS(ext_no, base, bits, bits_nr) \
00174 APPEND_BITS(inner IP-ID, ext_no, \
00175 (base)->inner_ip.id, (base)->inner_ip.id_nr, \
00176 (bits), (bits_nr), 16)
00177
00178
00179 #define APPEND_TS_BITS(ext_no, base, bits, bits_nr) \
00180 APPEND_BITS(TS, ext_no, \
00181 (base)->ts, (base)->ts_nr, \
00182 (bits), (bits_nr), 32)
00183
00184 #endif
00185