1 /** \file lct_hdr.c \brief LCT header
2 *
3 * $Author: peltotal $ $Date: 2007/02/28 08:58:00 $ $Revision: 1.23 $
4 *
5 * MAD-ALCLIB: Implementation of ALC/LCT protocols, Compact No-Code FEC,
6 * Simple XOR FEC, Reed-Solomon FEC, and RLC Congestion Control protocol.
7 * Copyright (c) 2003-2007 TUT - Tampere University of Technology
8 * main authors/contacts: jani.peltotalo@tut.fi and sami.peltotalo@tut.fi
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * In addition, as a special exception, TUT - Tampere University of Technology
25 * gives permission to link the code of this program with the OpenSSL library (or
26 * with modified versions of OpenSSL that use the same license as OpenSSL), and
27 * distribute linked combinations including the two. You must obey the GNU
28 * General Public License in all respects for all of the code used other than
29 * OpenSSL. If you modify this file, you may extend this exception to your version
30 * of the file, but you are not obligated to do so. If you do not wish to do so,
31 * delete this exception statement from your version.
32 */
33
34 #ifdef _MSC_VER
35 #include <winsock2.h>
36 #else
37 #include <arpa/inet.h>
38 #endif
39
40 #include "lct_hdr.h"
41
add_fdt_lct_he(def_lct_hdr_t * def_lct_hdr,int hdrlen,unsigned int fdt_instance_id)42 int add_fdt_lct_he(def_lct_hdr_t *def_lct_hdr, int hdrlen, unsigned int fdt_instance_id) {
43
44 unsigned int word;
45 int len = 0;
46
47 word = ((EXT_FDT << 24) | ((FLUTE_VERSION & 0xF) << 20) | (fdt_instance_id & 0x000FFFFF));
48 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen) = htonl(word);
49 len += 4;
50
51 return len;
52
53 }
54
add_cenc_lct_he(def_lct_hdr_t * def_lct_hdr,int hdrlen,unsigned char content_enc_algo)55 int add_cenc_lct_he(def_lct_hdr_t *def_lct_hdr, int hdrlen, unsigned char content_enc_algo) {
56
57 unsigned int word;
58 int len = 0;
59
60 word = ((EXT_CENC << 24) | (content_enc_algo << 16) | (0 & 0x0000FFFF));
61 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen) = htonl(word);
62 len += 4;
63
64 return len;
65 }
66
add_fti_0_2_128_130_lct_he(def_lct_hdr_t * def_lct_hdr,int hdrlen,unsigned long long transferlen,unsigned short fec_inst_id,unsigned short eslen,unsigned int max_sblen)67 int add_fti_0_2_128_130_lct_he(def_lct_hdr_t *def_lct_hdr, int hdrlen,
68 unsigned long long transferlen,
69 unsigned short fec_inst_id, unsigned short eslen, unsigned int max_sblen) {
70
71 unsigned int word;
72 unsigned short tmp;
73 int len = 0;
74
75 tmp = ((unsigned int)(transferlen >> 32) & 0x0000FFFF);
76 word = ((EXT_FTI << 24) | (4 << 16) | tmp);
77 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen) = htonl(word);
78 len += 4;
79
80 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen + len) = htonl((unsigned int)transferlen);
81 len += 4;
82
83 word = ((fec_inst_id << 16) | eslen);
84 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen + len) = htonl(word);
85 len += 4;
86
87 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen + len) = htonl(max_sblen);
88 len += 4;
89
90 return len;
91 }
92
add_fti_3_lct_he(def_lct_hdr_t * def_lct_hdr,int hdrlen,unsigned long long transferlen,unsigned char m,unsigned char G,unsigned short eslen,unsigned short max_sblen,unsigned short mxnbofes)93 int add_fti_3_lct_he(def_lct_hdr_t *def_lct_hdr, int hdrlen,
94 unsigned long long transferlen,
95 unsigned char m, unsigned char G, unsigned short eslen,
96 unsigned short max_sblen, unsigned short mxnbofes) {
97
98 unsigned int word;
99 unsigned short tmp;
100 int len = 0;
101
102 tmp = ((unsigned int)(transferlen >> 32) & 0x0000FFFF);
103 word = ((EXT_FTI << 24) | (4 << 16) | tmp);
104 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen) = htonl(word);
105 len += 4;
106
107 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen + len) = htonl((unsigned int)transferlen);
108 len += 4;
109
110 word = ((m << 24) | (G << 16) | eslen);
111 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen + len) = htonl(word);
112 len += 4;
113
114 word = ((max_sblen << 16) | mxnbofes);
115 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen + len) = htonl(word);
116 len += 4;
117
118 return len;
119 }
120
add_fti_129_lct_he(def_lct_hdr_t * def_lct_hdr,int hdrlen,unsigned long long transferlen,unsigned short fec_inst_id,unsigned short eslen,unsigned short max_sblen,unsigned short mxnbofes)121 int add_fti_129_lct_he(def_lct_hdr_t *def_lct_hdr, int hdrlen,
122 unsigned long long transferlen,
123 unsigned short fec_inst_id, unsigned short eslen,
124 unsigned short max_sblen, unsigned short mxnbofes) {
125
126 unsigned int word;
127 unsigned short tmp;
128 int len = 0;
129
130 tmp = ((unsigned int)(transferlen >> 32) & 0x0000FFFF);
131 word = ((EXT_FTI << 24) | (4 << 16) | tmp);
132 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen) = htonl(word);
133 len += 4;
134
135 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen + len) = htonl((unsigned int)transferlen);
136 len += 4;
137
138 word = ((fec_inst_id << 16) | eslen);
139 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen + len) = htonl(word);
140 len += 4;
141
142 word = ((max_sblen << 16) | mxnbofes);
143 *(unsigned int*)((unsigned char*)def_lct_hdr + hdrlen + len) = htonl(word);
144 len += 4;
145
146 return len;
147 }
148
add_nop_lct_he(void)149 int add_nop_lct_he(void) {
150 int len = 0;
151 /* TODO */
152 return len;
153 }
154
add_auth_lct_he(void)155 int add_auth_lct_he(void) {
156 int len = 0;
157 /* TODO */
158 return len;
159 }
160
add_time_lct_he(void)161 int add_time_lct_he(void) {
162 int len = 0;
163 /* TODO */
164 return len;
165 }
166