7e834a77b9ffd87b5958b202e05d0176e3eeda8d
[openwrt/openwrt.git] / package / broadcom-57xx / src / proto / bcmtcp.h
1 /*
2 * Copyright 2007, Broadcom Corporation
3 * All Rights Reserved.
4 *
5 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
7 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
8 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
9 *
10 * Fundamental constants relating to TCP Protocol
11 *
12 * $Id: bcmtcp.h,v 1.1.1.1 2007/05/31 08:00:41 michael Exp $
13 */
14
15 #ifndef _bcmtcp_h_
16 #define _bcmtcp_h_
17
18 /* enable structure packing */
19 #if defined(__GNUC__)
20 #define PACKED __attribute__((packed))
21 #else
22 #pragma pack(1)
23 #define PACKED
24 #endif
25
26 #define TCP_SRC_PORT_OFFSET 0 /* TCP source port offset */
27 #define TCP_DEST_PORT_OFFSET 2 /* TCP dest port offset */
28 #define TCP_CHKSUM_OFFSET 16 /* TCP body checksum offset */
29
30 /* These fields are stored in network order */
31 struct bcmtcp_hdr
32 {
33 uint16 src_port; /* Source Port Address */
34 uint16 dst_port; /* Destination Port Address */
35 uint32 seq_num; /* TCP Sequence Number */
36 uint32 ack_num; /* TCP Sequence Number */
37 uint16 hdrlen_rsvd_flags; /* Header length, reserved bits and flags */
38 uint16 tcpwin; /* TCP window */
39 uint16 chksum; /* Segment checksum with pseudoheader */
40 uint16 urg_ptr; /* Points to seq-num of byte following urg data */
41 } PACKED;
42
43 #undef PACKED
44 #if !defined(__GNUC__)
45 #pragma pack()
46 #endif
47
48 /* Byte offset of flags in TCP header */
49 #define TCP_FLAGS_OFFSET 13
50
51 #define TCP_FLAGS_FIN 0x01
52 #define TCP_FLAGS_SYN 0x02
53 #define TCP_FLAGS_RST 0x03
54 #define TCP_FLAGS_PSH 0x04
55 #define TCP_FLAGS_ACK 0x10
56 #define TCP_FLAGS_URG 0x20
57 #define TCP_FLAGS_ECN 0x40
58 #define TCP_FLAGS_CWR 0x80
59
60 #define TCP_FLAGS(tcp_hdr) (((uint8 *)(tcp_hdr))[TCP_FLAGS_OFFSET])
61 #define TCP_IS_ACK(tcp_hdr) (TCP_FLAGS(tcp_hdr) & TCP_FLAGS_ACK)
62
63 #define TCP_SRC_PORT(tcp_hdr) (ntoh16(((struct bcmtcp_hdr*)(tcp_hdr))->src_port))
64 #define TCP_DST_PORT(tcp_hdr) (ntoh16(((struct bcmtcp_hdr*)(tcp_hdr))->dst_port))
65 #define TCP_SEQ_NUM(tcp_hdr) (ntoh32(((struct bcmtcp_hdr*)(tcp_hdr))->seq_num))
66 #define TCP_ACK_NUM(tcp_hdr) (ntoh32(((struct bcmtcp_hdr*)(tcp_hdr))->ack_num))
67
68 #endif /* #ifndef _bcmtcp_h_ */