1190207Srpaulo/* @(#) $Header: /tcpdump/master/tcpdump/dccp.h,v 1.5 2006-11-02 09:05:23 hannes Exp $ (LBL) */
2162017Ssam/*
3162017Ssam * Copyright (C) Arnaldo Carvalho de Melo 2004
4162017Ssam * Copyright (C) Ian McDonald 2005 <iam4@cs.waikato.ac.nz>
5162017Ssam * Copyright (C) Yoshifumi Nishida 2005
6162017Ssam *
7162017Ssam * This software may be distributed either under the terms of the
8162017Ssam * BSD-style license that accompanies tcpdump or the GNU GPL version 2
9162017Ssam */
10162017Ssam
11162017Ssam#ifndef __DCCP_HDR__
12162017Ssam#define __DCCP_HDR__
13162017Ssam
14162017Ssam/**
15162017Ssam * struct dccp_hdr - generic part of DCCP packet header
16162017Ssam *
17162017Ssam * @dccph_sport - Relevant port on the endpoint that sent this packet
18162017Ssam * @dccph_dport - Relevant port on the other endpoint
19162017Ssam * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words
20162017Ssam * @dccph_ccval - Used by the HC-Sender CCID
21162017Ssam * @dccph_cscov - Parts of the packet that are covered by the Checksum field
22162017Ssam * @dccph_checksum - Internet checksum, depends on dccph_cscov
23162017Ssam * @dccph_x - 0 = 24 bit sequence number, 1 = 48
24162017Ssam * @dccph_type - packet type, see DCCP_PKT_ prefixed macros
25162017Ssam * @dccph_seq - sequence number high or low order 24 bits, depends on dccph_x
26162017Ssam */
27162017Ssamstruct dccp_hdr {
28162017Ssam	u_int16_t	dccph_sport,
29162017Ssam			dccph_dport;
30162017Ssam	u_int8_t	dccph_doff;
31162017Ssam	u_int8_t	dccph_ccval_cscov;
32162017Ssam	u_int16_t	dccph_checksum;
33162017Ssam	union {
34162017Ssam	u_int8_t	dccph_xtr;
35162017Ssam	u_int32_t	dccph_seq;
36162017Ssam	}		dccph_xtrs;
37162017Ssam};
38162017Ssam
39190207Srpaulo#define DCCPH_CCVAL(dh)	(((dh)->dccph_ccval_cscov >> 4) & 0xF)
40190207Srpaulo#define DCCPH_CSCOV(dh)	(((dh)->dccph_ccval_cscov) & 0xF)
41162017Ssam
42162017Ssam#define DCCPH_X(dh)	((dh)->dccph_xtrs.dccph_xtr & 1)
43162017Ssam#define DCCPH_TYPE(dh)	(((dh)->dccph_xtrs.dccph_xtr >> 1) & 0xF)
44162017Ssam#define DCCPH_SEQ(dh)   (((dh)->dccph_xtrs.dccph_seq) >> 8)
45162017Ssam
46162017Ssam/**
47162017Ssam * struct dccp_hdr_ext - the low bits of a 48 bit seq packet
48162017Ssam *
49162017Ssam * @dccph_seq_low - low 24 bits of a 48 bit seq packet
50162017Ssam */
51162017Ssamstruct dccp_hdr_ext {
52162017Ssam	u_int32_t	dccph_seq_low;
53162017Ssam};
54162017Ssam
55162017Ssam/**
56162017Ssam * struct dccp_hdr_request - Conection initiation request header
57162017Ssam *
58162017Ssam * @dccph_req_service - Service to which the client app wants to connect
59162017Ssam */
60162017Ssamstruct dccp_hdr_request {
61162017Ssam	u_int32_t	dccph_req_service;
62162017Ssam};
63162017Ssam
64162017Ssam/**
65162017Ssam * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets
66162017Ssam *
67162017Ssam * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
68162017Ssam * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
69162017Ssam */
70162017Ssamstruct dccp_hdr_ack_bits {
71162017Ssam	u_int32_t	dccph_ra;
72162017Ssam	u_int32_t	dccph_ack_nr_low;
73162017Ssam};
74162017Ssam
75162017Ssam#define DCCPH_ACK(dh_ack)   ((dh_ack)->dccph_ra >> 8)
76162017Ssam
77162017Ssam/**
78162017Ssam * struct dccp_hdr_response - Conection initiation response header
79162017Ssam *
80162017Ssam * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
81162017Ssam * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
82162017Ssam * @dccph_resp_service - Echoes the Service Code on a received DCCP-Request
83162017Ssam */
84162017Ssamstruct dccp_hdr_response {
85162017Ssam	struct dccp_hdr_ack_bits	dccph_resp_ack;
86162017Ssam	u_int32_t			dccph_resp_service;
87162017Ssam};
88162017Ssam
89172683Smlaier#if 0
90162017Ssamstatic inline struct dccp_hdr_data *dccp_hdr_data(struct dccp_hdr *hdrg)
91162017Ssam{
92162017Ssam	const int ext = DCCPH_X(hdrg) ? sizeof(struct dccp_hdr_ext) : 0;
93162017Ssam
94162017Ssam	return (struct dccp_hdr_data *)(((u_char *)hdrg) + sizeof(hdrg) + ext);
95162017Ssam}
96172683Smlaier#endif
97162017Ssam
98162017Ssam/**
99162017Ssam * struct dccp_hdr_reset - Unconditionally shut down a connection
100162017Ssam *
101162017Ssam * @dccph_reset_service - Echoes the Service Code on a received DCCP-Request
102162017Ssam */
103162017Ssamstruct dccp_hdr_reset {
104162017Ssam	struct dccp_hdr_ack_bits	dccph_reset_ack;
105162017Ssam	u_int8_t			dccph_reset_code,
106162017Ssam					dccph_reset_data[3];
107162017Ssam};
108162017Ssam
109162017Ssamenum dccp_pkt_type {
110162017Ssam	DCCP_PKT_REQUEST = 0,
111162017Ssam	DCCP_PKT_RESPONSE,
112162017Ssam	DCCP_PKT_DATA,
113162017Ssam	DCCP_PKT_ACK,
114162017Ssam	DCCP_PKT_DATAACK,
115162017Ssam	DCCP_PKT_CLOSEREQ,
116162017Ssam	DCCP_PKT_CLOSE,
117162017Ssam	DCCP_PKT_RESET,
118162017Ssam	DCCP_PKT_SYNC,
119162017Ssam	DCCP_PKT_SYNCACK,
120172683Smlaier	DCCP_PKT_INVALID
121162017Ssam};
122162017Ssam
123162017Ssamenum dccp_reset_codes {
124162017Ssam	DCCP_RESET_CODE_UNSPECIFIED = 0,
125162017Ssam	DCCP_RESET_CODE_CLOSED,
126162017Ssam	DCCP_RESET_CODE_ABORTED,
127162017Ssam	DCCP_RESET_CODE_NO_CONNECTION,
128162017Ssam	DCCP_RESET_CODE_PACKET_ERROR,
129162017Ssam	DCCP_RESET_CODE_OPTION_ERROR,
130162017Ssam	DCCP_RESET_CODE_MANDATORY_ERROR,
131162017Ssam	DCCP_RESET_CODE_CONNECTION_REFUSED,
132162017Ssam	DCCP_RESET_CODE_BAD_SERVICE_CODE,
133162017Ssam	DCCP_RESET_CODE_TOO_BUSY,
134162017Ssam	DCCP_RESET_CODE_BAD_INIT_COOKIE,
135162017Ssam	DCCP_RESET_CODE_AGGRESSION_PENALTY,
136172683Smlaier	__DCCP_RESET_CODE_LAST
137162017Ssam};
138162017Ssam
139162017Ssam#endif /* __DCCP_HDR__ */
140