rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame^] | 1 | /****************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2007 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *******************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * Filename: |
| 38 | * -------------------------------------------------------- |
| 39 | * rfc2507_lib_comon.h |
| 40 | * |
| 41 | * Project: |
| 42 | * -------------------------------------------------------- |
| 43 | * MONZA |
| 44 | * |
| 45 | * Description: |
| 46 | * -------------------------------------------------------- |
| 47 | * RFC2507 library common enums, macros and function declarations |
| 48 | * |
| 49 | * Author: |
| 50 | * -------------------------------------------------------- |
| 51 | * ------- |
| 52 | * |
| 53 | * -------------------------------------------------------- |
| 54 | * $Log$ |
| 55 | * |
| 56 | * 12 12 2014 tc.chang |
| 57 | * [MOLY00087434] [Universal Bin] Check in. |
| 58 | * RFC2507 |
| 59 | * |
| 60 | * 07 25 2012 andrew.wu |
| 61 | * [MOLY00001136] [RFC2507]Change KAL API usage |
| 62 | * change kal_get_time() to kal_get_systicks() |
| 63 | * |
| 64 | * 03 15 2012 andrew.wu |
| 65 | * removed! |
| 66 | * Modification for GCC migration |
| 67 | * |
| 68 | * 08 08 2011 tc.chang |
| 69 | * removed! |
| 70 | * . |
| 71 | * |
| 72 | * 08 07 2011 tc.chang |
| 73 | * removed! |
| 74 | * . |
| 75 | * |
| 76 | * 08 07 2011 tc.chang |
| 77 | * removed! |
| 78 | * . |
| 79 | * |
| 80 | * 08 03 2011 tc.chang |
| 81 | * removed! |
| 82 | * . |
| 83 | * |
| 84 | * 08 03 2011 tc.chang |
| 85 | * removed! |
| 86 | * . |
| 87 | * |
| 88 | * 07 26 2011 tc.chang |
| 89 | * removed! |
| 90 | * . |
| 91 | * |
| 92 | * 06 12 2011 tc.chang |
| 93 | * removed! |
| 94 | * . |
| 95 | * |
| 96 | * 06 03 2011 tc.chang |
| 97 | * removed! |
| 98 | * Send FULL_HEADER if the length of compressed header is larger than the length of the original header. |
| 99 | * . |
| 100 | * |
| 101 | * 05 25 2011 tc.chang |
| 102 | * removed! |
| 103 | * . |
| 104 | * |
| 105 | * 12 14 2010 max.yin |
| 106 | * removed! |
| 107 | * . |
| 108 | * |
| 109 | * 10 18 2010 max.yin |
| 110 | * removed! |
| 111 | * . |
| 112 | * |
| 113 | * removed! |
| 114 | * removed! |
| 115 | * |
| 116 | * |
| 117 | * removed! |
| 118 | * removed! |
| 119 | * |
| 120 | * |
| 121 | * removed! |
| 122 | * removed! |
| 123 | * |
| 124 | * |
| 125 | * removed! |
| 126 | * removed! |
| 127 | * |
| 128 | * |
| 129 | * removed! |
| 130 | * removed! |
| 131 | * |
| 132 | * |
| 133 | * removed! |
| 134 | * removed! |
| 135 | * |
| 136 | * |
| 137 | * removed! |
| 138 | * removed! |
| 139 | * |
| 140 | * |
| 141 | * removed! |
| 142 | * removed! |
| 143 | * |
| 144 | * |
| 145 | * removed! |
| 146 | * removed! |
| 147 | * |
| 148 | * |
| 149 | ******************************************************************************/ |
| 150 | |
| 151 | #ifndef _RFC2507_LIB_COMMON_H |
| 152 | #define _RFC2507_LIB_COMMON_H |
| 153 | |
| 154 | #include "kal_public_api.h" |
| 155 | #include "kal_public_defs.h" |
| 156 | #include "kal_general_types.h" |
| 157 | #include "rfc2507_lib.h" |
| 158 | |
| 159 | /* Macro */ |
| 160 | #if !defined(__MTK_TARGET__) && defined(__RFC2507_CHECK_MEM_LEAK__) |
| 161 | |
| 162 | /* For MoDOS UT environment. */ |
| 163 | #define rfc2507_alloc_sys_mem(size) rfc2507_get_ctrl_buffer(size, __FILE__, __LINE__) |
| 164 | #define rfc2507_dealloc_sys_mem(ptr) rfc2507_free_ctrl_buffer(ptr, __FILE__, __LINE__) |
| 165 | extern void* rfc2507_get_ctrl_buffer(kal_uint16 size, kal_char * file_name, kal_uint32 line); |
| 166 | extern void rfc2507_free_ctrl_buffer(void* buf, kal_char * file_name, kal_uint32 line); |
| 167 | #else /* __RFC2507_CHECK_MEM_LEAK__ */ |
| 168 | |
| 169 | /* Target load */ |
| 170 | #define rfc2507_alloc_sys_mem(size) get_ctrl_buffer(size) |
| 171 | #define rfc2507_dealloc_sys_mem(ptr) free_ctrl_buffer(ptr) |
| 172 | #endif /* __RFC2507_CHECK_MEM_LEAK__ */ |
| 173 | |
| 174 | #define BITS_PER_BYTE 8 |
| 175 | |
| 176 | /* |
| 177 | * Macros for determining RFC2507 PID values from a supplied base |
| 178 | * (RFC2507_PARAMETERS FirstPid). |
| 179 | */ |
| 180 | #define RFC2507_FULL_HEADER_PID(x) (x + 0) |
| 181 | #define RFC2507_COMPRESSED_TCP_PID(x) (x + 1) |
| 182 | #define RFC2507_COMPRESSED_TCP_NODELTA_PID(x) (x + 2) |
| 183 | #define RFC2507_COMPRESSED_NON_TCP_PID(x) (x + 3) |
| 184 | #define RFC2507_CONTEXT_STATE_PID(x) (x + 4) |
| 185 | #define RFC2507_REGULAR_HEADER_PID (0xFE) |
| 186 | |
| 187 | /* MUST skip 0 for TCP packet SN when compressing TCP header. |
| 188 | * Also used for differentiation in Rfc2507ProcessStoredPacket(). |
| 189 | */ |
| 190 | #define INVALID_TCP_PSN 0 |
| 191 | |
| 192 | /* |
| 193 | * A constant defining the maximum number of IP sub-header length fields that |
| 194 | * may be used for a FULL_HEADER packet |
| 195 | */ |
| 196 | #define FULL_HEADER_MAX_LENGTH_FIELDS 2 |
| 197 | |
| 198 | /* |
| 199 | * 2009.4.14 Robert add |
| 200 | * Max. subheader number in SUB_HEADER_CHAIN_LIST. |
| 201 | */ |
| 202 | #define RFC2507_MAX_SUB_HEADER_CHAIN_NUM 10 |
| 203 | |
| 204 | /* |
| 205 | * Definitions of special values for TLV-encoding options |
| 206 | */ |
| 207 | #define TLV_OPTION_TYPE_PAD1 0 |
| 208 | #define TLV_OPTION_TYPE_PADN 1 |
| 209 | |
| 210 | /* |
| 211 | * Contants for determining the type of an IP packet |
| 212 | */ |
| 213 | #define IP_VERSION_NUMBER_MASK 0xF0 |
| 214 | #define IP_V4_VERSION_NUMBER 0x40 |
| 215 | #define IP_V6_VERSION_NUMBER 0x60 |
| 216 | |
| 217 | /* |
| 218 | * Constants and macro for determining the length of IP_V4_SUB_HEADER |
| 219 | */ |
| 220 | #define IP_V4_IHL_MASK 0x0F |
| 221 | #define IP_V4_MINIMUM_IHL 5 |
| 222 | #define IP_V4_LEN_OFFSET 0 |
| 223 | #define BYTES_PER_IP_V4_LEN(x) (((x) & IP_V4_IHL_MASK) * 4) |
| 224 | #define IP_V4_HAS_OPTIONS(x) (((x) & IP_V4_IHL_MASK) != IP_V4_MINIMUM_IHL) |
| 225 | |
| 226 | /* |
| 227 | * Constants and macros for determining that the IPv4 packet is a fragment |
| 228 | */ |
| 229 | #define IP_V4_FLAGS_OFFSET 6 |
| 230 | #define IP_V4_FLAGS_MASK 0xE0 |
| 231 | #define IP_V4_FLAGS_SHIFT 5 |
| 232 | #define IP_V4_FLAGS(x) (((x) & IP_V4_FLAGS_MASK) >> IP_V4_FLAGS_SHIFT) |
| 233 | #define IP_V4_MF_FLAG 0x01 |
| 234 | #define IP_V4_MF_FLAG_IS_SET(x) (0 != (IP_V4_FLAGS(x) & IP_V4_MF_FLAG)) |
| 235 | #define IP_V4_FRAGMENT_FIELD 6 |
| 236 | #define IP_V4_FRAGMENT_MASK 0x1FFF |
| 237 | |
| 238 | /* |
| 239 | * Macro for determining the position of the IP_V4_TYPE_OF_SERVICE field in a |
| 240 | * IP_V4_SUB_HEADER |
| 241 | */ |
| 242 | #define IP_V4_TYPE_OF_SERVICE_OFFSET 1 |
| 243 | #define IP_V4_TYPE_OF_SERVICE_DEF_MASK 0xFC |
| 244 | |
| 245 | /* |
| 246 | * Macro for determining positions of IPv4 fields |
| 247 | */ |
| 248 | #define IP_V4_TOTAL_LENGTH_OFFSET 2 |
| 249 | #define IP_V4_IDENTIFICATION_OFFSET 4 |
| 250 | #define IP_V4_IDENTIFICATION_LENGTH 2 |
| 251 | #define IP_V4_PROTOCOL_OFFSET 9 |
| 252 | #define IP_V4_CHECKSUM_OFFSET 10 |
| 253 | |
| 254 | #define IP_V4_SUB_HEADER_LEN 20 |
| 255 | #define IP_V6_SUB_HEADER_LEN 40 |
| 256 | |
| 257 | #define IP_V6_PAYLOAD_LENGTH_OFFSET 4 |
| 258 | #define IP_V6_PROTOCOL_OFFSET 6 |
| 259 | #define IP_V6_ADDRESS_LENGTH 16 |
| 260 | |
| 261 | /* |
| 262 | * Constant and macro to determine the length of HOP_BY_HOP_OPTIONS_SUB_HEADER, |
| 263 | * DESTINATION_OPTIONS_SUB_HEADER and ROUTING_SUB_HEADER |
| 264 | */ |
| 265 | #define HDR_EXT_LEN_OFFSET 1 |
| 266 | #define BYTES_PER_HDR_EXT_LEN(x) (((x) + 1) * 8) |
| 267 | |
| 268 | #define TLV_OPTION_DATA_OFFSET 2 |
| 269 | |
| 270 | /* |
| 271 | * Constant for determining the type of the sub-header after |
| 272 | * HOP_BY_HOP_OPTIONS_SUB_HEADER, DESTINATION_OPTIONS_SUB_HEADER, |
| 273 | * ROUTING_SUB_HEADER, FRAGMENT_SUB_HEADER and AUTHENTICATION_SUB_HEADER |
| 274 | */ |
| 275 | #define NEXT_HEADER_PROTOCOL_OFFSET 0 |
| 276 | |
| 277 | /* |
| 278 | * Constants defining the positions of the "type" and "segments left" fields of |
| 279 | * the ROUTING_SUB_HEADER |
| 280 | */ |
| 281 | #define ROUTING_TYPE_OFFSET 2 |
| 282 | #define ROUTING_SEGMENTS_LEFT_OFFSET 3 |
| 283 | |
| 284 | #define FRAGMENT_SUB_HEADER_LEN 8 |
| 285 | |
| 286 | /* |
| 287 | * Macros to determine the length of AUTHENTICATION_SUB_HEADER |
| 288 | */ |
| 289 | #define AUTHENTICATION_LEN_OFFSET 1 |
| 290 | #define BYTES_PER_AUTHENTICATION_LEN(x) (((x) + 2) * 4) |
| 291 | #define AUTHENTICATION_DATA_OFFSET 8 |
| 292 | |
| 293 | /* |
| 294 | * Macros to determine the length of MINIMAL_ENCAPSULATION_SUB_HEADER |
| 295 | */ |
| 296 | #define MINIMAL_ENCAPSULATION_LEN_OFFSET 1 |
| 297 | #define BYTES_PER_MINIMAL_ENCAPSULATION_LEN(x) (((x) & 0x80) ? 12 : 8) |
| 298 | #define MINIMAL_ENCAPSULATION_CHECKSUM_OFFSET 2 |
| 299 | |
| 300 | #define ESP_SUB_HEADER_LEN 4 |
| 301 | |
| 302 | #define TCP_LEN_OFFSET 12 |
| 303 | #define BYTES_PER_TCP_LEN(x) (((x) >> 4) * 4) |
| 304 | #define MIN_TCP_SUB_HEADER_LEN 20 |
| 305 | |
| 306 | #define UDP_LENGTH_OFFSET 4 |
| 307 | #define UDP_CHECKSUM_OFFSET 6 |
| 308 | #define UDP_CHECKSUM_LENGTH 2 |
| 309 | #define UDP_SUB_HEADER_LEN 8 |
| 310 | |
| 311 | #define PROTOCOL_NUMBER_TCP 6 |
| 312 | |
| 313 | /* |
| 314 | * 2009.4.14 Robert add |
| 315 | * Subheader chain operation macro. |
| 316 | */ |
| 317 | #define GET_SUB_HDR_ITEM(_pList_, _Index_) \ |
| 318 | ( &((_pList_)->HdrItem[_Index_]) ) |
| 319 | |
| 320 | #define GET_FIRST_HDR(_pList_) Rfc2507_GetFirstSubHdrItem((SUB_HEADER_CHAIN_LIST *)_pList_) |
| 321 | #define GET_LAST_HDR(_pList_) Rfc2507_GetLastSubHdrItem((SUB_HEADER_CHAIN_LIST *)_pList_) |
| 322 | #define GET_NEXT_HDR(_pList_) Rfc2507_GetNextSubHdrItem((SUB_HEADER_CHAIN_LIST *)_pList_) |
| 323 | #define GET_PREV_HDR(_pList_) Rfc2507_GetPrevSubHdrItem((SUB_HEADER_CHAIN_LIST *)_pList_) |
| 324 | |
| 325 | /* Remember to modify the mapping table */ |
| 326 | typedef enum |
| 327 | { |
| 328 | RFC2507_INT_DECOMPRESS_SUCCESS, |
| 329 | RFC2507_INT_DECOMPRESS_SUCCESS_MORE_TO_GO, |
| 330 | RFC2507_TCP_DECOMPRESS_SUCCESS_RCV_CONTEXT_STATE, |
| 331 | RFC2507_TCP_DECOMPRESS_FAIL_CANNOT_CREATE_CID, |
| 332 | RFC2507_TCP_DECOMPRESS_FAIL_NO_PACKET_IN_WINDOW, |
| 333 | RFC2507_TCP_DECOMPRESS_FAIL_CID_NO_EXIST, |
| 334 | RFC2507_TCP_DECOMPRESS_FAIL_CAN_BE_FREED_SEND_CONTEXT_STATE, |
| 335 | RFC2507_TCP_DECOMPRESS_FAIL_CAN_BE_FREED, |
| 336 | RFC2507_NON_TCP_DECOMPRESS_FAIL_CAN_BE_FREED, |
| 337 | RFC2507_NON_TCP_DECOMPRESS_FAIL_STORED, |
| 338 | RFC2507_DECOMPRESS_UNKNOWN_PID_TYPE, |
| 339 | NO_OF_RFC2507_INTERNAL_DECOMPRESS_RESULT, |
| 340 | INVALID_RFC2507_INTERNAL_DECOMPRESS_RESULT |
| 341 | } RFC2507_INTERNAL_DECOMPRESS_RESULT_ENUM; |
| 342 | |
| 343 | /* |
| 344 | * SUB_HEADER_TYPE: Enumeration listing the types of sub-header supported |
| 345 | * and the number of sub-headers supported. |
| 346 | */ |
| 347 | typedef enum |
| 348 | { |
| 349 | IP_V4_SUB_HEADER, |
| 350 | IP_V6_SUB_HEADER, |
| 351 | HOP_BY_HOP_OPTIONS_SUB_HEADER, |
| 352 | DESTINATION_OPTIONS_SUB_HEADER, |
| 353 | ROUTING_SUB_HEADER, |
| 354 | FRAGMENT_SUB_HEADER, |
| 355 | AUTHENTICATION_SUB_HEADER, |
| 356 | ESP_SUB_HEADER, /* Encapsulating Security Payload */ |
| 357 | MINIMAL_ENCAPSULATION_SUB_HEADER, |
| 358 | TCP_SUB_HEADER, |
| 359 | UDP_SUB_HEADER, |
| 360 | NO_NEXT_SUB_HEADER, |
| 361 | NO_SUB_HEADERS |
| 362 | } SUB_HEADER_TYPE; |
| 363 | |
| 364 | /* |
| 365 | * SUB_HEADER_LIST: Structure used for lists of sub-headers in CID information |
| 366 | */ |
| 367 | typedef struct |
| 368 | { |
| 369 | kal_uint16 Offset; /* |
| 370 | * Offset of the start of the sub-header |
| 371 | * from the start of the SDU (in bytes) |
| 372 | */ |
| 373 | SUB_HEADER_TYPE Type; /* |
| 374 | * The type of the sub-header at this offset |
| 375 | */ |
| 376 | } SUB_HEADER_LIST; |
| 377 | |
| 378 | /* |
| 379 | * FIELD_COMPRESSION_TYPE: Enumeration listing the field types for compression |
| 380 | * and decompression of sub-headers |
| 381 | */ |
| 382 | typedef enum |
| 383 | { |
| 384 | NOCHANGE_FIELD, |
| 385 | DELTA_FIELD, |
| 386 | RANDOM_FIELD, |
| 387 | INFERRED_FIELD |
| 388 | } FIELD_COMPRESSION_TYPE; |
| 389 | |
| 390 | /* |
| 391 | * FIELD_DEFINING_TYPE: Enumeration listing the field types for defining packet |
| 392 | * streams for compression of sub-headers |
| 393 | */ |
| 394 | typedef enum |
| 395 | { |
| 396 | NOT_DEF_FIELD, |
| 397 | DEF_FIELD, |
| 398 | ROUTING_TYPE_0_DEF_FIELD |
| 399 | } FIELD_DEFINING_TYPE; |
| 400 | |
| 401 | /* |
| 402 | * FIELD_INFO: Structure to hold information on the fields in a sub-header |
| 403 | */ |
| 404 | typedef struct |
| 405 | { |
| 406 | kal_uint16 Start; /* |
| 407 | * The position of the start of the |
| 408 | * field in terms of bits from the |
| 409 | * start of the sub-header |
| 410 | */ |
| 411 | kal_uint8 Length; /* |
| 412 | * The length of the field in bits |
| 413 | */ |
| 414 | FIELD_COMPRESSION_TYPE Type; /* |
| 415 | * The type of the field for |
| 416 | * compression purposes |
| 417 | */ |
| 418 | FIELD_DEFINING_TYPE Defining; /* |
| 419 | * Indicates how this field is used in |
| 420 | * defining the packet stream (CID) |
| 421 | */ |
| 422 | } FIELD_INFO; |
| 423 | |
| 424 | /* |
| 425 | * SUB_HEADER_INFO: Structure to hold information on the sub-headers |
| 426 | */ |
| 427 | typedef struct |
| 428 | { |
| 429 | SUB_HEADER_TYPE Type; /* |
| 430 | * A unique identifier indicating the |
| 431 | * type of the sub-header |
| 432 | */ |
| 433 | kal_uint8 Protocol; /* |
| 434 | * The value of the field in the |
| 435 | * previous sub-header that identifies |
| 436 | * this type sub-header follows. Not |
| 437 | * necessarily unique. |
| 438 | */ |
| 439 | kal_uint8 NoFields; /* |
| 440 | * The number of fields in the |
| 441 | * sub-header, indicating the number |
| 442 | * of elements in the FieldInfo array |
| 443 | * that follows |
| 444 | */ |
| 445 | const FIELD_INFO *FieldInfo; /* |
| 446 | * An array of structures, with each |
| 447 | * element in the array describing a |
| 448 | * field within the sub-header |
| 449 | */ |
| 450 | } SUB_HEADER_INFO; |
| 451 | |
| 452 | |
| 453 | /* |
| 454 | * IP_V4_FIELDS: Enumeration listing the fields in an IPv4 sub-header, acting as |
| 455 | * an index to the Rfc2507SubHeaderInfo[IP_V4_SUB_HEADER].FieldInfo array of FIELD_INFO, with the last item in |
| 456 | * this enumeration defining the number of elements in that array |
| 457 | */ |
| 458 | typedef enum |
| 459 | { |
| 460 | IP_V4_VERSION, |
| 461 | IP_V4_IHL, |
| 462 | IP_V4_TYPE_OF_SERVICE, |
| 463 | IP_V4_TOTAL_LENGTH, |
| 464 | IP_V4_IDENTIFICATION, |
| 465 | IP_V4_FLAG, |
| 466 | IP_V4_FRAGMENT_OFFSET, |
| 467 | IP_V4_TIME_TO_LIVE, |
| 468 | IP_V4_PROTOCOL, |
| 469 | IP_V4_HEADER_CHECKSUM, |
| 470 | IP_V4_SOURCE_ADDRESS, |
| 471 | IP_V4_DESTINATION_ADDRESS, |
| 472 | NO_IP_V4_FIELDS |
| 473 | } IP_V4_FIELDS; |
| 474 | |
| 475 | /* |
| 476 | * IP_V6_FIELDS: Enumeration listing the fields in an IPv6 sub-header, acting as |
| 477 | * an index to the Rfc2507SubHeaderInfo[IP_V6_SUB_HEADER].FieldInfo array of FIELD_INFO, with the last item in |
| 478 | * this enumeration defining the number of elements in that array |
| 479 | */ |
| 480 | typedef enum |
| 481 | { |
| 482 | IP_V6_VERSION, |
| 483 | IP_V6_TRAFFIC_CLASS, |
| 484 | IP_V6_FLOW_LABEL, |
| 485 | IP_V6_PAYLOAD_LENGTH, |
| 486 | IP_V6_NEXT_HEADER, |
| 487 | IP_V6_HOP_LIMIT, |
| 488 | IP_V6_SOURCE_ADDRESS, |
| 489 | IP_V6_DESTINATION_ADDRESS, |
| 490 | NO_IP_V6_FIELDS |
| 491 | } IP_V6_FIELDS; |
| 492 | |
| 493 | /* |
| 494 | * HOP_BY_HOP_OPTIONS_FIELDS: Enumeration listing the fields in a hop-by-hop |
| 495 | * options sub-header, acting as an index to the Rfc2507SubHeaderInfo[HOP_BY_HOP_OPTIONS_SUB_HEADER].FieldInfo |
| 496 | * array of FIELD_INFO, with the last item in this enumeration defining the |
| 497 | * number of elements in that array |
| 498 | */ |
| 499 | typedef enum |
| 500 | { |
| 501 | HOP_BY_HOP_OPTIONS_NEXT_HEADER, |
| 502 | HOP_BY_HOP_OPTIONS_HDR_EXT_LEN, |
| 503 | HOP_BY_HOP_OPTIONS_OPTION_TYPE, |
| 504 | HOP_BY_HOP_OPTIONS_OPTION_LENGTH, |
| 505 | HOP_BY_HOP_OPTIONS_OPTION_DATA, |
| 506 | NO_HOP_BY_HOP_OPTIONS_FIELDS |
| 507 | } HOP_BY_HOP_OPTIONS_FIELDS; |
| 508 | |
| 509 | /* |
| 510 | * DESTINATION_OPTIONS_FIELDS: Enumeration listing the fields in a hop-by-hop |
| 511 | * options sub-header, acting as an index to the Rfc2507SubHeaderInfo[HOP_BY_HOP_OPTIONS_SUB_HEADER].FieldInfo |
| 512 | * array of FIELD_INFO, with the last item in this enumeration defining the |
| 513 | * number of elements in that array |
| 514 | */ |
| 515 | typedef enum |
| 516 | { |
| 517 | DESTINATION_OPTIONS_NEXT_HEADER, |
| 518 | DESTINATION_OPTIONS_HDR_EXT_LEN, |
| 519 | DESTINATION_OPTIONS_OPTION_TYPE, |
| 520 | DESTINATION_OPTIONS_OPTION_LENGTH, |
| 521 | DESTINATION_OPTIONS_OPTION_DATA, |
| 522 | NO_DESTINATION_OPTIONS_FIELDS |
| 523 | } DESTINATION_OPTIONS_FIELDS; |
| 524 | |
| 525 | /* |
| 526 | * ROUTING_FIELDS: Enumeration listing the fields in a routing sub-header, |
| 527 | * acting as an index to the Rfc2507SubHeaderInfo[ROUTING_SUB_HEADER].FieldInfo array of FIELD_INFO, with the |
| 528 | * last item in this enumeration defining the number of elements in that array |
| 529 | */ |
| 530 | typedef enum |
| 531 | { |
| 532 | ROUTING_NEXT_HEADER, |
| 533 | ROUTING_HDR_EXT_LEN, |
| 534 | ROUTING_ROUTING_TYPE, |
| 535 | ROUTING_SEGMENTS_LEFT, |
| 536 | ROUTING_TYPE_SPECIFIC_DATA, |
| 537 | NO_ROUTING_FIELDS |
| 538 | } ROUTING_FIELDS; |
| 539 | |
| 540 | /* |
| 541 | * FRAGMENT_FIELDS: Enumeration listing the fields in a fragment sub-header, |
| 542 | * acting as an index to the Rfc2507SubHeaderInfo[FRAGMENT_SUB_HEADER].FieldInfo array of FIELD_INFO, with the |
| 543 | * last item in this enumeration defining the number of elements in that array |
| 544 | */ |
| 545 | typedef enum |
| 546 | { |
| 547 | FRAGMENT_NEXT_HEADER, |
| 548 | FRAGMENT_RESERVED, |
| 549 | FRAGMENT_OFFSET, |
| 550 | FRAGMENT_RES, |
| 551 | FRAGMENT_M, |
| 552 | FRAGMENT_IDENTIFICATION, |
| 553 | NO_FRAGMENT_FIELDS |
| 554 | } FRAGMENT_FIELDS; |
| 555 | |
| 556 | /* |
| 557 | * AUTHENTICATION_FIELDS: Enumeration listing the fields in a authentification |
| 558 | * sub-header, acting as an index to the Rfc2507SubHeaderInfo[AUTHENTICATION_SUB_HEADER].FieldInfo array of |
| 559 | * FIELD_INFO, with the last item in this enumeration defining the number of |
| 560 | * elements in that array |
| 561 | */ |
| 562 | typedef enum |
| 563 | { |
| 564 | AUTHENTICATION_NEXT_HEADER, |
| 565 | AUTHENTICATION_LENGTH, |
| 566 | AUTHENTICATION_RESERVED, |
| 567 | AUTHENTICATION_SPI, |
| 568 | AUTHENTICATION_DATA, |
| 569 | NO_AUTHENTICATION_FIELDS |
| 570 | } AUTHENTICATION_FIELDS; |
| 571 | |
| 572 | /* |
| 573 | * ESP_FIELDS: Enumeration listing the fields in a ESP sub-header, acting as an |
| 574 | * index to the EspSubHeaderField array of FIELD_INFO, with the last item in |
| 575 | * this enumeration defining the number of elements in that array |
| 576 | */ |
| 577 | typedef enum |
| 578 | { |
| 579 | ESP_SPI, |
| 580 | ESP_DATA, |
| 581 | NO_ESP_FIELDS |
| 582 | } ESP_FIELDS; |
| 583 | |
| 584 | /* |
| 585 | * MINIMAL_ENCAPSULATION_FIELDS: Enumeration listing the fields in a minimal |
| 586 | * encapsulation sub-header, acting as an index to the |
| 587 | * Rfc2507SubHeaderInfo[MINIMAL_ENCAPSULATION_SUB_HEADER].FieldInfo array of FIELD_INFO, with the last item in |
| 588 | * this enumeration defining the number of elements in that array |
| 589 | */ |
| 590 | typedef enum |
| 591 | { |
| 592 | MINIMAL_ENCAPSULATION_PROTOCOL, |
| 593 | MINIMAL_ENCAPSULATION_S_BIT, |
| 594 | MINIMAL_ENCAPSULATION_RESERVED, |
| 595 | MINIMAL_ENCAPSULATION_HEADER_CHECKSUM, |
| 596 | MINIMAL_ENCAPSULATION_ORIG_DEST_ADDR, |
| 597 | MINIMAL_ENCAPSULATION_ORIG_SRC_ADDR, |
| 598 | NO_MINIMAL_ENCAPSULATION_FIELDS |
| 599 | } MINIMAL_ENCAPSULATION_FIELDS; |
| 600 | |
| 601 | /* |
| 602 | * TCP_FIELDS: Enumeration listing the fields in a TCP sub-header, acting as an |
| 603 | * index to the Rfc2507SubHeaderInfo[TCP_SUB_HEADER].FieldInfo array of FIELD_INFO, with the last item in |
| 604 | * this enumeration defining the number of elements in that array |
| 605 | */ |
| 606 | typedef enum |
| 607 | { |
| 608 | TCP_SOURCE_PORT, |
| 609 | TCP_DESTINATION_PORT, |
| 610 | TCP_SEQUENCE_NUMBER, |
| 611 | TCP_ACKNOWLEDGEMENT_NUMBER, |
| 612 | TCP_DATA_OFFSET, |
| 613 | TCP_RESERVED, |
| 614 | TCP_FLAGS, |
| 615 | TCP_WINDOW, |
| 616 | TCP_CHECKSUM, |
| 617 | TCP_URGENT_POINTER, |
| 618 | TCP_OPTIONS, |
| 619 | NO_TCP_FIELDS |
| 620 | } TCP_FIELDS; |
| 621 | |
| 622 | /* |
| 623 | * UDP_FIELDS: Enumeration listing the fields in a UDP sub-header, acting as an |
| 624 | * index to the Rfc2507SubHeaderInfo[UDP_SUB_HEADER].FieldInfo array of FIELD_INFO, with the last item in |
| 625 | * this enumeration defining the number of elements in that array |
| 626 | */ |
| 627 | typedef enum |
| 628 | { |
| 629 | UDP_SOURCE_PORT, |
| 630 | UDP_DESTINATION_PORT, |
| 631 | UDP_LENGTH, |
| 632 | UDP_CHECKSUM, |
| 633 | NO_UDP_FIELDS |
| 634 | } UDP_FIELDS; |
| 635 | |
| 636 | /* |
| 637 | * SUB_HEADER_CHAIN_INFO: structure for items in a linked list describing the |
| 638 | * sub-headers in an IP packet |
| 639 | */ |
| 640 | typedef struct |
| 641 | { |
| 642 | SUB_HEADER_TYPE Type; /* |
| 643 | * The type of the sub-header. Index to the |
| 644 | * Rfc2507SubHeaderInfo array of structures. |
| 645 | */ |
| 646 | kal_uint16 Start; /* |
| 647 | * The byte offset of the start of the sub-header |
| 648 | * from the start of the IP packet |
| 649 | */ |
| 650 | kal_uint16 Length; /* |
| 651 | * The length in bytes of the sub-header |
| 652 | */ |
| 653 | } SUB_HEADER_CHAIN_INFO; |
| 654 | |
| 655 | /* |
| 656 | * 2009.4.14 Robert add |
| 657 | * Use array to replace Dlist queue |
| 658 | */ |
| 659 | typedef struct |
| 660 | { |
| 661 | kal_uint8 HdrItemCount; /* Count of the sub-header. */ |
| 662 | kal_uint8 HdrItemCurrIdx; /* index of Current item. */ |
| 663 | |
| 664 | SUB_HEADER_CHAIN_INFO HdrItem[RFC2507_MAX_SUB_HEADER_CHAIN_NUM]; |
| 665 | /* |
| 666 | * The byte offset of the start of the sub-header |
| 667 | * from the start of the IP packet |
| 668 | */ |
| 669 | } SUB_HEADER_CHAIN_LIST; |
| 670 | |
| 671 | typedef struct _WindowHeader |
| 672 | { |
| 673 | struct _WindowHeader *pNext; |
| 674 | struct _WindowHeader *pPrev; |
| 675 | kal_uint8 *pPacket; |
| 676 | kal_uint16 PacketLen; |
| 677 | kal_uint16 PacketOffset; |
| 678 | kal_uint8 Pid; |
| 679 | kal_uint8 PacketInfo; |
| 680 | kal_uint8 L2HdrLength; |
| 681 | union |
| 682 | { |
| 683 | RFC2507_TIME_OF_DAY PacketTime; |
| 684 | kal_uint32 uwSequenceNo; |
| 685 | } uni; |
| 686 | } WindowHeader; |
| 687 | |
| 688 | typedef struct |
| 689 | { |
| 690 | kal_uint8 uCount; |
| 691 | WindowHeader *pHead; |
| 692 | WindowHeader *pTail; |
| 693 | } WindowList; |
| 694 | |
| 695 | /*********** FUNCTION DECLARATION ****************************************************/ |
| 696 | |
| 697 | INLINE_MODIFIER INLINE void Rfc2507_OS_CurrentTime(RFC2507_TIME_OF_DAY *currentTimeInTicks) |
| 698 | { |
| 699 | *currentTimeInTicks = kal_get_systicks(); |
| 700 | } |
| 701 | |
| 702 | extern void Rfc2507_CidInfoInsertAtStart(RFC2507_CID_LIST *pCidInfoList,RFC2507_COMMON_CID *pNewCidInfo); |
| 703 | extern void Rfc2507_CidInfoInsertAtEnd(RFC2507_CID_LIST *pCidInfoList,RFC2507_COMMON_CID *pNewCidInfo); |
| 704 | extern void Rfc2507_CidInfoInsertAtBefore(RFC2507_CID_LIST *pCidInfoList, RFC2507_COMMON_CID *pCurrCidInfo, |
| 705 | RFC2507_COMMON_CID *pNewCidInfo); |
| 706 | extern void Rfc2507_CidInfoDeleteFromList(RFC2507_CID_LIST *pCidInfoList, RFC2507_COMMON_CID *pCidInfo); |
| 707 | extern SUB_HEADER_CHAIN_INFO* Rfc2507_GetFirstSubHdrItem(SUB_HEADER_CHAIN_LIST *pSubHdrList ); |
| 708 | extern SUB_HEADER_CHAIN_INFO* Rfc2507_GetLastSubHdrItem(SUB_HEADER_CHAIN_LIST *pSubHdrList ); |
| 709 | extern SUB_HEADER_CHAIN_INFO* Rfc2507_GetNextSubHdrItem(SUB_HEADER_CHAIN_LIST *pSubHdrList ); |
| 710 | extern SUB_HEADER_CHAIN_INFO* Rfc2507_GetPrevSubHdrItem(SUB_HEADER_CHAIN_LIST *pSubHdrList ); |
| 711 | extern void Rfc2507_GetSubHeaderChainInfo(RFC2507_ENTITY_INFO *pEntity, kal_uint8* pPacket, |
| 712 | SUB_HEADER_CHAIN_LIST *pSubHdrList ); |
| 713 | extern kal_bool Rfc2507_IPv4IsFragment(kal_uint8 *SubHeader); |
| 714 | extern kal_bool Rfc2507_IPv4IsRandom(kal_uint8 *SubHeader); |
| 715 | extern kal_uint16 Rfc2507CalculateIpChecksum(kal_uint8 *pData, kal_uint32 length); |
| 716 | extern kal_bool Rfc2507_CompareSubHeaderChains(kal_uint8 *Chain1, SUB_HEADER_CHAIN_LIST *pSubHdrList1, |
| 717 | kal_uint8 *Chain2, SUB_HEADER_CHAIN_LIST *pSubHdrList2); |
| 718 | extern kal_uint16 Rfc2507_CompressOptions(kal_uint8 *dest, kal_uint32 compHdrOffset, const kal_uint8 *src, const kal_uint8 *saved, kal_uint16 size); |
| 719 | extern kal_uint16 Rfc2507_DecompressOptions(kal_uint8 *saved, const kal_uint8 *src, kal_uint16 size); |
| 720 | extern kal_bool Rfc2507ContextHasChanged(kal_uint8 *pInputSrc, |
| 721 | kal_uint8 *pSavedHeader, |
| 722 | SUB_HEADER_CHAIN_LIST *pSavedSubHdrList, |
| 723 | SUB_HEADER_CHAIN_LIST *pGivenSubHdrList, |
| 724 | kal_bool isTcpContext); |
| 725 | extern kal_uint16 Rfc2507CalculateChecksum(kal_uint8 *pData, |
| 726 | kal_uint16 dataLength, |
| 727 | kal_uint8 *pPseudoHeader, |
| 728 | kal_uint16 pseudoHeaderLength); |
| 729 | extern void Rfc2507InferFields(SUB_HEADER_CHAIN_LIST *pSubHdrList, |
| 730 | kal_uint8 *pReconstitutedPacket, |
| 731 | kal_uint16 uwPacketLength); |
| 732 | extern kal_bool Rfc2507InitStoredPacket(RFC2507_DECOMPRESS_INPUT_INFO *pInput, WindowList *pList, |
| 733 | kal_uint32 unionValue, WindowHeader **pStoredPacket); |
| 734 | extern void Rfc2507EmptyWindow(RFC2507_ENTITY_INFO *pEntity, WindowList *pList); |
| 735 | extern void Rfc2507DeleteStoredPacket(WindowList *pList, WindowHeader *pWindowItem); |
| 736 | extern kal_uint8 Rfc2507ProcessStoredPacket(RFC2507_DECOMPRESS_INPUT_INFO *pInput, |
| 737 | WindowList *pList, |
| 738 | kal_uint16 tcpExpectedPacketSn); |
| 739 | extern kal_uint16 Rfc2507ReconsIpv4SubHeader(kal_uint8 *pSavedHeader, |
| 740 | kal_uint8 *pPosReceivedHeader, |
| 741 | SUB_HEADER_CHAIN_LIST *pSubHdrList, |
| 742 | SUB_HEADER_CHAIN_INFO *pItem, |
| 743 | kal_bool isTcpDelta, |
| 744 | kal_uint16 *pSavedHeaderLength); |
| 745 | extern kal_uint16 Rfc2507DecompressRandomField(kal_uint8 *pSavedHeader, |
| 746 | kal_uint8 *pPosn, |
| 747 | SUB_HEADER_CHAIN_LIST *pSubHdrList, |
| 748 | kal_uint16 *pSavedHeaderLength, |
| 749 | kal_bool isTcpDelta); |
| 750 | extern kal_bool Rfc2507CompressRandomField(RFC2507_COMPRESS_INPUT_INFO *pInput, |
| 751 | SUB_HEADER_CHAIN_LIST *pSubHdrList, |
| 752 | kal_uint8 *pSavedHeader, |
| 753 | kal_uint8 *pPosn, |
| 754 | kal_uint32 *pCompHdrOffset); |
| 755 | kal_uint8 Rfc2507_BigEndGet8(kal_uint8 *pbSource); |
| 756 | kal_uint16 Rfc2507_BigEndGet16(kal_uint8 *abSource); |
| 757 | kal_uint32 Rfc2507_BigEndGet32(kal_uint8 *abSource); |
| 758 | void Rfc2507_BigEndSet16(kal_uint16 usSource, kal_uint8 *abDestination); |
| 759 | void Rfc2507_BigEndSet32(kal_uint32 ulSource, kal_uint8 *abDestination); |
| 760 | |
| 761 | /***** GLOBAL ************************************************************************/ |
| 762 | extern const SUB_HEADER_INFO Rfc2507SubHeaderInfo[NO_SUB_HEADERS]; |
| 763 | extern const kal_uint8 aRfc2507DecompressResultMappingTable[NO_OF_RFC2507_INTERNAL_DECOMPRESS_RESULT]; |
| 764 | |
| 765 | #ifdef __RFC2507_PDCP_UT__ |
| 766 | extern kal_uint8 PDCP_UT_SLIDING_WINDOW_SIZE_g; |
| 767 | #endif |
| 768 | |
| 769 | #endif /* _RFC2507_LIB_COMMON_H */ |