Fix #ifndef line whose symbol had been omitted.
[obnox/wireshark/wip.git] / packet-rx.c
1 /* packet-rx.c
2  * Routines for RX packet dissection
3  * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
4  * Based on routines from tcpdump patches by
5  *   Ken Hornstein <kenh@cmf.nrl.navy.mil>
6  *
7  * $Id: packet-rx.c,v 1.7 2000/01/14 19:11:26 guy Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@zing.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * Copied from packet-tftp.c
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <stdio.h>
35
36 #ifdef HAVE_SYS_TYPES_H
37 # include <sys/types.h>
38 #endif
39
40 #ifdef HAVE_NETINET_IN_H
41 # include <netinet/in.h>
42 #endif
43
44 #include <string.h>
45 #include <glib.h>
46 #include "packet.h"
47 #include "packet-rx.h"
48 #include "resolv.h"
49
50 static const value_string rx_types[] = {
51         { RX_PACKET_TYPE_DATA,          "data" },
52         { RX_PACKET_TYPE_ACK,           "ack" },
53         { RX_PACKET_TYPE_BUSY,          "busy" },
54         { RX_PACKET_TYPE_ABORT,         "abort" },
55         { RX_PACKET_TYPE_ACKALL,        "ackall" },
56         { RX_PACKET_TYPE_CHALLENGE,     "challenge" },
57         { RX_PACKET_TYPE_RESPONSE,      "response" },
58         { RX_PACKET_TYPE_DEBUG,         "debug" },
59         { RX_PACKET_TYPE_PARAMS,        "params" },
60         { RX_PACKET_TYPE_VERSION,       "version" },
61         { 0,                            NULL },
62 };
63
64 static const value_string rx_flags[] = {
65         { RX_CLIENT_INITIATED,  "client-init" },
66         { RX_REQUEST_ACK,       "req-ack" },
67         { RX_LAST_PACKET,       "last-pckt" },
68         { RX_MORE_PACKETS,      "more-pckts" },
69         { RX_FREE_PACKET,       "free-pckt" }
70 };
71
72 static int proto_rx = -1;
73
74 static int hf_rx_epoch = -1;
75 static int hf_rx_cid = -1;
76 static int hf_rx_seq = -1;
77 static int hf_rx_serial = -1;
78 static int hf_rx_callnumber = -1;
79 static int hf_rx_type = -1;
80 static int hf_rx_flags = -1;
81 static int hf_rx_flags_clientinit = -1;
82 static int hf_rx_flags_request_ack = -1;
83 static int hf_rx_flags_last_packet = -1;
84 static int hf_rx_flags_more_packets = -1;
85 static int hf_rx_flags_free_packet = -1;
86 static int hf_rx_userstatus = -1;
87 static int hf_rx_securityindex = -1;
88 static int hf_rx_spare = -1;
89 static int hf_rx_serviceid = -1;
90
91 static gint ett_rx = -1;
92 static gint ett_rx_flags = -1;
93
94 void
95 dissect_rx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
96 {
97         proto_tree      *rx_tree, *rx_tree_flags, *rx_flags, *ti;
98         struct rx_header *rxh;
99         int reply;
100
101         rxh = (struct rx_header *) &pd[offset];
102
103         /* get at least a full packet structure */
104         if ( !BYTES_ARE_IN_FRAME(offset, sizeof(struct rx_header)) )
105                 return;
106
107         if (check_col(fd, COL_PROTOCOL))
108                 col_add_str(fd, COL_PROTOCOL, "RX");
109
110
111         if (tree) {
112                 ti = proto_tree_add_item_format(tree, proto_rx, offset,
113                         sizeof(struct rx_header), NULL, "RX Protocol (%s)", 
114                         val_to_str(rxh->type,rx_types,"unknown (%d)"));
115                 rx_tree = proto_item_add_subtree(ti, ett_rx);
116
117                 proto_tree_add_item(rx_tree, hf_rx_epoch,
118                         offset, 4, pntohl(&rxh->epoch));
119                 proto_tree_add_item(rx_tree, hf_rx_cid,
120                         offset+4, 4, pntohl(&rxh->cid));
121                 proto_tree_add_item(rx_tree, hf_rx_callnumber,
122                         offset+8, 4, pntohl(&rxh->callNumber));
123                 proto_tree_add_item(rx_tree, hf_rx_seq,
124                         offset+12, 4, pntohl(&rxh->seq));
125                 proto_tree_add_item(rx_tree, hf_rx_serial,
126                         offset+16, 4, pntohl(&rxh->serial));
127
128                 proto_tree_add_item(rx_tree, hf_rx_type,
129                         offset+20, 1, rxh->type);
130
131                 rx_flags = proto_tree_add_item(rx_tree, hf_rx_flags,
132                         offset+21, 1, rxh->flags);
133                 rx_tree_flags = proto_item_add_subtree(rx_flags, ett_rx_flags);
134                 proto_tree_add_item(rx_tree_flags, hf_rx_flags_free_packet,
135                         offset+21, 1, rxh->flags);
136                 proto_tree_add_item(rx_tree_flags, hf_rx_flags_more_packets,
137                         offset+21, 1, rxh->flags);
138                 proto_tree_add_item(rx_tree_flags, hf_rx_flags_last_packet,
139                         offset+21, 1, rxh->flags);
140                 proto_tree_add_item(rx_tree_flags, hf_rx_flags_request_ack,
141                         offset+21, 1, rxh->flags);
142                 proto_tree_add_item(rx_tree_flags, hf_rx_flags_clientinit,
143                         offset+21, 1, rxh->flags);
144
145                 proto_tree_add_item(rx_tree, hf_rx_userstatus,
146                         offset+22, 1, rxh->userStatus);
147                 proto_tree_add_item(rx_tree, hf_rx_securityindex,
148                         offset+23, 1, rxh->securityIndex);
149                 proto_tree_add_item(rx_tree, hf_rx_spare,
150                         offset+24, 2, pntohs(&rxh->spare));
151                 proto_tree_add_item(rx_tree, hf_rx_serviceid,
152                         offset+26, 2, pntohs(&rxh->serviceId));
153         }
154
155         if (check_col(fd, COL_INFO))
156                 col_add_fstr(fd, COL_INFO,
157                         "Type: %s  "
158                         "Seq: %lu  "
159                         "Call: %lu  "
160                         "Source Port: %s  "
161                         "Destination Port: %s  ",
162                         val_to_str(rxh->type, rx_types, "%d"),
163                         (unsigned long)pntohl(&rxh->seq),
164                         (unsigned long)pntohl(&rxh->callNumber),
165                         get_udp_port(pi.srcport),
166                         get_udp_port(pi.destport)
167                 );
168
169         reply = (rxh->flags & RX_CLIENT_INITIATED) == 0;
170         if ( (rxh->type == RX_PACKET_TYPE_ABORT && reply) ||
171                 rxh->type == RX_PACKET_TYPE_DATA )
172         {
173                 dissect_afs(pd,offset,fd,tree);
174         }
175 }
176
177 void
178 proto_register_rx(void)
179 {
180         static hf_register_info hf[] = {
181                 { &hf_rx_epoch, {
182                         "Epoch", "rx.epoch", FT_UINT32, BASE_DEC,
183                         NULL, 0, "Epoch" }},
184                 { &hf_rx_cid, {
185                         "CID", "rx.cid", FT_UINT32, BASE_DEC,
186                         NULL, 0, "CID" }},
187                 { &hf_rx_callnumber, {
188                         "Call Number", "rx.callnumber", FT_UINT32, BASE_DEC,
189                         NULL, 0, "Call Number" }},
190                 { &hf_rx_seq, {
191                         "Sequence Number", "rx.seq", FT_UINT32, BASE_DEC,
192                         NULL, 0, "Sequence Number" }},
193                 { &hf_rx_serial, {
194                         "Serial", "rx.serial", FT_UINT32, BASE_DEC,
195                         NULL, 0, "Serial" }},
196                 { &hf_rx_type, {
197                         "Type", "rx.type", FT_UINT8, BASE_DEC,
198                         VALS(rx_types), 0, "Type" }},
199                 { &hf_rx_flags, {
200                         "Flags", "rx.flags", FT_UINT8, BASE_HEX,
201                         NULL, 0, "Flags" }},
202                 { &hf_rx_flags_clientinit, {
203                         "Client Initiated", "rx.flags.client_init", FT_UINT8, BASE_BIN,
204                         NULL, RX_CLIENT_INITIATED, "Client Initiated" }},
205                 { &hf_rx_flags_request_ack, {
206                         "Request Ack", "rx.flags.request_ack", FT_UINT8, BASE_BIN,
207                         NULL, RX_REQUEST_ACK, "Request Ack" }},
208                 { &hf_rx_flags_last_packet, {
209                         "Last Packet", "rx.flags.last_packet", FT_UINT8, BASE_BIN,
210                         NULL, RX_LAST_PACKET, "Last Packet" }},
211                 { &hf_rx_flags_more_packets, {
212                         "More Packets", "rx.flags.more_packets", FT_UINT8, BASE_BIN,
213                         NULL, RX_MORE_PACKETS, "More Packets" }},
214                 { &hf_rx_flags_free_packet, {
215                         "Free Packet", "rx.flags.free_packet", FT_UINT8, BASE_BIN,
216                         NULL, RX_FREE_PACKET, "Free Packet" }},
217                 { &hf_rx_userstatus, {
218                         "User Status", "rx.userstatus", FT_UINT32, BASE_DEC,
219                         NULL, 0, "User Status" }},
220                 { &hf_rx_securityindex, {
221                         "Security Index", "rx.securityindex", FT_UINT32, BASE_DEC,
222                         NULL, 0, "Security Index" }},
223                 { &hf_rx_spare, {
224                         "Spare/Checksum", "rx.spare", FT_UINT16, BASE_DEC,
225                         NULL, 0, "Spare/Checksum" }},
226                 { &hf_rx_serviceid, {
227                         "Service ID", "rx.serviceid", FT_UINT16, BASE_DEC,
228                         NULL, 0, "Service ID" }},
229         };
230         static gint *ett[] = {
231                 &ett_rx,
232                 &ett_rx_flags,
233         };
234
235         proto_rx = proto_register_protocol("RX Protocol", "rx");
236         proto_register_field_array(proto_rx, hf, array_length(hf));
237         proto_register_subtree_array(ett, array_length(ett));
238 }