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>
7 * $Id: packet-rx.c,v 1.12 2000/05/31 05:07:38 guy Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@zing.org>
11 * Copyright 1998 Gerald Combs
13 * Copied from packet-tftp.c
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.
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.
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.
36 #ifdef HAVE_SYS_TYPES_H
37 # include <sys/types.h>
40 #ifdef HAVE_NETINET_IN_H
41 # include <netinet/in.h>
47 #include "packet-rx.h"
48 #include "packet-afs.h"
51 #define UDP_PORT_RX_LOW 7000
52 #define UDP_PORT_RX_HIGH 7009
53 #define UDP_PORT_RX_AFS_BACKUPS 7021
55 static const value_string rx_types[] = {
56 { RX_PACKET_TYPE_DATA, "data" },
57 { RX_PACKET_TYPE_ACK, "ack" },
58 { RX_PACKET_TYPE_BUSY, "busy" },
59 { RX_PACKET_TYPE_ABORT, "abort" },
60 { RX_PACKET_TYPE_ACKALL, "ackall" },
61 { RX_PACKET_TYPE_CHALLENGE, "challenge" },
62 { RX_PACKET_TYPE_RESPONSE, "response" },
63 { RX_PACKET_TYPE_DEBUG, "debug" },
64 { RX_PACKET_TYPE_PARAMS, "params" },
65 { RX_PACKET_TYPE_VERSION, "version" },
69 static const value_string rx_flags[] = {
70 { RX_CLIENT_INITIATED, "client-init" },
71 { RX_REQUEST_ACK, "req-ack" },
72 { RX_LAST_PACKET, "last-pckt" },
73 { RX_MORE_PACKETS, "more-pckts" },
74 { RX_FREE_PACKET, "free-pckt" }
77 static int proto_rx = -1;
79 static int hf_rx_epoch = -1;
80 static int hf_rx_cid = -1;
81 static int hf_rx_seq = -1;
82 static int hf_rx_serial = -1;
83 static int hf_rx_callnumber = -1;
84 static int hf_rx_type = -1;
85 static int hf_rx_flags = -1;
86 static int hf_rx_flags_clientinit = -1;
87 static int hf_rx_flags_request_ack = -1;
88 static int hf_rx_flags_last_packet = -1;
89 static int hf_rx_flags_more_packets = -1;
90 static int hf_rx_flags_free_packet = -1;
91 static int hf_rx_userstatus = -1;
92 static int hf_rx_securityindex = -1;
93 static int hf_rx_spare = -1;
94 static int hf_rx_serviceid = -1;
96 static gint ett_rx = -1;
97 static gint ett_rx_flags = -1;
100 dissect_rx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
102 proto_tree *rx_tree, *rx_tree_flags, *rx_flags, *ti;
103 struct rx_header *rxh;
106 rxh = (struct rx_header *) &pd[offset];
108 /* get at least a full packet structure */
109 if ( !BYTES_ARE_IN_FRAME(offset, sizeof(struct rx_header)) )
112 if (check_col(fd, COL_PROTOCOL))
113 col_add_str(fd, COL_PROTOCOL, "RX");
117 ti = proto_tree_add_protocol_format(tree, proto_rx, NullTVB, offset,
118 sizeof(struct rx_header), "RX Protocol (%s)",
119 val_to_str(rxh->type,rx_types,"unknown (%d)"));
120 rx_tree = proto_item_add_subtree(ti, ett_rx);
122 proto_tree_add_uint(rx_tree, hf_rx_epoch, NullTVB,
123 offset, 4, pntohl(&rxh->epoch));
124 proto_tree_add_uint(rx_tree, hf_rx_cid, NullTVB,
125 offset+4, 4, pntohl(&rxh->cid));
126 proto_tree_add_uint(rx_tree, hf_rx_callnumber, NullTVB,
127 offset+8, 4, pntohl(&rxh->callNumber));
128 proto_tree_add_uint(rx_tree, hf_rx_seq, NullTVB,
129 offset+12, 4, pntohl(&rxh->seq));
130 proto_tree_add_uint(rx_tree, hf_rx_serial, NullTVB,
131 offset+16, 4, pntohl(&rxh->serial));
133 proto_tree_add_uint(rx_tree, hf_rx_type, NullTVB,
134 offset+20, 1, rxh->type);
136 rx_flags = proto_tree_add_uint(rx_tree, hf_rx_flags, NullTVB,
137 offset+21, 1, rxh->flags);
138 rx_tree_flags = proto_item_add_subtree(rx_flags, ett_rx_flags);
139 proto_tree_add_uint(rx_tree_flags, hf_rx_flags_free_packet, NullTVB,
140 offset+21, 1, rxh->flags);
141 proto_tree_add_uint(rx_tree_flags, hf_rx_flags_more_packets, NullTVB,
142 offset+21, 1, rxh->flags);
143 proto_tree_add_uint(rx_tree_flags, hf_rx_flags_last_packet, NullTVB,
144 offset+21, 1, rxh->flags);
145 proto_tree_add_uint(rx_tree_flags, hf_rx_flags_request_ack, NullTVB,
146 offset+21, 1, rxh->flags);
147 proto_tree_add_uint(rx_tree_flags, hf_rx_flags_clientinit, NullTVB,
148 offset+21, 1, rxh->flags);
150 proto_tree_add_uint(rx_tree, hf_rx_userstatus, NullTVB,
151 offset+22, 1, rxh->userStatus);
152 proto_tree_add_uint(rx_tree, hf_rx_securityindex, NullTVB,
153 offset+23, 1, rxh->securityIndex);
154 proto_tree_add_uint(rx_tree, hf_rx_spare, NullTVB,
155 offset+24, 2, pntohs(&rxh->spare));
156 proto_tree_add_uint(rx_tree, hf_rx_serviceid, NullTVB,
157 offset+26, 2, pntohs(&rxh->serviceId));
160 if (check_col(fd, COL_INFO))
161 col_add_fstr(fd, COL_INFO,
166 "Destination Port: %s ",
167 val_to_str(rxh->type, rx_types, "%d"),
168 (unsigned long)pntohl(&rxh->seq),
169 (unsigned long)pntohl(&rxh->callNumber),
170 get_udp_port(pi.srcport),
171 get_udp_port(pi.destport)
174 reply = (rxh->flags & RX_CLIENT_INITIATED) == 0;
175 if ( (rxh->type == RX_PACKET_TYPE_ABORT && reply) ||
176 rxh->type == RX_PACKET_TYPE_DATA )
178 dissect_afs(pd,offset,fd,tree);
183 proto_register_rx(void)
185 static hf_register_info hf[] = {
187 "Epoch", "rx.epoch", FT_UINT32, BASE_DEC,
190 "CID", "rx.cid", FT_UINT32, BASE_DEC,
192 { &hf_rx_callnumber, {
193 "Call Number", "rx.callnumber", FT_UINT32, BASE_DEC,
194 NULL, 0, "Call Number" }},
196 "Sequence Number", "rx.seq", FT_UINT32, BASE_DEC,
197 NULL, 0, "Sequence Number" }},
199 "Serial", "rx.serial", FT_UINT32, BASE_DEC,
200 NULL, 0, "Serial" }},
202 "Type", "rx.type", FT_UINT8, BASE_DEC,
203 VALS(rx_types), 0, "Type" }},
205 "Flags", "rx.flags", FT_UINT8, BASE_HEX,
207 { &hf_rx_flags_clientinit, {
208 "Client Initiated", "rx.flags.client_init", FT_UINT8, BASE_BIN,
209 NULL, RX_CLIENT_INITIATED, "Client Initiated" }},
210 { &hf_rx_flags_request_ack, {
211 "Request Ack", "rx.flags.request_ack", FT_UINT8, BASE_BIN,
212 NULL, RX_REQUEST_ACK, "Request Ack" }},
213 { &hf_rx_flags_last_packet, {
214 "Last Packet", "rx.flags.last_packet", FT_UINT8, BASE_BIN,
215 NULL, RX_LAST_PACKET, "Last Packet" }},
216 { &hf_rx_flags_more_packets, {
217 "More Packets", "rx.flags.more_packets", FT_UINT8, BASE_BIN,
218 NULL, RX_MORE_PACKETS, "More Packets" }},
219 { &hf_rx_flags_free_packet, {
220 "Free Packet", "rx.flags.free_packet", FT_UINT8, BASE_BIN,
221 NULL, RX_FREE_PACKET, "Free Packet" }},
222 { &hf_rx_userstatus, {
223 "User Status", "rx.userstatus", FT_UINT32, BASE_DEC,
224 NULL, 0, "User Status" }},
225 { &hf_rx_securityindex, {
226 "Security Index", "rx.securityindex", FT_UINT32, BASE_DEC,
227 NULL, 0, "Security Index" }},
229 "Spare/Checksum", "rx.spare", FT_UINT16, BASE_DEC,
230 NULL, 0, "Spare/Checksum" }},
231 { &hf_rx_serviceid, {
232 "Service ID", "rx.serviceid", FT_UINT16, BASE_DEC,
233 NULL, 0, "Service ID" }},
235 static gint *ett[] = {
240 proto_rx = proto_register_protocol("RX Protocol", "rx");
241 proto_register_field_array(proto_rx, hf, array_length(hf));
242 proto_register_subtree_array(ett, array_length(ett));
246 proto_reg_handoff_rx(void)
250 /* Ports in the range UDP_PORT_RX_LOW to UDP_PORT_RX_HIGH
251 are all used for various AFS services. */
252 for (port = UDP_PORT_RX_LOW; port <= UDP_PORT_RX_HIGH; port++)
253 dissector_add("udp.port", port, dissect_rx);
254 dissector_add("udp.port", UDP_PORT_RX_AFS_BACKUPS, dissect_rx);