comparison src/g23m-fad/ip/ip_udp.h @ 174:90eb61ecd093

src/g23m-fad: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2016 05:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
173:bf64d785238a 174:90eb61ecd093
1 /*
2 +----------------------------------------------------------------------------
3 | Project: GSM-WAP (8444)
4 | Modul: UDP
5 +----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +----------------------------------------------------------------------------
17 | Purpose: Definitions for the Protocol Stack Entity
18 | Internet Protocol
19 +----------------------------------------------------------------------------
20 */
21
22 #ifndef IP_UDP_H
23 #define IP_UDP_H
24
25 /*-------------------------------------------------------------------------*/
26
27 #include "typedefs.h"
28
29 /*---- Macros for the IP header -------------------------------------------*/
30
31 #define SET_IP_VERSION(ip_header,value) (\
32 ((UBYTE*)(ip_header))[0] = (UBYTE) \
33 ((value)<<4 & 0xF0 | ((UBYTE*)(ip_header))[0] & 0x0F) \
34 )
35
36 #define SET_IP_HEADER_LEN(ip_header,value) (\
37 ((UBYTE*)(ip_header))[0] = (UBYTE) \
38 (((UBYTE*)(ip_header))[0] & 0xF0 | (value) & 0x0F) \
39 )
40
41 #define SET_IP_TYPE_OF_SERVICE(ip_header,value) (\
42 ((UBYTE*)(ip_header))[1] = (UBYTE) (value) \
43 )
44
45 #define SET_IP_TOTAL_LEN(ip_header,value) (\
46 ((UBYTE*)(ip_header))[2] = (UBYTE) ((value)>>8), \
47 ((UBYTE*)(ip_header))[3] = (UBYTE) (value) \
48 )
49
50 #define SET_IP_IDENT(ip_header,value) (\
51 ((UBYTE*)(ip_header))[4] = (UBYTE) ((value)>>8), \
52 ((UBYTE*)(ip_header))[5] = (UBYTE) (value) \
53 )
54
55 #define SET_IP_OFF_FLAG(ip_header,value) (\
56 ((UBYTE*)(ip_header))[6] = (UBYTE) \
57 (((UBYTE*)(ip_header))[6] & 0x7F | (value)<<7 & 0x80) \
58 )
59
60 #define SET_IP_DF_FLAG(ip_header,value) (\
61 ((UBYTE*)(ip_header))[6] = (UBYTE) \
62 (((UBYTE*)(ip_header))[6] & 0xBF | (value)<<6 & 0x40) \
63 )
64
65 #define SET_IP_MF_FLAG(ip_header,value) (\
66 ((UBYTE*)(ip_header))[6] = (UBYTE) \
67 (((UBYTE*)(ip_header))[6] & 0xDF | (value)<<5 & 0x20) \
68 )
69
70 #define SET_IP_FRAG_OFFSET(ip_header,value) (\
71 ((UBYTE*)(ip_header))[6] = (UBYTE) \
72 (((UBYTE*)(ip_header))[6] & 0xE0 | (value)>>8 & 0x1F), \
73 ((UBYTE*)(ip_header))[7] = (UBYTE) (value) \
74 )
75
76 #define SET_IP_TTL(ip_header,value) (\
77 ((UBYTE*)(ip_header))[8] = (UBYTE) (value) \
78 )
79
80 #define SET_IP_PROT(ip_header,value) (\
81 ((UBYTE*)(ip_header))[9] = (UBYTE) (value) \
82 )
83
84 #define SET_IP_CHECKSUM(ip_header,value) (\
85 ((UBYTE*)(ip_header))[10] = (UBYTE) (value), \
86 ((UBYTE*)(ip_header))[11] = (UBYTE) ((value)>>8) \
87 ) /* please take note of the reversed byte order */
88
89 #define RESET_IP_CHECKSUM(ip_header) (\
90 ((UBYTE*)(ip_header))[10] = 0, \
91 ((UBYTE*)(ip_header))[11] = 0 \
92 )
93
94 #define SET_IP_SOURCE_ADDR(ip_header,value) (\
95 ((UBYTE*)(ip_header))[12] = (UBYTE) ((value)>>24), \
96 ((UBYTE*)(ip_header))[13] = (UBYTE) ((value)>>16), \
97 ((UBYTE*)(ip_header))[14] = (UBYTE) ((value)>>8), \
98 ((UBYTE*)(ip_header))[15] = (UBYTE) (value) \
99 )
100
101 #define SET_IP_DEST_ADDR(ip_header,value) (\
102 ((UBYTE*)(ip_header))[16] = (UBYTE) ((value)>>24), \
103 ((UBYTE*)(ip_header))[17] = (UBYTE) ((value)>>16), \
104 ((UBYTE*)(ip_header))[18] = (UBYTE) ((value)>>8), \
105 ((UBYTE*)(ip_header))[19] = (UBYTE) (value) \
106 )
107
108 #define GET_IP_VERSION(ip_header) (\
109 ((UBYTE*)(ip_header))[0]>>4 \
110 )
111
112 #define GET_IP_HEADER_LEN(ip_header) (\
113 ((UBYTE*)(ip_header))[0] & 0xF \
114 )
115
116 #define GET_IP_HEADER_LEN_B(ip_header) (\
117 GET_IP_HEADER_LEN (ip_header) << 2 \
118 )
119
120 #define GET_IP_TYPE_OF_SERVICE(ip_header) (\
121 ((UBYTE*)(ip_header))[1] \
122 )
123
124 #define GET_IP_TOTAL_LEN(ip_header) (\
125 ((UBYTE*)(ip_header))[2]<<8 | ((UBYTE*)(ip_header))[3] \
126 )
127
128 #define GET_IP_IDENT(ip_header) (\
129 ((UBYTE*)(ip_header))[4]<<8 | ((UBYTE*)(ip_header))[5] \
130 )
131
132 #define GET_IP_OFF_FLAG(ip_header) (\
133 ((UBYTE*)(ip_header))[6]>>7 & 0x1 \
134 )
135
136 #define GET_IP_DF_FLAG(ip_header) (\
137 ((UBYTE*)(ip_header))[6]>>6 & 0x1 \
138 )
139
140 #define GET_IP_MF_FLAG(ip_header) (\
141 ((UBYTE*)(ip_header))[6]>>5 & 0x1 \
142 )
143
144 #define GET_IP_FRAG_OFFSET(ip_header) (\
145 (((UBYTE*)(ip_header))[6] & 0x1F) << 8 | ((UBYTE*)(ip_header))[7] \
146 )
147
148 #define GET_IP_FRAG_OFFSET_B(ip_header) (\
149 GET_IP_FRAG_OFFSET (ip_header) << 3 \
150 )
151
152 #define GET_IP_TTL(ip_header) (\
153 ((UBYTE*)(ip_header))[8] \
154 )
155
156 #define GET_IP_PROT(ip_header) (\
157 ((UBYTE*)(ip_header))[9] \
158 )
159
160 #define GET_IP_CHECKSUM(ip_header) (\
161 ((UBYTE*)(ip_header))[10] | ((UBYTE*)(ip_header))[11]<<8 \
162 ) /* please take note of the reversed byte order */
163
164 #define GET_IP_SOURCE_ADDR(ip_header) (\
165 ((UBYTE*)(ip_header))[12]<<24 | \
166 ((UBYTE*)(ip_header))[13]<<16 | \
167 ((UBYTE*)(ip_header))[14]<<8 | \
168 ((UBYTE*)(ip_header))[15] \
169 )
170
171 #define GET_IP_DEST_ADDR(ip_header) (\
172 ((UBYTE*)(ip_header))[16]<<24 | \
173 ((UBYTE*)(ip_header))[17]<<16 | \
174 ((UBYTE*)(ip_header))[18]<<8 | \
175 ((UBYTE*)(ip_header))[19] \
176 )
177
178 /*---- Macros for the UDP header ------------------------------------------*/
179
180 #define SET_UDP_SRC_PORT(ip_header,value) (\
181 ((UBYTE*)(ip_header))[20] = (UBYTE) ((value)>>8), \
182 ((UBYTE*)(ip_header))[21] = (UBYTE) (value) \
183 )
184
185 #define SET_UDP_DST_PORT(ip_header,value) (\
186 ((UBYTE*)(ip_header))[22] = (UBYTE) ((value)>>8), \
187 ((UBYTE*)(ip_header))[23] = (UBYTE) (value) \
188 )
189
190 #define SET_UDP_LEN(ip_header,value) (\
191 ((UBYTE*)(ip_header))[24] = (UBYTE) ((value)>>8), \
192 ((UBYTE*)(ip_header))[25] = (UBYTE) (value) \
193 )
194
195 #define SET_UDP_CHKSUM(ip_header,offset,value) (\
196 ((UBYTE*)(ip_header))[(offset)+6] = (UBYTE) (value), \
197 ((UBYTE*)(ip_header))[(offset)+7] = (UBYTE) ((value)>>8) \
198 ) /* please take note of the reversed byte order */
199
200 #define RESET_UDP_CHKSUM(ip_header,offset) (\
201 ((UBYTE*)(ip_header))[(offset)+6] = 0, \
202 ((UBYTE*)(ip_header))[(offset)+7] = 0 \
203 )
204
205 #define GET_UDP_SRC_PORT(ip_header,offset) (\
206 ((UBYTE*)(ip_header))[offset]<<8 | ((UBYTE*)(ip_header))[(offset)+1] \
207 )
208
209 #define GET_UDP_DST_PORT(ip_header,offset) (\
210 ((UBYTE*)(ip_header))[(offset)+2]<<8 | ((UBYTE*)(ip_header))[(offset)+3] \
211 )
212
213 #define GET_UDP_LEN(ip_header,offset) (\
214 ((UBYTE*)(ip_header))[(offset)+4]<<8 | ((UBYTE*)(ip_header))[(offset)+5] \
215 )
216
217 #define GET_UDP_CHK_SUM(ip_header,offset) (\
218 ((UBYTE*)(ip_header))[(offset)+6] | ((UBYTE*)(ip_header))[(offset)+7]<<8 \
219 ) /* please take note of the reversed byte order */
220
221 /*---- Macros for the UDP pseudo header -----------------------------------*/
222
223 #define SET_UDP_PSEUDO_H_SRC_ADDR(ip_header,value) (\
224 ((UBYTE*)(ip_header))[0] = (UBYTE) ((value)>>24), \
225 ((UBYTE*)(ip_header))[1] = (UBYTE) ((value)>>16), \
226 ((UBYTE*)(ip_header))[2] = (UBYTE) ((value)>>8), \
227 ((UBYTE*)(ip_header))[3] = (UBYTE) (value) \
228 )
229
230 #define SET_UDP_PSEUDO_H_DEST_ADDR(ip_header,value) (\
231 ((UBYTE*)(ip_header))[4] = (UBYTE) ((value)>>24), \
232 ((UBYTE*)(ip_header))[5] = (UBYTE) ((value)>>16), \
233 ((UBYTE*)(ip_header))[6] = (UBYTE) ((value)>>8), \
234 ((UBYTE*)(ip_header))[7] = (UBYTE) (value) \
235 )
236
237 #define SET_UDP_PSEUDO_H_ZERO(ip_header,value) (\
238 ((UBYTE*)(ip_header))[8] = (UBYTE) (value) \
239 )
240
241 #define SET_UDP_PSEUDO_H_PROT(ip_header,value) (\
242 ((UBYTE*)(ip_header))[9] = (UBYTE) (value) \
243 )
244
245 #define SET_UDP_PSEUDO_H_LEN(ip_header,value) (\
246 ((UBYTE*)(ip_header))[10] = (UBYTE) ((value)>>8), \
247 ((UBYTE*)(ip_header))[11] = (UBYTE) (value) \
248 )
249
250 /*---- Macros for the ICMP header -----------------------------------------*/
251
252 #define SET_ICMP_TYPE(ip_header,value,offset) (\
253 ((UBYTE*)(ip_header))[offset] = (UBYTE) (value) \
254 )
255
256 #define SET_ICMP_CODE(ip_header,value,offset) (\
257 ((UBYTE*)(ip_header))[(offset)+1] = (UBYTE) (value) \
258 )
259
260 #define SET_ICMP_CHK_SUM(ip_header,value,offset) (\
261 ((UBYTE*)(ip_header))[(offset)+2] = (UBYTE) (value), \
262 ((UBYTE*)(ip_header))[(offset)+3] = (UBYTE) ((value)>>8) \
263 ) /* please take note of the reversed byte order */
264
265 #define RESET_ICMP_CHK_SUM(ip_header,offset) (\
266 ((UBYTE*)(ip_header))[(offset)+2] = 0, \
267 ((UBYTE*)(ip_header))[(offset)+3] = 0 \
268 )
269
270 #define SET_ICMP_IDENT(ip_header,value,offset) (\
271 ((UBYTE*)(ip_header))[(offset)+4] = (UBYTE) ((value)>>8), \
272 ((UBYTE*)(ip_header))[(offset)+5] = (UBYTE) (value) \
273 )
274
275 #define SET_ICMP_SEQ_NR(ip_header,value,offset) (\
276 ((UBYTE*)(ip_header))[(offset)+6] = (UBYTE) ((value)>>8), \
277 ((UBYTE*)(ip_header))[(offset)+7] = (UBYTE) (value) \
278 )
279
280 #define GET_ICMP_TYPE(ip_header,offset) (\
281 ((UBYTE*)(ip_header))[offset] \
282 )
283
284 #define GET_ICMP_CODE(ip_header,offset) (\
285 ((UBYTE*)(ip_header))[(offset)+1] \
286 )
287
288 #define GET_ICMP_CHK_SUM(ip_header,offset) (\
289 ((UBYTE*)(ip_header))[(offset)+2] | ((UBYTE*)(ip_header))[(offset)+3]<<8 \
290 ) /* please take note of the reversed byte order */
291
292 #define GET_ICMP_IDENT(ip_header,offset) (\
293 ((UBYTE*)(ip_header))[(offset)+4]<<8 | ((UBYTE*)(ip_header))[(offset)+5] \
294 )
295
296 #define GET_ICMP_SEQ_NR(ip_header,offset) (\
297 ((UBYTE*)(ip_header))[(offset)+6]<<8 | ((UBYTE*)(ip_header))[(offset)+7] \
298 )
299
300 /*---- Constants ----------------------------------------------------------*/
301
302 /* Types of primitives */
303
304 #define P_DTI_READY_IND 0
305 #define P_DTI_DATA_REQ 1
306 #define P_DTI_GETDATA_REQ 2
307 #define P_DTI_DATA_IND 3
308 #define P_IP_ADDR_CNF 4
309 #define P_UDP_ERROR_RES 5
310 #define P_UDP_GETDATA_REQ 6
311 #define P_UDP_BIND_REQ 7
312 #define P_UDP_CONFIG_REQ 8
313 #define P_UDPA_CONFIG_REQ 9
314 #define P_DTI_DATA_TEST_IND 10
315 #define P_DTI_DATA_TEST_REQ 11
316 #define P_UDP_CLOSEPORT_REQ 12
317 #define P_TIMER_REASSEMBLY 13
318 #define P_UDPA_ACTIVATE_REQ 14
319
320 /* For building packets */
321
322 #define B_NORMAL_PACKET 1 /* Build normal packet */
323 #define B_SEGMENT 2 /* Build segment packet */
324 #define B_ICMP_ECHO 3 /* Build ICMP echo packet */
325 #define B_ICMP_ECHO_REPLY 4 /* Build ICMP echo reply packet */
326 #define B_ICMP_TTL_0 5 /* Build TTL packet */
327 #define B_ICMP_NO_FORWARD 6 /* Build ICMP when no forward */
328 #define B_IP_FORWARD 7 /* Build packet forward */
329 #define B_ICMP_TIME_EX 8 /* Time exceeded by segmenting */
330 #define B_ICMP_PACKET 9 /* ICMP packet */
331 #define B_NO_DEST_PORT 10 /* No destination port */
332 #define B_ICMP_REASSEMBLE_TIMEOUT 11 /* Build ICMP when timeout reassembly */
333
334 #define BUILD_NO_PACKET 0 /* No packet shall be built */
335
336 /* For IP packet header */
337
338 #define IP_VERSION 4 /* IP version number */
339 #define ICMP_PROT 1 /* ICMP protocol */
340 #define UDP_PROT 17 /* UDP protocol */
341 #define DL_SEGMENT 1 /* DL segment */
342 #define NORMAL_SERVICE 0 /* No services */
343 #define NO_SEGMENT_ID 0 /* No segment ID */
344 #define START_SEGMENT_ID 0 /* Offset for identity segmenting */
345 #define IDENTITY_0 0 /* Identity set to zero */
346 #define FLAG_NOT_SET 0 /* Flag zero */
347 #define FLAG_SET 1 /* Flag one */
348 #define NO_OFFSET_FRAG 0 /* No offset for fragmenting */
349 #define STANDARD_TTL 64 /* Standard TTL by initialisation */
350 #define LEN_IP_HEADER_B 20 /* Minimum length of IP header in bytes */
351
352 /* ICMP messages */
353
354 #define ICMP_ECHO_REPLY 0 /* ICMP ping reply */
355 #define LEN_ICMP_ECHO_REPLY 64 /* Datagram ICMP echo reply in bytes */
356 #define LEN_ICMP_TIMEOUT 128 /* Datagram ICMP timeout in bytes */
357
358 #define ICMP_CODE_ECHO_REPLY 0 /* ICMP ping reply */
359 #define ICMP_CODE_NO_HOST 1 /* No destination host*/
360 #define ICMP_CODE_NO_FORWARD 0 /* No forward route */
361 #define ICMP_CODE_NO_PORT 3 /* No destination port */
362 #define ICMP_CODE_FRAGM_TIME_EXC 1 /* Reassembly time exceeded */
363
364 #define ICMP_TYP_DEST_URECHBL 3 /* Cannot reach the destination */
365 #define ICMP_TYP_ECHO_REPLY 0 /* Ping request type */
366 #define ICMP_TYP_ECHO 8 /* Ping */
367 #define ICMP_TYP_TIME_EXCEDED 11 /* Timeout or TTL is 0 */
368
369 /* For UDP packet header */
370
371 #define LEN_UDP_HEADER_B 8 /* Length of UDP header in bytes */
372
373 /* For init */
374
375 #define NO_TUI 0
376 #define NO_CH_ID 0
377 #define NO_ADDR 0
378 #define NO_PORT 0
379 #define NO_PROT_ID 0
380 #define NO_MTU 0
381 #define INIT_NETMASK 0
382 #define NO_ID_REASSBL 0
383 #define NO_PROT_REASSBL 0
384 #define NO_TIMER 0
385
386 /*---- Prototypes ---------------------------------------------------------*/
387
388 void table_state_tui (
389 void * primitive,
390 UBYTE typ,
391 UBYTE * akt_layer
392 );
393
394 void free_dti_data_req (T_DTI2_DATA_REQ ** dti_data_req);
395
396 void free_dti_data_ind (T_DTI2_DATA_IND ** dti_data_ind);
397
398 /* The following functions are actually defined in the UDP module.
399 * Due to unfortunate decisions in the past they must still be
400 * declared here redundantly, but should really be declared in a
401 * common include file. No time to fix this now, though.
402 * [ni 2002-06-18]
403 */
404
405 /** Computes the internet checksum [RFC 1071] over a data block.
406 *
407 * @param block pointer to data block
408 * @param len length of the block in octets
409 * @return the checksum
410 */
411 USHORT inet_checksum (UBYTE * block, USHORT len);
412
413 /** Computes the internet checksum over a DTI descriptor list. There
414 * may be a value from a previous partial calculation that is added to
415 * the sum as a start value. The function relies on the data length
416 * being at least start_offset.
417 *
418 * @param dlist descriptor list containing the data
419 * @param start_offset beginning position of interesting data
420 * @param start_value value from previous partial checksum calculation
421 * @return the checksum value
422 */
423 USHORT desc_checksum (
424 T_desc_list2 * dlist,
425 USHORT start_offset,
426 ULONG start_value
427 );
428
429 void del_rest_descs (T_desc_list2 * desc_list, T_desc2 * desc);
430
431 void put_desc_last_pos (T_desc_list2 * desc_list, T_desc2 * desc);
432
433 void put_desc_first_pos (T_desc_list2 * desc_list, T_desc2 * desc_new);
434
435 void build_icmp_with_payload (
436 T_DTI2_DATA_REQ * data_req,
437 USHORT identity,
438 UBYTE ttl,
439 ULONG src_addr,
440 UBYTE icmp_type,
441 UBYTE icmp_code
442 );
443
444 void set_desc_len (
445 T_desc_list2 * desc_list,
446 T_desc2 * desc,
447 USHORT len_desc
448 );
449
450 void copy_from_descs_to_desc (
451 T_desc2 ** desc,
452 T_desc2 * desc_new,
453 USHORT copy_len,
454 USHORT offset_desc,
455 USHORT offset_desc_new,
456 USHORT * pos_copy,
457 USHORT * total_len_copy
458 );
459
460 void del_descs (T_desc2 * p_desc);
461
462 void build_icmp_packet (
463 USHORT header_len_b,
464 UBYTE typ,
465 UBYTE code,
466 UBYTE ttl,
467 UBYTE * ip_header,
468 USHORT identity,
469 ULONG dest_addr,
470 ULONG src_addr,
471 T_desc_list2 * desc_list
472 );
473
474 void build_ip_header (
475 UBYTE * ip_header_new,
476 USHORT identity,
477 UBYTE header_len,
478 UBYTE type_of_service,
479 UBYTE ttl,
480 ULONG src_addr,
481 ULONG dest_addr,
482 USHORT total_len,
483 USHORT fragm_offset,
484 UBYTE df_flag,
485 UBYTE mf_flag,
486 UBYTE prot
487 );
488
489 void truncate_descs (T_desc_list2 * p_desc_list, USHORT new_length);
490
491 void free_primitive_data_ind (T_DTI2_DATA_IND ** dti_data_ind);
492
493 void free_primitive_data_req (T_DTI2_DATA_REQ ** dti_data_req);
494
495 ULONG partial_checksum (UBYTE * block, USHORT len);
496
497 /*-------------------------------------------------------------------------*/
498
499 #endif /* IP_UDP_H */
500
501 /*-------------------------------------------------------------------------*/
502