ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/rohc/rohc.h
Revision: 1.1
Committed: Sun Feb 8 06:02:44 2004 UTC (20 years, 4 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: ROHC-IMPORT-2004-02-08
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29     */
30     #ifndef _ROHC_H
31     #define _ROHC_H
32    
33     // ROHC_DEBUG_LEVEL determines the level of output produced by ROHC module
34     // 0 == error messages only (useable in kernel module)
35     // 1 == a few informative messages also
36     // 2 == more informative messages (useable for user mode debugging)
37     // 3 == even more informative messages
38     #define ROHC_DEBUG_LEVEL 0
39    
40     #define ROHC_OK 1
41     #define ROHC_OK_NO_DATA 0
42     #define ROHC_ERROR -5
43     #define ROHC_ERROR_NO_CONTEXT -1
44     #define ROHC_ERROR_PACKAGE_FAILED -2
45     #define ROHC_FEEDBACK_ONLY -3
46     #define ROHC_ERROR_CRC -4
47    
48     #define ROHC_TRUE 1
49     #define ROHC_FALSE 0
50    
51     typedef unsigned char boolean;
52    
53     #define ROHC_LARGE_CID 1
54     #define ROHC_SMALL_CID 2
55    
56     #define ROHC_U_MODE 1
57     #define ROHC_O_MODE 2
58     #define ROHC_R_MODE 3
59    
60     #define ROHC_NO_CONTEXT 1
61     #define ROHC_STATIC_CONTEXT 2
62     #define ROHC_FULL_CONTEXT 3
63    
64     #define GET_BIT_0_2(x) ((*x) & 0x07)
65     #define GET_BIT_0_4(x) ((*x) & 0x1f)
66     #define GET_BIT_0_3(x) ( ((*x) & 0x0f) )
67     #define GET_BIT_0_5(x) ((*x) & 0x3f)
68     #define GET_BIT_0_6(x) ((*x) & 0x7f)
69     #define GET_BIT_0_7(x) ((*x) & 0xff)
70    
71     #define GET_BIT_1_7(x) ( ((*x) & 0xfe) >> 1 )
72     #define GET_BIT_3_4(x) ( ((*x) & 0x18) >> 3 )
73     #define GET_BIT_3_5(x) ( ((*x) & 0x38) >> 3 )
74     #define GET_BIT_3_6(x) ( ((*x) & 0x78) >> 3 )
75     #define GET_BIT_3_7(x) ( ((*x) & 0xf8) >> 3 )
76     #define GET_BIT_4_7(x) ( ((*x) & 0xf0) >> 4 )
77     #define GET_BIT_5_7(x) ( ((*x) & 0xe0) >> 5 )
78     #define GET_BIT_6_7(x) ( ((*x) & 0xc0) >> 6 )
79    
80     #define GET_DUAL_0_4_AND_7(x, y) ( ((*x) & 0x1f) << 1 | ( (*y) & 0x01 ) )
81     #define GET_DUAL_0_2_AND_ALL(x, y) ( ((*x) & 0x03) << 1 | ( (*y) & 0xff ) )
82    
83     #define GET_BIT_0(x) ((*x) & 0x01)
84     #define GET_BIT_1(x) ((*x) & 0x02)
85     #define GET_BIT_2(x) ((*x) & 0x04)
86     #define GET_BIT_3(x) ((*x) & 0x08)
87     #define GET_BIT_4(x) ((*x) & 0x10)
88     #define GET_BIT_5(x) ((*x) & 0x20)
89     #define GET_BIT_6(x) ((*x) & 0x40)
90     #define GET_BIT_7(x) ((*x) & 0x80)
91    
92     // Convert GET_BIT_x values to 0 or 1..
93     // example: GET_REAL( GET_BIT_5(data_ptr) );
94     #define GET_REAL(x) ( (x) ? 1 : 0 )
95    
96     #define C_WINDOW_WIDTH 16
97    
98    
99     // Defines for the compressor profiles
100    
101     #define GET_DF(x) ((ntohs(x)>>14)&1)
102    
103     #define MOD_TOS 0x01
104     #define MOD_TOT_LEN 0x02
105     #define MOD_ID 0x04
106     #define MOD_FRAG_OFF 0x08
107     #define MOD_TTL 0x10
108     #define MOD_PROTOCOL 0x20
109     #define MOD_CHECK 0x40
110     #define MOD_SADDR 0x80
111     #define MOD_DADDR 0x0100
112    
113     #define c_IR 0
114     #define c_IRDYN 1
115     #define c_UO0 2
116     #define c_UO1 3
117     #define c_UO2 4
118    
119     #define c_NOEXT 0
120     #define c_EXT0 1
121     #define c_EXT1 2
122     #define c_EXT2 3
123     #define c_EXT3 4
124    
125     #define CHANGE_TO_FO_COUNT 700
126     #define CHANGE_TO_IR_COUNT 1700
127    
128     #define MAX_IR_COUNT 3
129     #define MAX_FO_COUNT 3
130    
131     #define IPID_MAX_DELTA 20
132    
133     // Defines for profiles in decomp.
134    
135     #define PACKAGE_UO_0 0
136     #define PACKAGE_UO_1 1
137     #define PACKAGE_UOR_2 2
138     #define PACKAGE_IR_DYN 3
139     #define PACKAGE_IR 4
140     #define PACKAGE_UNKNOWN 5
141     #define PACKAGE_CE 6
142     #define PACKAGE_CE_OFF 7
143    
144     // DO NOT CHANGE THIS NUMBERS!
145     #define PACKAGE_EXT_0 0
146     #define PACKAGE_EXT_1 1
147     #define PACKAGE_EXT_2 2
148     #define PACKAGE_EXT_3 3
149    
150     #define PROTOCOL_IP_IN_IP 4
151     #define PROTOCOL_IP6 41
152    
153     #define IP_DF 0x4000 /* Flag: "Don't Fragment" */
154    
155     #define CRC_ACTION 1
156    
157     #define WEIGHT_OLD 1
158     #define WEIGHT_NEW 1
159    
160     #ifdef USER_SPACE
161     #include <stdio.h>
162     #include <stdlib.h>
163     #include <time.h>
164     #include <sys/time.h>
165    
166     #define KERN_DEBUG stderr
167     #define GFP_KERNEL 0
168     #define GFP_ATOMIC 1
169     #define printk printf
170     #define kfree free
171    
172     static inline void * kmalloc(int size, int type) {
173     if (type != GFP_ATOMIC) {
174     printf("wrong kmalloc type..\n");
175     exit(0);
176     }
177     return malloc(size);
178     }
179    
180     #include <stdarg.h>
181     #define rohc_debugf(level, format...) if (level<=ROHC_DEBUG_LEVEL) { printf(format); } else
182    
183    
184     /*
185     * This is a version of ip_compute_csum() optimized for IP headers,
186     * which always checksum on 4 octet boundaries.
187     *
188     * By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by
189     * Arnt Gulbrandsen.
190     */
191     static inline unsigned short ip_fast_csum(unsigned char * iph,
192     unsigned int ihl) {
193     unsigned int sum;
194    
195     __asm__ __volatile__(" \n\
196     movl (%1), %0 \n\
197     subl $4, %2 \n\
198     jbe 2f \n\
199     addl 4(%1), %0 \n\
200     adcl 8(%1), %0 \n\
201     adcl 12(%1), %0 \n\
202     1: adcl 16(%1), %0 \n\
203     lea 4(%1), %1 \n\
204     decl %2 \n\
205     jne 1b \n\
206     adcl $0, %0 \n\
207     movl %0, %2 \n\
208     shrl $16, %0 \n\
209     addw %w2, %w0 \n\
210     adcl $0, %0 \n\
211     notl %0 \n\
212     2: \n\
213     "
214     /* Since the input registers which are loaded with iph and ipl
215     are modified, we must also specify them as outputs, or gcc
216     will assume they contain their original values. */
217     : "=r" (sum), "=r" (iph), "=r" (ihl)
218     : "1" (iph), "2" (ihl));
219     return(sum);
220     }
221    
222     static inline int get_microseconds(void) {
223     struct timeval tv;
224     gettimeofday(&tv, NULL);
225     return tv.tv_sec * 1000000 + tv.tv_usec;
226     }
227    
228    
229     static inline int get_milliseconds(void) {
230     struct timeval tv;
231     gettimeofday(&tv, NULL);
232     return tv.tv_sec * 1000 + tv.tv_usec/1000;
233     }
234    
235    
236    
237     #define simple_strtol strtol
238    
239     // End of userspace defines..
240     #else
241     // Start of kernel mode defines..
242    
243     #define rohc_debugf(level, format...) if (level<=ROHC_DEBUG_LEVEL) { printk(KERN_INFO format); } else
244    
245     static inline int get_microseconds(void) {
246     struct timeval tv;
247     do_gettimeofday(&tv);
248     return tv.tv_sec * 1000000 + tv.tv_usec;
249     }
250    
251     static inline int get_milliseconds(void) {
252     struct timeval tv;
253     do_gettimeofday(&tv);
254     return tv.tv_sec * 1000 + tv.tv_usec/1000;
255     }
256    
257     #endif // End of kernelsapce defines
258    
259    
260     #endif