Support for 802.11+Prism II monitor-mode link-layer headers, from
[obnox/wireshark/wip.git] / packet-pgm.h
1 /* packet-pgm.h
2  * Declarations for pgm packet disassembly
3  *
4  * $Id: packet-pgm.h,v 1.6 2001/08/06 19:05:14 guy Exp $
5  * 
6  * Copyright (c) 2000 by Talarian Corp
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1999 Gerald Combs
11  * 
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifndef _PACKET_PGM_H
28 #define _PACKET_PGM_H
29 typedef guint8 nchar_t;
30 typedef guint16 nshort_t;
31 typedef guint32 nlong_t;
32
33 /* The PGM main header */
34 typedef struct {
35         nshort_t sport;            /* source port */
36         nshort_t dport;            /* destination port */
37         nchar_t type;              /* PGM type */
38         nchar_t opts;              /* options */
39         nshort_t cksum;            /* checksum */
40         nchar_t gsi[6];            /* Global Source ID */
41         nshort_t tsdulen;          /* TSDU length */
42 } pgm_type;
43 #define pgmhdr_ntoh(_p) \
44         (_p)->sport = ntohs((_p)->sport); \
45         (_p)->dport = ntohs((_p)->dport); \
46         (_p)->type = ntohs((_p)->type); \
47         (_p)->opts = ntohs((_p)->opts); \
48         (_p)->cksum = ntohs((_p)->cksum); \
49         (_p)->tsdulen = ntohs((_p)->tsdulen)
50
51 /* The PGM SPM header */
52 typedef struct {
53         nlong_t sqn;              /* SPM's sequence number */
54         nlong_t trail;            /* Trailing edge sequence number */
55         nlong_t lead;             /* Leading edge sequence number */
56         nshort_t path_afi;        /* NLA AFI */
57         nshort_t res;             /* reserved */
58         nlong_t path;             /* Path NLA */
59 } pgm_spm_t;
60 const size_t PGM_SPM_SZ = sizeof(pgm_type)+sizeof(pgm_spm_t);
61 #define spm_ntoh(_p) \
62         (_p)->sqn = ntohl((_p)->sqn); \
63         (_p)->trail = ntohl((_p)->trail); \
64         (_p)->lead = ntohl((_p)->lead); \
65         (_p)->path_afi = ntohs((_p)->path_afi); \
66         (_p)->res = ntohs((_p)->res);
67
68 /* The PGM Data (ODATA/RDATA) header */
69 typedef struct {
70         nlong_t sqn;              /* Data Packet sequence number */
71         nlong_t trail;            /* Trailing edge sequence number */
72 } pgm_data_t;
73 #define data_ntoh(_p) \
74         (_p)->sqn = ntohl((_p)->sqn); \
75         (_p)->trail = ntohl((_p)->trail)
76 const size_t PGM_DATA_HDR_SZ = sizeof(pgm_type)+sizeof(pgm_data_t);
77
78 /* The PGM NAK (NAK/N-NAK/NCF) header */
79 typedef struct {
80         nlong_t sqn;             /* Requested sequence number */
81         nshort_t src_afi;        /* NLA AFI for source (IPv4 is set to 1) */
82         nshort_t src_res;        /* reserved */
83         nlong_t src;             /* Source NLA  */
84         nshort_t grp_afi;        /* Multicast group AFI (IPv4 is set to 1) */
85         nshort_t grp_res;        /* reserved */
86         nlong_t grp;             /* Multicast group NLA */
87 } pgm_nak_t;
88 const size_t PGM_NAK_SZ = sizeof(pgm_type)+sizeof(pgm_nak_t);
89 #define nak_ntoh(_p) \
90         (_p)->sqn = ntohl((_p)->sqn); \
91         (_p)->src_afi = ntohs((_p)->src_afi); \
92         (_p)->src_res = ntohs((_p)->src_res); \
93         (_p)->grp_afi = ntohs((_p)->grp_afi); \
94         (_p)->grp_res = ntohs((_p)->grp_res)
95
96 /* The PGM ACK header (PGMCC) */
97 typedef struct {
98         nlong_t rx_max_sqn;      /* RX_MAX sequence number */
99         nlong_t bitmap;          /* Received Packet Bitmap */
100 } pgm_ack_t;
101 const size_t PGM_ACK_SZ = sizeof(pgm_type)+sizeof(pgm_ack_t);
102 #define ack_ntoh(_p) \
103         (_p)->rx_max_sqn = ntohl((_p)->rx_max_sqn); \
104         (_p)->bitmap = ntohl((_p)->bitmap)
105
106 /* constants for hdr types */
107 #if defined(PGM_SPEC_01_PCKTS)
108 /* old spec-01 types */
109 #define PGM_SPM_PCKT  0x00
110 #define PGM_ODATA_PCKT  0x10
111 #define PGM_RDATA_PCKT  0x11
112 #define PGM_NAK_PCKT  0x20
113 #define PGM_NNAK_PCKT  0x21
114 #define PGM_NCF_PCKT 0x30
115 #else
116 /* spec-02 types (as well as spec-04+) */
117 #define PGM_SPM_PCKT  0x00
118 #define PGM_ODATA_PCKT  0x04
119 #define PGM_RDATA_PCKT  0x05
120 #define PGM_NAK_PCKT  0x08
121 #define PGM_NNAK_PCKT  0x09
122 #define PGM_NCF_PCKT 0x0A
123 #define PGM_ACK_PCKT 0x0D
124 #endif /* PGM_SPEC_01_PCKTS */
125
126 /* port swapping on NAK and NNAKs or not (default is to swap) */
127 /* PGM_NO_PORT_SWAP */
128
129 /* option flags (main PGM header) */
130 #define PGM_OPT 0x01
131 #define PGM_OPT_NETSIG 0x02
132 #define PGM_OPT_VAR_PKTLEN 0x40
133 #define PGM_OPT_PARITY 0x80
134
135 /* option types */
136 #define PGM_OPT_LENGTH 0x00
137 #define PGM_OPT_END 0x80
138 #define PGM_OPT_FRAGMENT 0x01
139 #define PGM_OPT_NAK_LIST 0x02
140 #define PGM_OPT_JOIN 0x03
141 #define PGM_OPT_REDIRECT 0x07
142 #define PGM_OPT_SYN 0x0D
143 #define PGM_OPT_FIN 0x0E
144 #define PGM_OPT_RST 0x0F
145 #define PGM_OPT_PARITY_PRM 0x08
146 #define PGM_OPT_PARITY_GRP 0x09
147 #define PGM_OPT_CURR_TGSIZE 0x0A
148 #define PGM_OPT_PGMCC_DATA  0x12
149 #define PGM_OPT_PGMCC_FEEDBACK  0x13
150
151 const nchar_t PGM_OPT_INVALID = 0x7F;
152
153 /* OPX bit values */
154 #define PGM_OPX_IGNORE  0x00
155 #define PGM_OPX_INVAL   0x01
156 #define PGM_OPX_DISCARD 0x10
157
158 /* option formats */
159 typedef struct {
160         nchar_t type;
161         nchar_t len;
162         nchar_t opx;
163         nchar_t res;
164 } pgm_opt_generic_t;
165
166 typedef struct {
167         nchar_t type;
168         nchar_t len;
169         nshort_t total_len;
170 } pgm_opt_length_t;
171
172 typedef struct {
173         nchar_t type;
174         nchar_t len;
175         nchar_t opx;
176         nchar_t res;
177 } pgm_opt_nak_list_t;
178
179 /* 
180  * To squeeze the whole option into 255 bytes, we
181  * can only have 62 in the list
182  */
183 #define PGM_MAX_NAK_LIST_SZ (62)
184
185 typedef struct {
186         nchar_t type;
187         nchar_t len;
188         nchar_t opx;
189         nchar_t res;
190         nlong_t opt_join_min;
191 } pgm_opt_join_t;
192
193 typedef struct {
194         nchar_t type;
195         nchar_t len;
196         nchar_t opx;
197         nchar_t po;
198         nlong_t prm_tgsz;
199 } pgm_opt_parity_prm_t;
200
201 /* OPT_PARITY_PRM P and O bits */
202 const nchar_t PGM_OPT_PARITY_PRM_PRO = 0x2;
203 const nchar_t PGM_OPT_PARITY_PRM_OND = 0x1;
204
205 typedef struct {
206         nchar_t type;
207         nchar_t len;
208         nchar_t opx;
209         nchar_t res;
210         nlong_t prm_grp;
211 } pgm_opt_parity_grp_t;
212
213 typedef struct {
214         nchar_t type;
215         nchar_t len;
216         nchar_t opx;
217         nchar_t res;
218         nlong_t prm_atgsz;
219 } pgm_opt_curr_tgsize_t;
220
221 typedef struct {
222         nchar_t type;
223         nchar_t len;
224         nchar_t opx;
225         nchar_t res;
226         nlong_t tsp;
227         nshort_t acker_afi;
228         nshort_t res2;
229         nlong_t acker;
230 } pgm_opt_pgmcc_data_t;
231
232 typedef struct {
233         nchar_t type;
234         nchar_t len;
235         nchar_t opx;
236         nchar_t res;
237         nlong_t tsp;
238         nshort_t acker_afi;
239         nshort_t loss_rate;
240         nlong_t acker;
241 } pgm_opt_pgmcc_feedback_t;
242
243 /*
244  * Udp port for UDP encapsulation
245  */
246 #define DEFAULT_UDP_ENCAP_UCAST_PORT 3055
247 #define DEFAULT_UDP_ENCAP_MCAST_PORT 3056
248
249 #endif /* _PACKET_PGM_H */