Update from Kojak to dissect ICQ login packets and text messages.
[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.2 1999/10/22 03:55:17 guy Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@unicom.net>
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 void
92 dissect_rx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
93 {
94         proto_tree      *rx_tree, *rx_tree_flags, *rx_flags, *ti;
95         struct rx_header *rxh;
96         int reply;
97
98         rxh = (struct rx_header *) &pd[offset];
99
100         /* get at least a full packet structure */
101         if ( !BYTES_ARE_IN_FRAME(offset, sizeof(struct rx_header)) )
102                 return;
103
104         if (check_col(fd, COL_PROTOCOL))
105                 col_add_str(fd, COL_PROTOCOL, "RX");
106
107
108         if (tree) {
109                 ti = proto_tree_add_item(tree, proto_rx, offset,
110                         sizeof(struct rx_header), NULL);
111                 rx_tree = proto_item_add_subtree(ti, ETT_RX);
112
113                 proto_tree_add_item(rx_tree, hf_rx_epoch,
114                         offset, 4, ntohl(rxh->epoch));
115                 proto_tree_add_item(rx_tree, hf_rx_cid,
116                         offset+4, 4, ntohl(rxh->cid));
117                 proto_tree_add_item(rx_tree, hf_rx_callnumber,
118                         offset+8, 4, ntohl(rxh->callNumber));
119                 proto_tree_add_item(rx_tree, hf_rx_seq,
120                         offset+12, 4, ntohl(rxh->seq));
121                 proto_tree_add_item(rx_tree, hf_rx_serial,
122                         offset+16, 4, ntohl(rxh->serial));
123
124                 proto_tree_add_item(rx_tree, hf_rx_type,
125                         offset+20, 1, rxh->type);
126
127                 rx_flags = proto_tree_add_item(rx_tree, hf_rx_flags,
128                         offset+21, 1, rxh->flags);
129                 rx_tree_flags = proto_item_add_subtree(rx_flags, ETT_RX_FLAGS);
130                 proto_tree_add_item(rx_tree_flags, hf_rx_flags_free_packet,
131                         offset+21, 1, rxh->flags);
132                 proto_tree_add_item(rx_tree_flags, hf_rx_flags_more_packets,
133                         offset+21, 1, rxh->flags);
134                 proto_tree_add_item(rx_tree_flags, hf_rx_flags_last_packet,
135                         offset+21, 1, rxh->flags);
136                 proto_tree_add_item(rx_tree_flags, hf_rx_flags_request_ack,
137                         offset+21, 1, rxh->flags);
138                 proto_tree_add_item(rx_tree_flags, hf_rx_flags_clientinit,
139                         offset+21, 1, rxh->flags);
140
141                 proto_tree_add_item(rx_tree, hf_rx_userstatus,
142                         offset+22, 1, rxh->userStatus);
143                 proto_tree_add_item(rx_tree, hf_rx_securityindex,
144                         offset+23, 1, rxh->securityIndex);
145                 proto_tree_add_item(rx_tree, hf_rx_spare,
146                         offset+24, 2, ntohs(rxh->spare));
147                 proto_tree_add_item(rx_tree, hf_rx_serviceid,
148                         offset+26, 2, ntohs(rxh->serviceId));
149
150                 //proto_tree_add_text(rx_tree, offset+28, END_OF_FRAME, "Data");
151         }
152
153         if (check_col(fd, COL_INFO))
154                 col_add_fstr(fd, COL_INFO,
155                         "Type: %s  "
156                         "Seq: %lu  "
157                         "Call: %lu  "
158                         "Source Port: %s  "
159                         "Destination Port: %s  ",
160                         val_to_str(rxh->type, rx_types, "%d"),
161                         (unsigned long)ntohl(rxh->seq),
162                         (unsigned long)ntohl(rxh->callNumber),
163                         get_udp_port(pi.srcport),
164                         get_udp_port(pi.destport)
165                 );
166
167         reply = (rxh->flags & RX_CLIENT_INITIATED) == 0;
168         if ( (rxh->type == RX_PACKET_TYPE_ABORT && reply) ||
169                 rxh->type == RX_PACKET_TYPE_DATA )
170         {
171                 dissect_afs(pd,offset,fd,tree);
172         }
173 }
174
175 void
176 proto_register_rx(void)
177 {
178         static hf_register_info hf[] = {
179                 { &hf_rx_epoch, {
180                         "Epoch", "rx.epoch", FT_UINT32, BASE_DEC,
181                         NULL, 0, "Epoch" }},
182                 { &hf_rx_cid, {
183                         "CID", "rx.cid", FT_UINT32, BASE_DEC,
184                         NULL, 0, "CID" }},
185                 { &hf_rx_callnumber, {
186                         "Call Number", "rx.callnumber", FT_UINT32, BASE_DEC,
187                         NULL, 0, "Call Number" }},
188                 { &hf_rx_seq, {
189                         "Sequence Number", "rx.seq", FT_UINT32, BASE_DEC,
190                         NULL, 0, "Sequence Number" }},
191                 { &hf_rx_serial, {
192                         "Serial", "rx.serial", FT_UINT32, BASE_DEC,
193                         NULL, 0, "Serial" }},
194                 { &hf_rx_type, {
195                         "Type", "rx.type", FT_UINT8, BASE_DEC,
196                         VALS(rx_types), 0, "Type" }},
197                 { &hf_rx_flags, {
198                         "Flags", "rx.flags", FT_UINT8, BASE_HEX,
199                         NULL, 0, "Flags" }},
200                 { &hf_rx_flags_clientinit, {
201                         "Client Initiated", "rx.flags.client_init", FT_UINT8, BASE_BIN,
202                         NULL, RX_CLIENT_INITIATED, "Client Initiated" }},
203                 { &hf_rx_flags_request_ack, {
204                         "Request Ack", "rx.flags.request_ack", FT_UINT8, BASE_BIN,
205                         NULL, RX_REQUEST_ACK, "Request Ack" }},
206                 { &hf_rx_flags_last_packet, {
207                         "Last Packet", "rx.flags.last_packet", FT_UINT8, BASE_BIN,
208                         NULL, RX_LAST_PACKET, "Last Packet" }},
209                 { &hf_rx_flags_more_packets, {
210                         "More Packets", "rx.flags.more_packets", FT_UINT8, BASE_BIN,
211                         NULL, RX_MORE_PACKETS, "More Packets" }},
212                 { &hf_rx_flags_free_packet, {
213                         "Free Packet", "rx.flags.free_packet", FT_UINT8, BASE_BIN,
214                         NULL, RX_FREE_PACKET, "Free Packet" }},
215                 { &hf_rx_userstatus, {
216                         "User Status", "rx.userstatus", FT_UINT32, BASE_DEC,
217                         NULL, 0, "User Status" }},
218                 { &hf_rx_securityindex, {
219                         "Security Index", "rx.securityindex", FT_UINT32, BASE_DEC,
220                         NULL, 0, "Security Index" }},
221                 { &hf_rx_spare, {
222                         "Spare/Checksum", "rx.spare", FT_UINT16, BASE_DEC,
223                         NULL, 0, "Spare/Checksum" }},
224                 { &hf_rx_serviceid, {
225                         "Service ID", "rx.serviceid", FT_UINT16, BASE_DEC,
226                         NULL, 0, "Service ID" }},
227         };
228
229         proto_rx = proto_register_protocol("RX Protocol", "rx");
230         proto_register_field_array(proto_rx, hf, array_length(hf));
231 }