rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | #ifndef __RFC2507_LIB_TEST_H__ |
| 2 | #define __RFC2507_LIB_TEST_H__ |
| 3 | |
| 4 | #define RFC2507_DBG_MAX_NUMBER_BUFFER_ALLOC 300 |
| 5 | #define MAX_NUM_OF_PACKETS 6 |
| 6 | #define MAX_LEN_OF_PACKET 128 |
| 7 | |
| 8 | struct rfc2507_ctrl_buff_dbg_struct |
| 9 | { |
| 10 | kal_uint32 address; |
| 11 | kal_bool alloc; |
| 12 | kal_char *file_name; |
| 13 | kal_uint32 line; |
| 14 | }; |
| 15 | |
| 16 | struct rfc2507_ctrl_buff_size_info_struct |
| 17 | { |
| 18 | kal_uint32 buff_size; |
| 19 | kal_uint32 times; |
| 20 | }; |
| 21 | |
| 22 | extern struct rfc2507_ctrl_buff_dbg_struct g_rfc2507_alloc_buff_dbg[]; |
| 23 | extern kal_uint16 g_rfc2507_alloc_buff_dbg_count; |
| 24 | |
| 25 | struct rfc2507_dl_queue_struct |
| 26 | { |
| 27 | kal_bool is_used; |
| 28 | kal_uint16 bitLength; |
| 29 | peer_buff_struct *pFlcBuff; |
| 30 | }; |
| 31 | |
| 32 | /* Structure */ |
| 33 | // IPv4 Header |
| 34 | typedef struct ip_hdr |
| 35 | { |
| 36 | unsigned char ip_header_len:4; // 4-bit header length (in 32-bit words) |
| 37 | // normally=5 (Means 20 Bytes may be 24 also) |
| 38 | unsigned char ip_version :4; // 4-bit IPv4 version |
| 39 | unsigned char ip_tos; // IP type of service |
| 40 | unsigned short ip_total_length; // Total length |
| 41 | unsigned short ip_id; // Unique identifier |
| 42 | |
| 43 | unsigned char ip_frag_offset :5; // Fragment offset field |
| 44 | |
| 45 | unsigned char ip_more_fragment :1; |
| 46 | unsigned char ip_dont_fragment :1; |
| 47 | unsigned char ip_reserved_zero :1; |
| 48 | |
| 49 | unsigned char ip_frag_offset1; //fragment offset |
| 50 | |
| 51 | unsigned char ip_ttl; // Time to live |
| 52 | unsigned char ip_protocol; // Protocol(TCP,UDP etc) |
| 53 | unsigned short ip_checksum; // IP checksum |
| 54 | unsigned int ip_srcaddr; // Source address |
| 55 | unsigned int ip_destaddr; // Source address |
| 56 | } IPV4_HDR; |
| 57 | |
| 58 | // TCP header |
| 59 | typedef struct tcp_header |
| 60 | { |
| 61 | unsigned short source_port; // source port |
| 62 | unsigned short dest_port; // destination port |
| 63 | unsigned int sequence; // sequence number - 32 bits |
| 64 | unsigned int acknowledge; // acknowledgement number - 32 bits |
| 65 | |
| 66 | unsigned char reserved_part1:4; //according to rfc |
| 67 | unsigned char data_offset:4; /*The number of 32-bit words |
| 68 | in the TCP header. |
| 69 | This indicates where the data begins. |
| 70 | The length of the TCP header |
| 71 | is always a multiple |
| 72 | of 32 bits.*/ |
| 73 | |
| 74 | unsigned char fin :1; //Finish Flag |
| 75 | unsigned char syn :1; //Synchronise Flag |
| 76 | unsigned char rst :1; //Reset Flag |
| 77 | unsigned char psh :1; //Push Flag |
| 78 | unsigned char ack :1; //Acknowledgement Flag |
| 79 | unsigned char urg :1; //Urgent Flag |
| 80 | unsigned char reserved_part2 :2; |
| 81 | |
| 82 | //////////////////////////////// |
| 83 | |
| 84 | unsigned short window; // window |
| 85 | unsigned short checksum; // checksum |
| 86 | unsigned short urgent_pointer; // urgent pointer |
| 87 | } TCP_HDR; |
| 88 | |
| 89 | /* RFC793 and RFC768: Format of Pseudo Header |
| 90 | 0 7 8 15 16 23 24 31 |
| 91 | +--------+--------+--------+--------+ |
| 92 | | source address | |
| 93 | +--------+--------+--------+--------+ |
| 94 | | destination address | |
| 95 | +--------+--------+--------+--------+ |
| 96 | | zero | protocol | Length | |
| 97 | +--------+--------+--------+--------+ |
| 98 | */ |
| 99 | typedef struct ipv4_pseudo_header |
| 100 | { |
| 101 | unsigned int src_addr; |
| 102 | unsigned int dst_addr; |
| 103 | unsigned char zero; |
| 104 | unsigned char protocol; |
| 105 | unsigned short tcp_len; |
| 106 | } TCP_IPV4_PSEUDO_HEADER, UDP_IPV4_PSEUDO_HEADER; |
| 107 | |
| 108 | // UDP header |
| 109 | typedef struct udp_header |
| 110 | { |
| 111 | unsigned short source_port; // source port |
| 112 | unsigned short dest_port; // destination port |
| 113 | unsigned short length; /* |
| 114 | Length is the length in octets of this user datagram including this |
| 115 | header and the data. (This means the minimum value of the length is |
| 116 | eight.) |
| 117 | */ |
| 118 | unsigned short checksum; /* |
| 119 | Checksum is the 16-bit one's complement of the one's complement sum of a |
| 120 | pseudo header of information from the IP header, the UDP header, and the |
| 121 | data, padded with zero octets at the end (if necessary) to make a |
| 122 | multiple of two octets. |
| 123 | */ |
| 124 | } UDP_HDR; |
| 125 | |
| 126 | //IPv6 Header |
| 127 | typedef struct ipv6_header |
| 128 | { |
| 129 | unsigned char traffic_class_1:4; /* MSB of 8-bit traffic class */ |
| 130 | unsigned char version:4; /* 4-bit IPv6 version number = 6 */ |
| 131 | unsigned char flow_label_1:4; /* First 4-bit of of 20-bit flow label */ |
| 132 | unsigned char traffic_class_2:4; /* LSB of 8-bit traffic class */ |
| 133 | unsigned short flow_label_2; /* Last 16-bit of of 20-bit flow label */ |
| 134 | unsigned short payload_legth; /* 16-bit payload length. |
| 135 | Length of the IPv6 payload, i.e., the rest of the packet following this IPv6 header, in octets. |
| 136 | (Note that any extension headers present are considered part of the payload, i.e., included in the length count.) |
| 137 | */ |
| 138 | unsigned char next_header;/* 8-bit next header |
| 139 | 0: Hop-by-Hop Options header |
| 140 | 43: Routing header |
| 141 | 44: Fragment header |
| 142 | 59: No Next Header |
| 143 | */ |
| 144 | unsigned char hop_limit;/* 8-bit hop limit */ |
| 145 | unsigned int src_addr_1; |
| 146 | unsigned int src_addr_2; |
| 147 | unsigned int src_addr_3; |
| 148 | unsigned int src_addr_4; |
| 149 | unsigned int dst_addr_1; |
| 150 | unsigned int dst_addr_2; |
| 151 | unsigned int dst_addr_3; |
| 152 | unsigned int dst_addr_4; |
| 153 | } IPV6_HDR; |
| 154 | |
| 155 | //Hop-by-Hop Options Header |
| 156 | typedef struct hop_by_hop_header |
| 157 | { |
| 158 | unsigned char next_header;/* 8-bit next header */ |
| 159 | unsigned char hdr_ext_len; /* Length of the Hop-by-Hop Options header in 8-octet units, |
| 160 | NOT including the first 8 octets. |
| 161 | */ |
| 162 | } HOP_BY_HOP_HDR; |
| 163 | |
| 164 | //Routing Header |
| 165 | typedef struct routing_header |
| 166 | { |
| 167 | unsigned char next_header;/* 8-bit next header */ |
| 168 | unsigned char hdr_ext_len;/* Length of the Routing header in 8-octet units, |
| 169 | NOT including the first 8 octets. |
| 170 | */ |
| 171 | unsigned char routing_type; |
| 172 | unsigned char segments_left; |
| 173 | } ROUTING_HDR; |
| 174 | |
| 175 | //Fragment Header |
| 176 | typedef struct fragment_header |
| 177 | { |
| 178 | unsigned char next_header;/* 8-bit next header */ |
| 179 | unsigned char reserved;/* 8-bit reserved */ |
| 180 | unsigned char fragment_offset_1;/* First 8-bit of 13-bit fragment offset */ |
| 181 | unsigned char fragment_offset_2:4;/* Next 4-bit of 13-bit fragment offset */ |
| 182 | unsigned char fragment_offset_3:1;/* Last 1-bit of 13-bit fragment offset */ |
| 183 | unsigned char res:2;/* 2-bit Res */ |
| 184 | unsigned char m_flag:1;/* 1-bit M flag: 1=more fragments;0=last fragment */ |
| 185 | unsigned int identification;/* 32-bit identification */ |
| 186 | } FRAGMENT_HDR; |
| 187 | |
| 188 | //Authentication Header |
| 189 | typedef struct authentication_header |
| 190 | { |
| 191 | unsigned char next_header;/* 8-bit next header */ |
| 192 | unsigned char length;/* 8-bit length */ |
| 193 | unsigned short reserved;/* 16 bit reserved */ |
| 194 | unsigned int spi; /* 32-bit security parameters index */ |
| 195 | } AUTHENTICATION_HDR; |
| 196 | |
| 197 | //Destination Options Header |
| 198 | typedef struct destination_options_header |
| 199 | { |
| 200 | unsigned char next_header;/* 8-bit next header */ |
| 201 | unsigned char hdr_ext_len;/* Length of the Destination Options header in 8-octet units, |
| 202 | NOT including the first 8 octets. |
| 203 | */ |
| 204 | } DESTINATION_OPTIONS_HDR; |
| 205 | |
| 206 | //Encapsulating Security Payload Header |
| 207 | typedef struct esp_header |
| 208 | { |
| 209 | unsigned int spi; /* 32-bit security association identifier (SPI), 32 bits */ |
| 210 | } ESP_HDR; |
| 211 | |
| 212 | typedef struct ipv6_pseudo_header |
| 213 | { |
| 214 | unsigned int src_addr1; |
| 215 | unsigned int src_addr2; |
| 216 | unsigned int src_addr3; |
| 217 | unsigned int src_addr4; |
| 218 | unsigned int dst_addr1; |
| 219 | unsigned int dst_addr2; |
| 220 | unsigned int dst_addr3; |
| 221 | unsigned int dst_addr4; |
| 222 | unsigned int upper_layer_pkt_len; |
| 223 | unsigned short zero1; |
| 224 | unsigned char zero2; |
| 225 | unsigned char next_header; |
| 226 | } TCP_IPV6_PSEUDO_HEADER, UDP_IPV6_PSEUDO_HEADER; |
| 227 | |
| 228 | typedef struct |
| 229 | { |
| 230 | /* IP Part */ |
| 231 | unsigned char TOS; |
| 232 | unsigned short IPId; |
| 233 | unsigned char Protocol; |
| 234 | unsigned int SrcAddr; |
| 235 | unsigned int DstAddr; |
| 236 | /* TCP Part */ |
| 237 | unsigned short SrcPort; |
| 238 | unsigned short DstPort; |
| 239 | unsigned int Seq; |
| 240 | unsigned int Ack; |
| 241 | unsigned char Reserved; |
| 242 | unsigned short Window; |
| 243 | unsigned short UrgentPointer; |
| 244 | } TCP_IP_CONN_PROFILE; |
| 245 | |
| 246 | typedef struct |
| 247 | { |
| 248 | /* IP Part */ |
| 249 | unsigned char TOS; |
| 250 | unsigned short IPId; |
| 251 | unsigned char Protocol; |
| 252 | unsigned int SrcAddr; |
| 253 | unsigned int DstAddr; |
| 254 | /* UDP Part */ |
| 255 | unsigned short SrcPort; |
| 256 | unsigned short DstPort; |
| 257 | } UDP_IP_CONN_PROFILE; |
| 258 | |
| 259 | typedef struct |
| 260 | { |
| 261 | /* IPv6 Part */ |
| 262 | unsigned char TrafficClass; |
| 263 | unsigned int FlowLabel; |
| 264 | unsigned char NextHeader; |
| 265 | unsigned char HopLimit; |
| 266 | unsigned int SrcAddr1; |
| 267 | unsigned int SrcAddr2; |
| 268 | unsigned int SrcAddr3; |
| 269 | unsigned int SrcAddr4; |
| 270 | unsigned int DstAddr1; |
| 271 | unsigned int DstAddr2; |
| 272 | unsigned int DstAddr3; |
| 273 | unsigned int DstAddr4; |
| 274 | /* TCP Part */ |
| 275 | unsigned short SrcPort; |
| 276 | unsigned short DstPort; |
| 277 | unsigned int Seq; |
| 278 | unsigned int Ack; |
| 279 | unsigned char Reserved; |
| 280 | unsigned short Window; |
| 281 | unsigned short UrgentPointer; |
| 282 | } TCP_IPv6_CONN_PROFILE; |
| 283 | |
| 284 | typedef struct |
| 285 | { |
| 286 | /* IPv6 Part */ |
| 287 | unsigned char TrafficClass; |
| 288 | unsigned int FlowLabel; |
| 289 | unsigned char NextHeader; |
| 290 | unsigned char HopLimit; |
| 291 | unsigned int SrcAddr1; |
| 292 | unsigned int SrcAddr2; |
| 293 | unsigned int SrcAddr3; |
| 294 | unsigned int SrcAddr4; |
| 295 | unsigned int DstAddr1; |
| 296 | unsigned int DstAddr2; |
| 297 | unsigned int DstAddr3; |
| 298 | unsigned int DstAddr4; |
| 299 | /* UDP Part */ |
| 300 | unsigned short SrcPort; |
| 301 | unsigned short DstPort; |
| 302 | } UDP_IPv6_CONN_PROFILE; |
| 303 | |
| 304 | typedef struct |
| 305 | { |
| 306 | unsigned int length; |
| 307 | unsigned char PacketData[MAX_LEN_OF_PACKET]; |
| 308 | } PACKET; |
| 309 | |
| 310 | typedef struct |
| 311 | { |
| 312 | unsigned int NoPackets; |
| 313 | PACKET *Packets[MAX_NUM_OF_PACKETS]; |
| 314 | } PACKET_STREAM_PATTERN; |
| 315 | |
| 316 | typedef enum |
| 317 | { |
| 318 | PACKET_STREAM_PATTERN_BEGIN = 201, |
| 319 | PSP_IPV4_TCP = PACKET_STREAM_PATTERN_BEGIN, |
| 320 | PSP_IPV4_UDP, |
| 321 | PSP_IPV6_TCP, |
| 322 | PSP_IPV6_UDP, |
| 323 | PSP_SPECIFIC_BEGIN = PSP_IPV6_UDP + 1, // 205 |
| 324 | PSP_IPV6_ROUTING_TCP = PSP_SPECIFIC_BEGIN, // 205 |
| 325 | PSP_IPV6_ROUTING_UDP, // 206 |
| 326 | PSP_IPV6_AUTH_TCP, // 207 |
| 327 | PSP_IPV6_ESP, // 208 |
| 328 | PSP_IPV6_FRAGMENT_TCP, // 209, TCP header will not be compressed |
| 329 | PSP_IPV4_MINIMAL_ENCAPSULATION_TCP, // 210, Minimal encapsulation header now is for IPv4 only |
| 330 | PSP_IPV6_ROUTING_NO_NEXT, // 211 |
| 331 | PSP_IPV6_HOP_BY_HOP_TCP, // 212 |
| 332 | PSP_IPV6_DESTINATION_TCP, // 213 |
| 333 | PSP_DEFINED_LAST = PSP_IPV6_DESTINATION_TCP, |
| 334 | PSP_SPECIFIC_END = 254 |
| 335 | } packet_stream_pattern_enum; |
| 336 | |
| 337 | extern packet_stream_pattern_enum psp_pattern; |
| 338 | |
| 339 | #define NUM_SPECIFIC_PSP (PSP_DEFINED_LAST - PSP_SPECIFIC_BEGIN + 1) |
| 340 | #define NOW_PSP() (psp_pattern) |
| 341 | #define SET_PSP(x) \ |
| 342 | if ((PACKET_STREAM_PATTERN_BEGIN <= x) && (PSP_SPECIFIC_END >= x)) \ |
| 343 | { \ |
| 344 | psp_pattern = x; \ |
| 345 | } |
| 346 | |
| 347 | /* External Function */ |
| 348 | extern void InitializePacketGenerator(void); |
| 349 | extern void rfc2507_dbg_buff_init(void); |
| 350 | extern void rfc2507_check_mem_leak(void); |
| 351 | |
| 352 | extern kal_uint8 rfc2507_check_if_queue_dl_data(kal_uint16 bitLength, peer_buff_struct *pFlcBuff); |
| 353 | extern peer_buff_struct *rfc2507_retrive_dl_data_from_queue(kal_uint16 *bitLength); |
| 354 | extern void rfc2507_packet_verify(peer_buff_struct *pData); |
| 355 | extern kal_bool rfc2507_prepare_test_data_to_ratdm(void** ppData, int* pDataSize, packet_stream_pattern_enum psp); |
| 356 | extern void rfc2507_dump_packet(char* pData, int pDataSize); |
| 357 | |
| 358 | #endif /* __RFC2507_LIB_TEST_H__*/ |