blob: e0ae6438f5a9bc588bea4bca46c7dfcd950a712a [file] [log] [blame]
/*
* Fundamental constants relating to TCP Protocol
*
* Copyright 1999-2016, Broadcom Corporation
* All rights reserved,
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided by the copyright holder "as is" and any express or
* implied warranties, including, but not limited to, the implied warranties of
* merchantability and fitness for a particular purpose are disclaimed. In no event
* shall copyright holder be liable for any direct, indirect, incidental, special,
* exemplary, or consequential damages (including, but not limited to, procurement
* of substitute goods or services; loss of use, data, or profits; or business
* interruption) however caused and on any theory of liability, whether in
* contract, strict liability, or tort (including negligence or otherwise) arising
* in any way out of the use of this software, even if advised of the possibility
* of such damage
*
*
* <<Broadcom-WL-IPTag/Open:>>
*
* $Id: bcmtcp.h 518342 2014-12-01 23:21:41Z $
*/
#ifndef _bcmtcp_h_
#define _bcmtcp_h_
#ifndef _TYPEDEFS_H_
#include <typedefs.h>
#endif
/* This marks the start of a packed structure section. */
#include <packed_section_start.h>
#define TCP_SRC_PORT_OFFSET 0 /* TCP source port offset */
#define TCP_DEST_PORT_OFFSET 2 /* TCP dest port offset */
#define TCP_SEQ_NUM_OFFSET 4 /* TCP sequence number offset */
#define TCP_ACK_NUM_OFFSET 8 /* TCP acknowledgement number offset */
#define TCP_HLEN_OFFSET 12 /* HLEN and reserved bits offset */
#define TCP_FLAGS_OFFSET 13 /* FLAGS and reserved bits offset */
#define TCP_CHKSUM_OFFSET 16 /* TCP body checksum offset */
#define TCP_PORT_LEN 2 /* TCP port field length */
/* 8bit TCP flag field */
#define TCP_FLAG_URG 0x20
#define TCP_FLAG_ACK 0x10
#define TCP_FLAG_PSH 0x08
#define TCP_FLAG_RST 0x04
#define TCP_FLAG_SYN 0x02
#define TCP_FLAG_FIN 0x01
#define TCP_HLEN_MASK 0xf000
#define TCP_HLEN_SHIFT 12
/* These fields are stored in network order */
BWL_PRE_PACKED_STRUCT struct bcmtcp_hdr
{
uint16 src_port; /* Source Port Address */
uint16 dst_port; /* Destination Port Address */
uint32 seq_num; /* TCP Sequence Number */
uint32 ack_num; /* TCP Sequence Number */
uint16 hdrlen_rsvd_flags; /* Header length, reserved bits and flags */
uint16 tcpwin; /* TCP window */
uint16 chksum; /* Segment checksum with pseudoheader */
uint16 urg_ptr; /* Points to seq-num of byte following urg data */
} BWL_POST_PACKED_STRUCT;
#define TCP_MIN_HEADER_LEN 20
#define TCP_HDRLEN_MASK 0xf0
#define TCP_HDRLEN_SHIFT 4
#define TCP_HDRLEN(hdrlen) (((hdrlen) & TCP_HDRLEN_MASK) >> TCP_HDRLEN_SHIFT)
#define TCP_FLAGS_MASK 0x1f
#define TCP_FLAGS(hdrlen) ((hdrlen) & TCP_FLAGS_MASK)
/* This marks the end of a packed structure section. */
#include <packed_section_end.h>
/* To address round up by 32bit. */
#define IS_TCPSEQ_GE(a, b) ((a - b) < NBITVAL(31)) /* a >= b */
#define IS_TCPSEQ_LE(a, b) ((b - a) < NBITVAL(31)) /* a =< b */
#define IS_TCPSEQ_GT(a, b) !IS_TCPSEQ_LE(a, b) /* a > b */
#define IS_TCPSEQ_LT(a, b) !IS_TCPSEQ_GE(a, b) /* a < b */
#endif /* #ifndef _bcmtcp_h_ */