ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/rohc/feedback.c
Revision: 1.2
Committed: Tue Apr 26 00:55:56 2005 UTC (19 years, 1 month ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_01, rel-3_0, rel-2_2, rel-2_0, rel-2_21, rel-2_22, rel-2_25, HEAD
Changes since 1.1: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
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 //----------------------------------------------------------------------------------------------------------------------------------
31 #include "comp.h"
32 #include "c_util.h"
33 #include "feedback.h"
34 //----------------------------------------------------------------------------------------------------------------------------------
35 // Builds a feedback1-package
36 // Param sn: sequence-number
37 // Param f: pointer to feedback packet
38 // Return: true if build was ok
39 //----------------------------------------------------------------------------------------------------------------------------------
40 bool f_feedback1(int sn, struct sd_feedback * f)
41 {
42 // int req_sn_bits = calc_feedback_sn_size(); //check if feddback1 is ok ..
43 // if (req_sn_bits < 9) {
44 f->feedback_type = 1; //set type for add_option
45 f->size = 1;
46 f->feedback[0] = (sn & 0xFF);
47 return true;
48 // }
49 // return false;
50 }
51 //----------------------------------------------------------------------------------------------------------------------------------
52 // Builds a feedback2-package
53 // Param achtype: ACK, NACK or S-NACK
54 // Param mode: mode in which ROHC operates; U-, O- or R-MODE
55 // Param sn: sequence-number
56 // Param f: pointer to feedback packet
57 //----------------------------------------------------------------------------------------------------------------------------------
58 void f_feedback2(int acktype, int mode, int sn, struct sd_feedback * f)
59 {
60 // int req_sn_bits=-1;
61 char tkn = (sn & 0xFF);
62 f->size = 2; // size of feedback-2 head
63
64 f->feedback_type = 2; //set type for add_option
65
66 f->feedback[0] = (acktype & 0x3) << 6 | (mode & 0x3) << 4;
67
68 // req_sn_bits = calc_feedback_sn_size();
69
70 if(sn < 255){ //12 bits sn
71 // if(req_sn_bits < 13){
72 f->feedback[0] |= (sn & 0xF00) >> 8;
73 f->feedback[1] = sn & 0xFF;
74 } else { //20 bits sn
75 f->feedback[0] |= (sn & 0xF0000) >> 16;
76 f->feedback[1] = sn & 0xFF00 >> 8;
77 f_add_option(f, OPT_TYPE_SN, &tkn); //return ! important ..
78 }
79 }
80 //----------------------------------------------------------------------------------------------------------------------------------
81 // Adds an option data for feedback2
82 // Param f: pointer to feedback packet
83 // Param opt_type: type of option to be added
84 // Param data: the option data
85 // Return: 0 if failed, 1 if ok
86 //----------------------------------------------------------------------------------------------------------------------------------
87 bool f_add_option(struct sd_feedback * f, int opt_type, char * data)
88 {
89 if (f->feedback_type == 2) {
90 f->feedback[f->size] = opt_type & 0xF;
91 f->feedback[f->size] <<= 4;
92 f->feedback[f->size] = (data ? 1 : 0) | f->feedback[f->size];
93 f->size++;
94
95 if(opt_type == OPT_TYPE_CRC || data) {
96 if(opt_type == OPT_TYPE_CRC)
97 f->feedback[f->size] = 0;
98 else
99 f->feedback[f->size] = data[0];
100 f->size++;
101 }
102 return true;
103 }
104 return false;
105 }
106 //----------------------------------------------------------------------------------------------------------------------------------
107 // Appends the cid on the feedback packet
108 // Param f: pointer to the feedback packet
109 // Param cid: the context-id
110 // Param largecidUsed: ==1 if largecid is used
111 // Return: true if cid was successfully appended, else false
112 //----------------------------------------------------------------------------------------------------------------------------------
113 bool f_append_cid(struct sd_feedback * f, int cid, int largecidUsed)
114 {
115 char * acid;
116 int largecidsize, i;
117
118 if(largecidUsed) { // largecid
119 largecidsize = c_bytesSdvl(cid);
120 if(f->size+largecidsize > 30) {
121 rohc_debugf(0, "ERROR [feedback.c - f_append_cid()]: Array to small!\n");
122 return(false);
123 } else {
124 for(i=f->size-1; i>=0; i--)
125 f->feedback[i+largecidsize] = f->feedback[i];
126 }
127 acid = (char*)kmalloc(largecidsize, GFP_ATOMIC);
128 if(!acid) {
129 f->size = 0;
130 return(false);
131 }
132 if(!c_encodeSdvl(acid, cid)) {
133 rohc_debugf(0, "ERROR [feedback.c - f_append_cid()]: This should never happen!\n");
134 return(false);
135 }
136 memcpy(f->feedback, acid, largecidsize);
137 kfree(acid);
138 f->size += largecidsize;
139 } else {
140 if(cid > 0 && cid < 16) {
141 for(i = f->size-1; i>=0; i--)
142 f->feedback[i+1] = f->feedback[i];
143 f->feedback[0] = 0xE0;
144 f->feedback[0] = (cid & 0xF) | f->feedback[0];
145 f->size++;
146 }
147 }
148 return(true);
149 }
150
151 //----------------------------------------------------------------------------------------------------------------------------------
152 // Wrap the feedback packet and add a CRC-option if specified
153 // Param f: the pointer to the feedback packet
154 // Param cid: the context-id
155 // Param largecidUsed: ==1 if largecid is used, else ==0
156 // Param with_crc: if ==1, the CRC option will be added to the feedback packet
157 // Param final_size: final size of the feedback packet will be written to this variable
158 // Return: NULL if failed, otherwise the pointer to the feedback packet
159 //----------------------------------------------------------------------------------------------------------------------------------
160 char * f_wrap_feedback(struct sd_feedback * f, int cid, int largecidUsed, int with_crc, int * final_size)
161 {
162 unsigned int crc;
163 char * feedback;
164
165 if (!f_append_cid(f, cid, largecidUsed))
166 return NULL;
167 if(with_crc) {
168 f_add_option(f, OPT_TYPE_CRC, (char*)1);
169 feedback = (char*)kmalloc(f->size, GFP_ATOMIC);
170 if (!feedback) {
171 f->size = 0;
172 return NULL;
173 }
174 memcpy(feedback, f->feedback, f->size);
175 crc = crc_calculate(CRC_TYPE_8, feedback, f->size);
176 feedback[f->size-1] = (char)(crc & 0xFF);
177 *final_size = f->size;
178 f->size = 0;
179 return(feedback);
180 }
181
182 feedback = (char*)kmalloc(f->size, GFP_ATOMIC);
183 if (!feedback) {
184 f->size = 0;
185 return NULL;
186 }
187 memcpy(feedback, f->feedback, f->size);
188 *final_size = f->size;
189 f->size = 0;
190 return(feedback);
191 }
192 //----------------------------------------------------------------------------------------------------------------------------------