ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/rohc/comp.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     /***************************************************************************
31     * File: comp.h *
32     * Description: Functions and structures for the compressor framework *
33     ***************************************************************************/
34    
35     #ifndef _COMP_H
36     #define _COMP_H
37    
38     #include <linux/ip.h>
39     #include "rohc.h"
40    
41     /////////////////////////////////////////////////////////////////////
42     // Public functions
43    
44     struct sc_rohc;
45     struct sc_context;
46     struct sc_feedback;
47    
48     /* Allocate space for a compressor (transmit side) */
49     void *rohc_alloc_compressor(int max_cid);
50    
51     /* Free space used by a compressor */
52     void rohc_free_compressor(struct sc_rohc *compressor);
53    
54     /* Compress a packet */
55     int rohc_compress(struct sc_rohc *compressor, unsigned char *ibuf, int isize,
56     unsigned char *obuf, int osize);
57    
58     /* Store static info (about profiles etc) in the buffer (no compressor is needed) */
59     int rohc_c_info(char *buffer);
60    
61     /* Store compression statistics for a compressor in the buffer */
62     int rohc_c_statistics(struct sc_rohc *compressor, char *buffer);
63    
64     /* Store context statistics for a compressor in the buffer */
65     int rohc_c_context(struct sc_rohc *compressor, int index, char *buffer);
66    
67     /* Get compressor enabled/disable status */
68     int rohc_c_is_enabled(struct sc_rohc *compressor);
69    
70     /* Is the compressor using small cid? */
71     int rohc_c_using_small_cid(struct sc_rohc * ch);
72    
73    
74     // Functions used by rohc's proc device
75    
76     void rohc_c_set_header(struct sc_rohc *compressor, int value);
77     void rohc_c_set_mrru(struct sc_rohc *compressor, int value);
78     void rohc_c_set_max_cid(struct sc_rohc *compressor, int value);
79     void rohc_c_set_large_cid(struct sc_rohc *compressor, int value);
80     void rohc_c_set_connection_type(struct sc_rohc *compressor, int value);
81     void rohc_c_set_enable(struct sc_rohc *compressor, int value);
82    
83     // These functions are used by the decompressor to send feedback..
84    
85     // Add this feedback to the next outgoing ROHC packet:
86     void c_piggyback_feedback(struct sc_rohc *,unsigned char *, int size);
87    
88     // Deliver received feedback in in decompressor to compressor..
89     void c_deliver_feedback(struct sc_rohc *,unsigned char *packet, int size);
90    
91    
92     /////////////////////////////////////////////////////////////////////
93     // Profiles
94    
95     #define C_NUM_PROFILES 4
96    
97     // The generic interface to compression profiles
98    
99     // To implement a new profile you need to implement the following interface
100     // (see c_ip.c or c_udp.c for examples) and add it to the "c_profiles" array
101     // in comp.c
102    
103     struct sc_profile {
104     unsigned short protocol; // IP-Protocol
105     unsigned short id; // Profile ID
106     char *version; // Version string
107     char *description; // Description string
108    
109     // Called when a new context should be initialized, based on the given packet
110     int (*create)(struct sc_context *context, const struct iphdr *packet);
111    
112     // Destroy profile specific data in context
113     void (*destroy)(struct sc_context *context);
114    
115     // Check if the packet belongs to the given context (using STATIC-DEF fields etc) */
116     int (*check_context)(struct sc_context *context, const struct iphdr *packet);
117    
118     // Compress the packet using the given context. Payload_offset indicates where the
119     // payload starts. Returns the size of the compressed packet or <=0 in case of an
120     // error..
121     int (*encode)(struct sc_context *, const struct iphdr *packet, int packet_size,
122     unsigned char *dest, int dest_size, int *payload_offset);
123    
124     // Called when feedback to the context arrives..
125     void (*feedback)(struct sc_context *, struct sc_feedback *);
126     };
127    
128     struct sc_profile *c_get_profile_from_protocol(struct sc_rohc *comp, int protocol);
129     struct sc_profile *c_get_profile_from_id(struct sc_rohc *comp, int profile_id);
130    
131     ////////////////////////////////////////////////////////////////////////
132    
133     typedef enum {U=1,O=2,R=3} C_MODE;
134     typedef enum {IR=1,FO=2,SO=3} C_STATE;
135    
136     struct sc_context {
137     int used; // 1==used, 0==unused
138     int latest_used; // time when this context was created
139     int first_used; // time when this context was latest used
140    
141     int cid;
142     int profile_id;
143     struct sc_profile *profile;
144    
145     struct sc_rohc *compressor;
146    
147     // Parameters and initial values common for all
148     // profiles:
149    
150     C_MODE c_mode;
151     C_STATE c_state;
152    
153     int nbo, rnd;
154     int nbo2, rnd2; // for second ip header if available
155    
156     // Statistics information
157     int total_uncompressed_size, total_compressed_size;
158     int header_uncompressed_size, header_compressed_size;
159     int num_send_packets, num_send_ir, num_send_ir_dyn, num_recv_feedbacks;
160     struct sc_wlsb *total_16_uncompressed, *total_16_compressed;
161     struct sc_wlsb *header_16_uncompressed, *header_16_compressed;
162    
163    
164     // Profile specific context here:
165     void *profile_context;
166     };
167    
168    
169     // Create a new context
170     struct sc_context *c_create_context(struct sc_rohc *, struct sc_profile *profile, struct iphdr *ip);
171    
172     // Find a context that match the given profile and IP-packet
173     struct sc_context *c_find_context(struct sc_rohc *, struct sc_profile *profile, struct iphdr *ip);
174    
175     // Find a context given the CID
176     struct sc_context *c_get_context(struct sc_rohc *, int cid);
177     /////////////////////////////////////////////////////////////////////
178    
179     struct sc_feedback {
180     unsigned char size; // =field(size) om field(code)==0, annars =field(code)
181     int cid;
182    
183     int type; // 1=FEEDBACK-1, 2=FEEDBACK-2
184    
185     unsigned char *data; // whole feedback packet exluding first feedback-type octet
186     int specific_offset;
187     int specific_size;
188    
189     // feedback-2 only:
190     enum {ACK,NACK,STATIC_NACK,RESERVED} acktype; // 0=ACK, 1=NACK, 2=STATIC-NACK, 3=RESERVED
191     };
192    
193     /////////////////////////////////////////////////////////////////////
194    
195     #define FEEDBACK_BUFFER_SIZE 10 // Number of outgoing feedbacks that can be queued..
196    
197     struct sc_rohc {
198     int enabled;
199    
200     int max_cid; // smallCID = [0-15], largeCID = [0-65535]
201     int large_cid;
202    
203     int num_used;
204     int num_allocated;
205     struct sc_context *contexts; // allokeras om vid behov.
206    
207     int mrru; // Maximum reconstructed reception unit (== 0)
208     int max_header_size; // Maximum header size that will be compressed
209     int connection_type;
210    
211     int profiles[C_NUM_PROFILES];
212    
213     unsigned char *feedback_buffer[FEEDBACK_BUFFER_SIZE];
214     unsigned int feedback_size [FEEDBACK_BUFFER_SIZE];
215     int feedback_pointer;
216    
217     int num_packets; // total number of sent packets
218     int total_compressed_size, total_uncompressed_size;
219    
220     struct sc_rohc *feedback_for;
221    
222     };
223    
224     int c_get_feedback(struct sc_rohc *, unsigned char *);
225     void c_add_feedback(struct sc_rohc *, unsigned char *, int size);
226    
227     /////////////////////////////////////////////////////////////////////
228    
229     #endif