1/* 2 * Fundamental constants relating to TCP Protocol 3 * 4 * Copyright (C) 2015, Broadcom Corporation. All Rights Reserved. 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * 18 * $Id: bcmtcp.h 434054 2013-11-05 02:01:21Z $ 19 */ 20 21#ifndef _bcmtcp_h_ 22#define _bcmtcp_h_ 23 24#ifndef _TYPEDEFS_H_ 25#include <typedefs.h> 26#endif 27 28/* This marks the start of a packed structure section. */ 29#include <packed_section_start.h> 30 31 32#define TCP_SRC_PORT_OFFSET 0 /* TCP source port offset */ 33#define TCP_DEST_PORT_OFFSET 2 /* TCP dest port offset */ 34#define TCP_SEQ_NUM_OFFSET 4 /* TCP sequence number offset */ 35#define TCP_ACK_NUM_OFFSET 8 /* TCP acknowledgement number offset */ 36#define TCP_HLEN_OFFSET 12 /* HLEN and reserved bits offset */ 37#define TCP_FLAGS_OFFSET 13 /* FLAGS and reserved bits offset */ 38#define TCP_CHKSUM_OFFSET 16 /* TCP body checksum offset */ 39 40#define TCP_PORT_LEN 2 /* TCP port field length */ 41 42/* 8bit TCP flag field */ 43#define TCP_FLAG_URG 0x20 44#define TCP_FLAG_ACK 0x10 45#define TCP_FLAG_PSH 0x08 46#define TCP_FLAG_RST 0x04 47#define TCP_FLAG_SYN 0x02 48#define TCP_FLAG_FIN 0x01 49 50#define TCP_HLEN_MASK 0xf000 51#define TCP_HLEN_SHIFT 12 52 53/* These fields are stored in network order */ 54BWL_PRE_PACKED_STRUCT struct bcmtcp_hdr 55{ 56 uint16 src_port; /* Source Port Address */ 57 uint16 dst_port; /* Destination Port Address */ 58 uint32 seq_num; /* TCP Sequence Number */ 59 uint32 ack_num; /* TCP Sequence Number */ 60 uint16 hdrlen_rsvd_flags; /* Header length, reserved bits and flags */ 61 uint16 tcpwin; /* TCP window */ 62 uint16 chksum; /* Segment checksum with pseudoheader */ 63 uint16 urg_ptr; /* Points to seq-num of byte following urg data */ 64} BWL_POST_PACKED_STRUCT; 65 66 67/*borg DTM QoS*/ 68/* Byte offset of flags in TCP header */ 69#define TCP_FLAGS_OFFSET 13 70 71#define TCP_MIN_HEADER_LEN 20 72#define TCP_FLAGS_FIN 0x01 73#define TCP_FLAGS_SYN 0x02 74#define TCP_FLAGS_RST 0x03 75#define TCP_FLAGS_PSH 0x04 76#define TCP_FLAGS_ACK 0x10 77#define TCP_FLAGS_URG 0x20 78#define TCP_FLAGS_ECN 0x40 79#define TCP_FLAGS_CWR 0x80 80 81#define TCP_IS_ACK(tcp_hdr) (TCP_FLAGS(tcp_hdr) & TCP_FLAGS_ACK) 82 83#define TCP_SRC_PORT(tcp_hdr) (ntoh16(((struct bcmtcp_hdr*)(tcp_hdr))->src_port)) 84#define TCP_DST_PORT(tcp_hdr) (ntoh16(((struct bcmtcp_hdr*)(tcp_hdr))->dst_port)) 85#define TCP_SEQ_NUM(tcp_hdr) (ntoh32(((struct bcmtcp_hdr*)(tcp_hdr))->seq_num)) 86#define TCP_ACK_NUM(tcp_hdr) (ntoh32(((struct bcmtcp_hdr*)(tcp_hdr))->ack_num)) 87 88#define TCP_HDRLEN_MASK 0xf0 89#define TCP_HDRLEN_SHIFT 4 90#define TCP_HDRLEN(hdrlen) (((hdrlen) & TCP_HDRLEN_MASK) >> TCP_HDRLEN_SHIFT) 91 92#define TCP_FLAGS_MASK 0x1f 93#define TCP_FLAGS(hdrlen) ((hdrlen) & TCP_FLAGS_MASK) 94 95/* This marks the end of a packed structure section. */ 96#include <packed_section_end.h> 97 98#endif /* #ifndef _bcmtcp_h_ */ 99