1 |
/* |
2 |
ROHC Project 2003 at Lulea University of Technology, Sweden. |
3 |
Authors: Andreas Vernersson <andver-8@student.luth.se> |
4 |
Daniel Pettersson <danpet-7@student.luth.se> |
5 |
Erik Soderstrom <soderstrom@yahoo.com> |
6 |
Fredrik Lindstrom <frelin-9@student.luth.se> |
7 |
Johan Stenmark <johste-8@student.luth.se> |
8 |
Martin Juhlin <juhlin@users.sourceforge.net> |
9 |
Mikael Larsson <larmik-9@student.luth.se> |
10 |
Robert Maxe <robmax-1@student.luth.se> |
11 |
|
12 |
Copyright (C) 2003 Andreas Vernersson, Daniel Pettersson, |
13 |
Erik Soderström, Fredrik Lindström, Johan Stenmark, |
14 |
Martin Juhlin, Mikael Larsson, Robert Maxe. |
15 |
|
16 |
This program is free software; you can redistribute it and/or modify |
17 |
it under the terms of the GNU General Public License as published by |
18 |
the Free Software Foundation; either version 2 of the License, or |
19 |
(at your option) any later version. |
20 |
|
21 |
This program is distributed in the hope that it will be useful, |
22 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 |
GNU General Public License for more details. |
25 |
|
26 |
You should have received a copy of the GNU General Public License |
27 |
along with this program; if not, write to the Free Software |
28 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
29 |
*/ |
30 |
#ifndef _ROHC_H |
31 |
#define _ROHC_H |
32 |
|
33 |
#include <netinet/ip.h> |
34 |
#include <netinet/udp.h> |
35 |
|
36 |
#include <inttypes.h> |
37 |
|
38 |
uint16_t typedef u16; |
39 |
uint32_t typedef u32; |
40 |
|
41 |
// ROHC_DEBUG_LEVEL determines the level of output produced by ROHC module |
42 |
// 0 == error messages only (useable in kernel module) |
43 |
// 1 == a few informative messages also |
44 |
// 2 == more informative messages (useable for user mode debugging) |
45 |
// 3 == even more informative messages |
46 |
#define ROHC_DEBUG_LEVEL 0 |
47 |
|
48 |
#define ROHC_OK 1 |
49 |
#define ROHC_OK_NO_DATA 0 |
50 |
#define ROHC_ERROR -5 |
51 |
#define ROHC_ERROR_NO_CONTEXT -1 |
52 |
#define ROHC_ERROR_PACKAGE_FAILED -2 |
53 |
#define ROHC_FEEDBACK_ONLY -3 |
54 |
#define ROHC_ERROR_CRC -4 |
55 |
|
56 |
#define ROHC_TRUE 1 |
57 |
#define ROHC_FALSE 0 |
58 |
|
59 |
typedef unsigned char boolean; |
60 |
|
61 |
#define ROHC_LARGE_CID 1 |
62 |
#define ROHC_SMALL_CID 2 |
63 |
|
64 |
#define ROHC_U_MODE 1 |
65 |
#define ROHC_O_MODE 2 |
66 |
#define ROHC_R_MODE 3 |
67 |
|
68 |
#define ROHC_NO_CONTEXT 1 |
69 |
#define ROHC_STATIC_CONTEXT 2 |
70 |
#define ROHC_FULL_CONTEXT 3 |
71 |
|
72 |
#define GET_BIT_0_2(x) ((*x) & 0x07) |
73 |
#define GET_BIT_0_4(x) ((*x) & 0x1f) |
74 |
#define GET_BIT_0_3(x) ( ((*x) & 0x0f) ) |
75 |
#define GET_BIT_0_5(x) ((*x) & 0x3f) |
76 |
#define GET_BIT_0_6(x) ((*x) & 0x7f) |
77 |
#define GET_BIT_0_7(x) ((*x) & 0xff) |
78 |
|
79 |
#define GET_BIT_1_7(x) ( ((*x) & 0xfe) >> 1 ) |
80 |
#define GET_BIT_3_4(x) ( ((*x) & 0x18) >> 3 ) |
81 |
#define GET_BIT_3_5(x) ( ((*x) & 0x38) >> 3 ) |
82 |
#define GET_BIT_3_6(x) ( ((*x) & 0x78) >> 3 ) |
83 |
#define GET_BIT_3_7(x) ( ((*x) & 0xf8) >> 3 ) |
84 |
#define GET_BIT_4_7(x) ( ((*x) & 0xf0) >> 4 ) |
85 |
#define GET_BIT_5_7(x) ( ((*x) & 0xe0) >> 5 ) |
86 |
#define GET_BIT_6_7(x) ( ((*x) & 0xc0) >> 6 ) |
87 |
|
88 |
#define GET_DUAL_0_4_AND_7(x, y) ( ((*x) & 0x1f) << 1 | ( (*y) & 0x01 ) ) |
89 |
#define GET_DUAL_0_2_AND_ALL(x, y) ( ((*x) & 0x03) << 1 | ( (*y) & 0xff ) ) |
90 |
|
91 |
#define GET_BIT_0(x) ((*x) & 0x01) |
92 |
#define GET_BIT_1(x) ((*x) & 0x02) |
93 |
#define GET_BIT_2(x) ((*x) & 0x04) |
94 |
#define GET_BIT_3(x) ((*x) & 0x08) |
95 |
#define GET_BIT_4(x) ((*x) & 0x10) |
96 |
#define GET_BIT_5(x) ((*x) & 0x20) |
97 |
#define GET_BIT_6(x) ((*x) & 0x40) |
98 |
#define GET_BIT_7(x) ((*x) & 0x80) |
99 |
|
100 |
// Convert GET_BIT_x values to 0 or 1.. |
101 |
// example: GET_REAL( GET_BIT_5(data_ptr) ); |
102 |
#define GET_REAL(x) ( (x) ? 1 : 0 ) |
103 |
|
104 |
#define C_WINDOW_WIDTH 16 |
105 |
|
106 |
|
107 |
// Defines for the compressor profiles |
108 |
|
109 |
#define GET_DF(x) ((ntohs(x)>>14)&1) |
110 |
|
111 |
#define MOD_TOS 0x01 |
112 |
#define MOD_TOT_LEN 0x02 |
113 |
#define MOD_ID 0x04 |
114 |
#define MOD_FRAG_OFF 0x08 |
115 |
#define MOD_TTL 0x10 |
116 |
#define MOD_PROTOCOL 0x20 |
117 |
#define MOD_CHECK 0x40 |
118 |
#define MOD_SADDR 0x80 |
119 |
#define MOD_DADDR 0x0100 |
120 |
|
121 |
#define c_IR 0 |
122 |
#define c_IRDYN 1 |
123 |
#define c_UO0 2 |
124 |
#define c_UO1 3 |
125 |
#define c_UO2 4 |
126 |
|
127 |
#define c_NOEXT 0 |
128 |
#define c_EXT0 1 |
129 |
#define c_EXT1 2 |
130 |
#define c_EXT2 3 |
131 |
#define c_EXT3 4 |
132 |
|
133 |
#define CHANGE_TO_FO_COUNT 700 |
134 |
#define CHANGE_TO_IR_COUNT 1700 |
135 |
|
136 |
#define MAX_IR_COUNT 3 |
137 |
#define MAX_FO_COUNT 3 |
138 |
|
139 |
#define IPID_MAX_DELTA 20 |
140 |
|
141 |
// Defines for profiles in decomp. |
142 |
|
143 |
#define PACKAGE_UO_0 0 |
144 |
#define PACKAGE_UO_1 1 |
145 |
#define PACKAGE_UOR_2 2 |
146 |
#define PACKAGE_IR_DYN 3 |
147 |
#define PACKAGE_IR 4 |
148 |
#define PACKAGE_UNKNOWN 5 |
149 |
#define PACKAGE_CE 6 |
150 |
#define PACKAGE_CE_OFF 7 |
151 |
|
152 |
// DO NOT CHANGE THESE NUMBERS! |
153 |
#define PACKAGE_EXT_0 0 |
154 |
#define PACKAGE_EXT_1 1 |
155 |
#define PACKAGE_EXT_2 2 |
156 |
#define PACKAGE_EXT_3 3 |
157 |
|
158 |
#define PROTOCOL_IP_IN_IP 4 |
159 |
#define PROTOCOL_IP6 41 |
160 |
|
161 |
#define IP_DF 0x4000 /* Flag: "Don't Fragment" */ |
162 |
|
163 |
#define CRC_ACTION 1 |
164 |
|
165 |
#define WEIGHT_OLD 1 |
166 |
#define WEIGHT_NEW 1 |
167 |
|
168 |
#include <stdio.h> |
169 |
#include <stdlib.h> |
170 |
#include <time.h> |
171 |
#include <sys/time.h> |
172 |
|
173 |
#define KERN_DEBUG stderr |
174 |
#define GFP_KERNEL 0 |
175 |
#define GFP_ATOMIC 1 |
176 |
#define printk printf |
177 |
#define kfree free |
178 |
|
179 |
static inline void * kmalloc(int size, int type) { |
180 |
if (type != GFP_ATOMIC) { |
181 |
printf("wrong kmalloc type..\n"); |
182 |
exit(0); |
183 |
} |
184 |
return malloc(size); |
185 |
} |
186 |
|
187 |
#include <stdarg.h> |
188 |
#define rohc_debugf(level, format...) if (level<=ROHC_DEBUG_LEVEL) { printf(format); } else |
189 |
|
190 |
#if defined(__i386__) && defined(__GNUC__) |
191 |
/* |
192 |
* This is a version of ip_compute_csum() optimized for IP headers, |
193 |
* which always checksum on 4 octet boundaries. |
194 |
* |
195 |
* By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by |
196 |
* Arnt Gulbrandsen. |
197 |
*/ |
198 |
static inline unsigned short ip_fast_csum(unsigned char * iph, |
199 |
unsigned int ihl) { |
200 |
unsigned int sum; |
201 |
|
202 |
__asm__ __volatile__(" \n\ |
203 |
movl (%1), %0 \n\ |
204 |
subl $4, %2 \n\ |
205 |
jbe 2f \n\ |
206 |
addl 4(%1), %0 \n\ |
207 |
adcl 8(%1), %0 \n\ |
208 |
adcl 12(%1), %0 \n\ |
209 |
1: adcl 16(%1), %0 \n\ |
210 |
lea 4(%1), %1 \n\ |
211 |
decl %2 \n\ |
212 |
jne 1b \n\ |
213 |
adcl $0, %0 \n\ |
214 |
movl %0, %2 \n\ |
215 |
shrl $16, %0 \n\ |
216 |
addw %w2, %w0 \n\ |
217 |
adcl $0, %0 \n\ |
218 |
notl %0 \n\ |
219 |
2: \n\ |
220 |
" |
221 |
/* Since the input registers which are loaded with iph and ipl |
222 |
are modified, we must also specify them as outputs, or gcc |
223 |
will assume they contain their original values. */ |
224 |
: "=r" (sum), "=r" (iph), "=r" (ihl) |
225 |
: "1" (iph), "2" (ihl)); |
226 |
return(sum); |
227 |
} |
228 |
#else |
229 |
# error "non-asm version of ip_fast_csum is required but not yet coded" |
230 |
#endif |
231 |
|
232 |
static inline int get_microseconds(void) { |
233 |
struct timeval tv; |
234 |
gettimeofday(&tv, NULL); |
235 |
return tv.tv_sec * 1000000 + tv.tv_usec; |
236 |
} |
237 |
|
238 |
|
239 |
static inline int get_milliseconds(void) { |
240 |
struct timeval tv; |
241 |
gettimeofday(&tv, NULL); |
242 |
return tv.tv_sec * 1000 + tv.tv_usec/1000; |
243 |
} |
244 |
|
245 |
#define simple_strtol strtol |
246 |
|
247 |
#endif |