add dissection of abort packets
[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.32 2002/02/01 16:37:18 nneul Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@ethereal.com>
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 <epan/packet.h>
47 #include "packet-rx.h"
48 #include <epan/resolv.h>
49
50 #define UDP_PORT_RX_LOW         7000
51 #define UDP_PORT_RX_HIGH        7009
52 #define UDP_PORT_RX_AFS_BACKUPS 7021
53
54 static const value_string rx_types[] = {
55         { RX_PACKET_TYPE_DATA,          "data" },
56         { RX_PACKET_TYPE_ACK,           "ack" },
57         { RX_PACKET_TYPE_BUSY,          "busy" },
58         { RX_PACKET_TYPE_ABORT,         "abort" },
59         { RX_PACKET_TYPE_ACKALL,        "ackall" },
60         { RX_PACKET_TYPE_CHALLENGE,     "challenge" },
61         { RX_PACKET_TYPE_RESPONSE,      "response" },
62         { RX_PACKET_TYPE_DEBUG,         "debug" },
63         { RX_PACKET_TYPE_PARAMS,        "params" },
64         { RX_PACKET_TYPE_VERSION,       "version" },
65         { 0,                            NULL },
66 };
67
68 static const value_string rx_flags[] = {
69         { RX_CLIENT_INITIATED,  "client-init" },
70         { RX_REQUEST_ACK,       "req-ack" },
71         { RX_LAST_PACKET,       "last-pckt" },
72         { RX_MORE_PACKETS,      "more-pckts" },
73         { RX_FREE_PACKET,       "free-pckt" },
74         { 0,                    NULL }
75 };
76
77 static const value_string rx_reason[] = {
78         { RX_ACK_REQUESTED,             "Ack Requested"         },
79         { RX_ACK_DUPLICATE,             "Duplicate Packet"      },
80         { RX_ACK_OUT_OF_SEQUENCE,       "Out Of Sequence"       },
81         { RX_ACK_EXEEDS_WINDOW,         "Exceeds Window"        },      
82         { RX_ACK_NOSPACE,               "No Space"              },
83         { RX_ACK_PING,                  "Ping"                  },
84         { RX_ACK_PING_RESPONSE,         "Ping Response"         },
85         { RX_ACK_DELAY,                 "Delay"                 },
86         { 0,                            NULL                    }
87 };
88
89 static const value_string rx_ack_type[] = {
90         { RX_ACK_TYPE_NACK,     "NACK"  },
91         { RX_ACK_TYPE_ACK,      "ACK"   },
92         { 0,                    NULL    }
93 };
94
95 static int proto_rx = -1;
96 static int hf_rx_epoch = -1;
97 static int hf_rx_cid = -1;
98 static int hf_rx_seq = -1;
99 static int hf_rx_serial = -1;
100 static int hf_rx_callnumber = -1;
101 static int hf_rx_type = -1;
102 static int hf_rx_flags = -1;
103 static int hf_rx_flags_clientinit = -1;
104 static int hf_rx_flags_request_ack = -1;
105 static int hf_rx_flags_last_packet = -1;
106 static int hf_rx_flags_more_packets = -1;
107 static int hf_rx_flags_free_packet = -1;
108 static int hf_rx_userstatus = -1;
109 static int hf_rx_securityindex = -1;
110 static int hf_rx_spare = -1;
111 static int hf_rx_serviceid = -1;
112 static int hf_rx_bufferspace = -1;
113 static int hf_rx_maxskew = -1;
114 static int hf_rx_first_packet = -1;
115 static int hf_rx_prev_packet = -1;
116 static int hf_rx_reason = -1;
117 static int hf_rx_numacks = -1;
118 static int hf_rx_ack_type = -1;
119 static int hf_rx_ack = -1;
120 static int hf_rx_challenge = -1;
121 static int hf_rx_version = -1;
122 static int hf_rx_nonce = -1;
123 static int hf_rx_inc_nonce = -1;
124 static int hf_rx_min_level = -1;
125 static int hf_rx_level = -1;
126 static int hf_rx_response = -1;
127 static int hf_rx_encrypted = -1;
128 static int hf_rx_kvno = -1;
129 static int hf_rx_ticket_len = -1;
130 static int hf_rx_ticket = -1;
131 static int hf_rx_ifmtu = -1;
132 static int hf_rx_maxmtu = -1;
133 static int hf_rx_rwind = -1;
134 static int hf_rx_maxpackets = -1;
135 static int hf_rx_abort = -1;
136 static int hf_rx_abortcode = -1;
137
138 static gint ett_rx = -1;
139 static gint ett_rx_flags = -1;
140 static gint ett_rx_ack = -1;
141 static gint ett_rx_challenge = -1;
142 static gint ett_rx_response = -1;
143 static gint ett_rx_encrypted = -1;
144 static gint ett_rx_abort = -1;
145
146 static dissector_handle_t afs_handle;
147
148 static int
149 dissect_rx_response_encrypted(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
150 {
151         proto_tree *tree;
152         proto_item *item;
153         int old_offset=offset;
154         int i;
155         guint32 callnumber;
156
157         item = proto_tree_add_item(parent_tree, hf_rx_encrypted, tvb, offset, -1, FALSE);
158         tree = proto_item_add_subtree(item, ett_rx_encrypted);
159
160         /* epoch : 4 bytes */
161         {
162                 nstime_t ts;
163                 ts.secs = tvb_get_ntohl(tvb, offset);
164                 ts.nsecs = 0;
165                 
166                 proto_tree_add_time(tree, hf_rx_epoch, tvb,
167                         offset, 4, &ts);
168                 offset += 4;
169         }
170
171         /* cid : 4 bytes */
172         proto_tree_add_item(tree, hf_rx_cid, tvb, offset, 4, FALSE);
173         offset += 4;
174
175         /*FIXME dont know how to handle this checksum, skipping it */
176         offset += 4;
177
178         /* sequrityindex : 1 byte */
179         proto_tree_add_item(tree, hf_rx_securityindex, tvb, offset, 1, FALSE);
180         offset += 4;
181
182         for (i=0; i<RX_MAXCALLS; i++) {
183                 /* callnumber : 4 bytes */
184                 callnumber = tvb_get_ntohl(tvb, offset);
185                 proto_tree_add_uint(tree, hf_rx_callnumber, tvb,
186                         offset, 4, callnumber);
187                 offset += 4;
188         }
189
190         /* inc nonce : 4 bytes */
191         proto_tree_add_item(tree, hf_rx_inc_nonce, tvb, offset, 4, FALSE);
192         offset += 4;
193
194         /* level : 4 bytes */
195         proto_tree_add_item(tree, hf_rx_level, tvb, offset, 4, FALSE);
196         offset += 4;
197         
198         proto_item_set_len(item, offset-old_offset);    
199         return offset;
200 }
201         
202
203 static int
204 dissect_rx_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset, guint32 seq, guint32 callnumber)
205 {
206         proto_tree *tree;
207         proto_item *item;
208         guint32 version, tl;
209         int old_offset=offset;
210
211         if (check_col(pinfo->cinfo, COL_INFO)) {
212                 col_add_fstr(pinfo->cinfo, COL_INFO,
213                         "RESPONSE  "
214                         "Seq: %lu  "
215                         "Call: %lu  "
216                         "Source Port: %s  "
217                         "Destination Port: %s  ",
218                         (unsigned long)seq,
219                         (unsigned long)callnumber,
220                         get_udp_port(pinfo->srcport),
221                         get_udp_port(pinfo->destport)
222                 );
223         }
224
225         item = proto_tree_add_item(parent_tree, hf_rx_response, tvb, offset, -1, FALSE);
226         tree = proto_item_add_subtree(item, ett_rx_response);
227
228         version = tvb_get_ntohl(tvb, offset);
229         proto_tree_add_uint(tree, hf_rx_version, tvb,
230                 offset, 4, version);
231         offset += 4;
232
233         if (version==2) {
234                 /* skip unused */
235                 offset += 4;
236
237                 /* encrypted : struct */
238                 offset = dissect_rx_response_encrypted(tvb, pinfo, tree, offset);
239
240                 /* kvno */
241                 proto_tree_add_item(tree, hf_rx_kvno, tvb, offset, 4, FALSE);
242                 offset += 4;
243                 
244                 /* ticket_len */
245                 tl = tvb_get_ntohl(tvb, offset);
246                 proto_tree_add_uint(tree, hf_rx_ticket_len, tvb,
247                         offset, 4, tl);
248                 offset += 4;
249         
250                 proto_tree_add_item(tree, hf_rx_ticket, tvb, offset, tl, FALSE);
251                 offset += tl;   
252         }
253
254         proto_item_set_len(item, offset-old_offset);    
255         return offset;
256 }
257
258 static int
259 dissect_rx_abort(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset, guint32 seq, guint32 callnumber)
260 {
261         proto_tree *tree;
262         proto_item *item;
263         int old_offset=offset;
264
265         if (check_col(pinfo->cinfo, COL_INFO)) {
266                 col_add_fstr(pinfo->cinfo, COL_INFO,
267                         "ABORT  "
268                         "Seq: %lu  "
269                         "Call: %lu  "
270                         "Source Port: %s  "
271                         "Destination Port: %s  ",
272                         (unsigned long)seq,
273                         (unsigned long)callnumber,
274                         get_udp_port(pinfo->srcport),
275                         get_udp_port(pinfo->destport)
276                 );
277         }
278
279         item = proto_tree_add_item(parent_tree, hf_rx_abort, tvb, offset, -1, FALSE);
280         tree = proto_item_add_subtree(item, ett_rx_abort);
281
282         /* kvno */
283         proto_tree_add_item(tree, hf_rx_abortcode, tvb, offset, 4, FALSE);
284         offset += 4;
285                 
286         proto_item_set_len(item, offset-old_offset);    
287         return offset;
288 }
289
290
291 static int
292 dissect_rx_challenge(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset, guint32 seq, guint32 callnumber)
293 {
294         proto_tree *tree;
295         proto_item *item;
296         guint32 version;
297         int old_offset=offset;
298
299         if (check_col(pinfo->cinfo, COL_INFO)) {
300                 col_add_fstr(pinfo->cinfo, COL_INFO,
301                         "CHALLENGE  "
302                         "Seq: %lu  "
303                         "Call: %lu  "
304                         "Source Port: %s  "
305                         "Destination Port: %s  ",
306                         (unsigned long)seq,
307                         (unsigned long)callnumber,
308                         get_udp_port(pinfo->srcport),
309                         get_udp_port(pinfo->destport)
310                 );
311         }
312
313         item = proto_tree_add_item(parent_tree, hf_rx_challenge, tvb, offset, -1, FALSE);
314         tree = proto_item_add_subtree(item, ett_rx_challenge);
315
316         version = tvb_get_ntohl(tvb, offset);
317         proto_tree_add_uint(tree, hf_rx_version, tvb,
318                 offset, 4, version);
319         offset += 4;
320
321         if (version==2) {
322                 proto_tree_add_item(tree, hf_rx_nonce, tvb, offset, 4, FALSE);
323                 offset += 4;
324
325                 proto_tree_add_item(tree, hf_rx_min_level, tvb, offset, 4, FALSE);
326                 offset += 4;
327         }
328
329         proto_item_set_len(item, offset-old_offset);    
330         return offset;
331 }
332
333 static int
334 dissect_rx_acks(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset, guint32 seq, guint32 callnumber)
335 {
336         proto_tree *tree;
337         proto_item *item;
338         guint8 num;
339         int old_offset = offset;
340
341         if (check_col(pinfo->cinfo, COL_INFO)) {
342                 col_add_fstr(pinfo->cinfo, COL_INFO,
343                         "ACK  "
344                         "Seq: %lu  "
345                         "Call: %lu  "
346                         "Source Port: %s  "
347                         "Destination Port: %s  ",
348                         (unsigned long)seq,
349                         (unsigned long)callnumber,
350                         get_udp_port(pinfo->srcport),
351                         get_udp_port(pinfo->destport)
352                 );
353         }
354
355         item = proto_tree_add_item(parent_tree, hf_rx_ack, tvb, offset, -1, FALSE);
356         tree = proto_item_add_subtree(item, ett_rx_ack);
357
358
359         /* bufferspace: 2 bytes*/
360         proto_tree_add_item(tree, hf_rx_bufferspace, tvb, offset, 2, FALSE);
361         offset += 2;
362         
363         /* maxskew: 2 bytes*/
364         proto_tree_add_item(tree, hf_rx_maxskew, tvb, offset, 2, FALSE);
365         offset += 2;
366         
367         /* first packet: 4 bytes*/
368         proto_tree_add_item(tree, hf_rx_first_packet, tvb, offset, 4, FALSE);
369         offset += 4;
370         
371         /* prev packet: 4 bytes*/
372         proto_tree_add_item(tree, hf_rx_prev_packet, tvb, offset, 4, FALSE);
373         offset += 4;
374
375         /* serial : 4 bytes */  
376         proto_tree_add_item(tree, hf_rx_serial, tvb, offset, 4, FALSE);
377         offset += 4;
378
379         /* reason : 1 byte */
380         proto_tree_add_item(tree, hf_rx_reason, tvb, offset, 1, FALSE);
381         offset += 1;
382
383         /* nACKs */
384         num = tvb_get_guint8(tvb, offset);
385         proto_tree_add_uint(tree, hf_rx_numacks, tvb, offset, 1, num);
386         offset += 1;
387
388         while(num--){
389                 proto_tree_add_item(tree, hf_rx_ack_type, tvb, offset, 1,
390                         FALSE);
391                 offset += 1;
392         }
393
394         /* Some implementations adds some extra fields.
395          * As far as I can see, these first add 3 padding bytes and then
396          * up to 4 32-bit values. (0,3,4 have been witnessed)
397          *
398          * RX as a protocol seems to be completely nondefined and seems to lack
399          * any sort of documentation other than "read the source of any of the
400          * (compatible?) implementations.
401          */
402         if (tvb_length_remaining(tvb, offset)>3) {
403                 offset += 3;    /* guess. some implementations adds 3 bytes */
404
405                 if (tvb_reported_length_remaining(tvb, offset) >= 4){
406                         proto_tree_add_item(tree, hf_rx_ifmtu, tvb, offset, 4,
407                                 FALSE);
408                         offset += 4;
409                 }
410                 if (tvb_reported_length_remaining(tvb, offset) >= 4){
411                         proto_tree_add_item(tree, hf_rx_maxmtu, tvb, offset, 4,
412                                 FALSE);
413                         offset += 4;
414                 }
415                 if (tvb_reported_length_remaining(tvb, offset) >= 4){
416                         proto_tree_add_item(tree, hf_rx_rwind, tvb, offset, 4,
417                                 FALSE);
418                         offset += 4;
419                 }
420                 if (tvb_reported_length_remaining(tvb, offset) >= 4){
421                         proto_tree_add_item(tree, hf_rx_maxpackets, tvb, offset, 4,
422                                 FALSE);
423                         offset += 4;
424                 }
425         }
426
427         proto_item_set_len(item, offset-old_offset);    
428         return offset;
429 }
430
431
432 static int
433 dissect_rx_flags(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *parent_tree, int offset)
434 {
435         proto_tree *tree;
436         proto_item *item;
437         guint8 flags;
438
439         flags = tvb_get_guint8(tvb, offset);
440         rxinfo->flags = flags;
441
442         item = proto_tree_add_uint(parent_tree, hf_rx_flags, tvb,
443                 offset, 1, flags);
444         tree = proto_item_add_subtree(item, ett_rx_flags);
445
446         proto_tree_add_uint(tree, hf_rx_flags_free_packet, tvb,
447                 offset, 1, flags);
448         proto_tree_add_uint(tree, hf_rx_flags_more_packets, tvb,
449                 offset, 1, flags);
450         proto_tree_add_uint(tree, hf_rx_flags_last_packet, tvb,
451                 offset, 1, flags);
452         proto_tree_add_uint(tree, hf_rx_flags_request_ack, tvb,
453                 offset, 1, flags);
454         proto_tree_add_uint(tree, hf_rx_flags_clientinit, tvb,
455                 offset, 1, flags);
456
457         offset += 1;
458         return offset;
459 }
460
461 static void
462 dissect_rx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
463 {
464         proto_tree *tree;
465         proto_item *item;
466         int offset = 0;
467         struct rxinfo rxinfo;
468         guint8 type;
469         guint32 seq, callnumber;
470         guint16 serviceid;
471
472         if (check_col(pinfo->cinfo, COL_PROTOCOL))
473                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RX");
474         if (check_col(pinfo->cinfo, COL_INFO))
475                 col_clear(pinfo->cinfo, COL_INFO);
476
477         item = proto_tree_add_protocol_format(parent_tree, proto_rx, tvb, 
478                 offset, 28, "RX Protocol");
479         tree = proto_item_add_subtree(item, ett_rx);
480
481         /* epoch : 4 bytes */
482         {
483                 nstime_t ts;;
484                 ts.secs = tvb_get_ntohl(tvb, offset);
485                 ts.nsecs = 0;
486                 
487                 proto_tree_add_time(tree, hf_rx_epoch, tvb,
488                         offset, 4, &ts);
489                 offset += 4;
490         }
491
492         /* cid : 4 bytes */
493         proto_tree_add_item(tree, hf_rx_cid, tvb, offset, 4, FALSE);
494         offset += 4;
495
496         /* callnumber : 4 bytes */
497         callnumber = tvb_get_ntohl(tvb, offset);
498         proto_tree_add_uint(tree, hf_rx_callnumber, tvb,
499                 offset, 4, callnumber);
500         offset += 4;
501         rxinfo.callnumber = callnumber;
502
503         /* seq : 4 bytes */
504         seq = tvb_get_ntohl(tvb, offset);
505         proto_tree_add_uint(tree, hf_rx_seq, tvb,
506                 offset, 4, seq);
507         offset += 4;
508         rxinfo.seq = seq;
509
510         /* serial : 4 bytes */
511         proto_tree_add_item(tree, hf_rx_serial, tvb, offset, 4, FALSE);
512         offset += 4;
513
514         /* type : 1 byte */
515         type = tvb_get_guint8(tvb, offset);
516         proto_tree_add_uint(tree, hf_rx_type, tvb,
517                 offset, 1, type);
518         offset += 1;
519         rxinfo.type = type;
520
521         /* flags : 1 byte */
522         offset = dissect_rx_flags(tvb, &rxinfo, tree, offset);
523
524         /* userstatus : 1 byte */
525         proto_tree_add_item(tree, hf_rx_userstatus, tvb, offset, 1, FALSE);
526         offset += 1;
527
528         /* sequrityindex : 1 byte */
529         proto_tree_add_item(tree, hf_rx_securityindex, tvb, offset, 1, FALSE);
530         offset += 1;
531
532         /*
533          * How clever: even though the AFS header files indicate that the
534          * serviceId is first, it's really encoded _after_ the spare field.
535          * I wasted a day figuring that out!
536          */
537
538         /* spare */
539         proto_tree_add_item(tree, hf_rx_spare, tvb, offset, 2, FALSE);
540         offset += 2;
541
542         /* service id : 2 bytes */
543         serviceid = tvb_get_ntohs(tvb, offset);
544         proto_tree_add_uint(tree, hf_rx_serviceid, tvb,
545                 offset, 2, serviceid);
546         offset += 2;
547         rxinfo.serviceid = serviceid;
548
549         switch (type) {
550         case RX_PACKET_TYPE_ACK:
551                 /*dissect_rx_acks(tvb, pinfo, parent_tree, offset, 
552                         cant create it in a parallell tree, then ett seasrch
553                         wont work */
554                 dissect_rx_acks(tvb, pinfo, tree, offset, 
555                         seq, callnumber);
556                 break;
557         case RX_PACKET_TYPE_ACKALL:
558                 /* does not contain any payload */
559                 if (check_col(pinfo->cinfo, COL_INFO)) {
560                         col_add_fstr(pinfo->cinfo, COL_INFO,
561                                 "ACKALL  "
562                                 "Seq: %lu  "
563                                 "Call: %lu  "
564                                 "Source Port: %s  "
565                                 "Destination Port: %s  ",
566                                 (unsigned long)seq,
567                                 (unsigned long)callnumber,
568                                 get_udp_port(pinfo->srcport),
569                                 get_udp_port(pinfo->destport)
570                         );
571                 }
572                 break;
573         case RX_PACKET_TYPE_CHALLENGE:
574                 dissect_rx_challenge(tvb, pinfo, tree, offset, seq, callnumber);
575                 break;
576         case RX_PACKET_TYPE_RESPONSE:
577                 dissect_rx_response(tvb, pinfo, tree, offset, seq, callnumber);
578                 break;
579         case RX_PACKET_TYPE_DATA: {
580                 tvbuff_t *next_tvb;
581                 pinfo->private_data = &rxinfo;
582                 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
583                 call_dissector(afs_handle, next_tvb, pinfo, parent_tree);
584                 };
585                 break;
586         case RX_PACKET_TYPE_ABORT:
587                 dissect_rx_abort(tvb, pinfo, tree, offset, seq, callnumber);
588                 break;
589         }
590
591 }
592
593 void
594 proto_register_rx(void)
595 {
596         static hf_register_info hf[] = {
597                 { &hf_rx_epoch, {
598                         "Epoch", "rx.epoch", FT_ABSOLUTE_TIME, BASE_DEC,
599                         NULL, 0, "Epoch", HFILL }},
600
601                 { &hf_rx_cid, {
602                         "CID", "rx.cid", FT_UINT32, BASE_DEC,
603                         NULL, 0, "CID", HFILL }},
604
605                 { &hf_rx_callnumber, {
606                         "Call Number", "rx.callnumber", FT_UINT32, BASE_DEC,
607                         NULL, 0, "Call Number", HFILL }},
608
609                 { &hf_rx_seq, {
610                         "Sequence Number", "rx.seq", FT_UINT32, BASE_DEC,
611                         NULL, 0, "Sequence Number", HFILL }},
612
613                 { &hf_rx_serial, {
614                         "Serial", "rx.serial", FT_UINT32, BASE_DEC,
615                         NULL, 0, "Serial", HFILL }},
616
617                 { &hf_rx_type, {
618                         "Type", "rx.type", FT_UINT8, BASE_DEC,
619                         VALS(rx_types), 0, "Type", HFILL }},
620
621                 { &hf_rx_flags, {
622                         "Flags", "rx.flags", FT_UINT8, BASE_HEX,
623                         NULL, 0, "Flags", HFILL }},
624
625                 { &hf_rx_flags_clientinit, {
626                         "Client Initiated", "rx.flags.client_init", FT_UINT8, BASE_BIN,
627                         NULL, RX_CLIENT_INITIATED, "Client Initiated", HFILL }},
628
629                 { &hf_rx_flags_request_ack, {
630                         "Request Ack", "rx.flags.request_ack", FT_UINT8, BASE_BIN,
631                         NULL, RX_REQUEST_ACK, "Request Ack", HFILL }},
632
633                 { &hf_rx_flags_last_packet, {
634                         "Last Packet", "rx.flags.last_packet", FT_UINT8, BASE_BIN,
635                         NULL, RX_LAST_PACKET, "Last Packet", HFILL }},
636
637                 { &hf_rx_flags_more_packets, {
638                         "More Packets", "rx.flags.more_packets", FT_UINT8, BASE_BIN,
639                         NULL, RX_MORE_PACKETS, "More Packets", HFILL }},
640
641                 { &hf_rx_flags_free_packet, {
642                         "Free Packet", "rx.flags.free_packet", FT_UINT8, BASE_BIN,
643                         NULL, RX_FREE_PACKET, "Free Packet", HFILL }},
644
645                 { &hf_rx_userstatus, {
646                         "User Status", "rx.userstatus", FT_UINT32, BASE_DEC,
647                         NULL, 0, "User Status", HFILL }},
648
649                 { &hf_rx_securityindex, {
650                         "Security Index", "rx.securityindex", FT_UINT32, BASE_DEC,
651                         NULL, 0, "Security Index", HFILL }},
652
653                 { &hf_rx_spare, {
654                         "Spare/Checksum", "rx.spare", FT_UINT16, BASE_DEC,
655                         NULL, 0, "Spare/Checksum", HFILL }},
656
657                 { &hf_rx_serviceid, {
658                         "Service ID", "rx.serviceid", FT_UINT16, BASE_DEC,
659                         NULL, 0, "Service ID", HFILL }},
660
661                 { &hf_rx_bufferspace, {
662                         "Bufferspace", "rx.bufferspace", FT_UINT16, BASE_DEC,
663                         NULL, 0, "Number Of Packets Available", HFILL }},
664
665                 { &hf_rx_maxskew, {
666                         "Max Skew", "rx.maxskew", FT_UINT16, BASE_DEC,
667                         NULL, 0, "Max Skew", HFILL }},
668
669                 { &hf_rx_first_packet, {
670                         "First Packet", "rx.first", FT_UINT32, BASE_DEC,
671                         NULL, 0, "First Packet", HFILL }},
672
673                 { &hf_rx_prev_packet, {
674                         "Prev Packet", "rx.prev", FT_UINT32, BASE_DEC,
675                         NULL, 0, "Previous Packet", HFILL }},
676
677                 { &hf_rx_reason, {
678                         "Reason", "rx.reason", FT_UINT8, BASE_DEC,
679                         VALS(rx_reason), 0, "Reason For This ACK", HFILL }},
680
681                 { &hf_rx_numacks, {
682                         "Num ACKs", "rx.num_acks", FT_UINT8, BASE_DEC,
683                         NULL, 0, "Number Of ACKs", HFILL }},
684
685                 { &hf_rx_ack_type, {
686                         "ACK Type", "rx.ack_type", FT_UINT8, BASE_DEC,
687                         VALS(rx_ack_type), 0, "Type Of ACKs", HFILL }},
688
689                 { &hf_rx_ack, {
690                         "ACK Packet", "rx.ack", FT_NONE, BASE_NONE,
691                         NULL, 0, "ACK Packet", HFILL }},
692
693                 { &hf_rx_challenge, {
694                         "CHALLENGE Packet", "rx.challenge", FT_NONE, BASE_NONE,
695                         NULL, 0, "CHALLENGE Packet", HFILL }},
696
697                 { &hf_rx_version, {
698                         "Version", "rx.version", FT_UINT32, BASE_DEC,
699                         NULL, 0, "Version Of Challenge/Response", HFILL }},
700
701                 { &hf_rx_nonce, {
702                         "Nonce", "rx.nonce", FT_UINT32, BASE_HEX,
703                         NULL, 0, "Nonce", HFILL }},
704
705                 { &hf_rx_inc_nonce, {
706                         "Inc Nonce", "rx.inc_nonce", FT_UINT32, BASE_HEX,
707                         NULL, 0, "Incremented Nonce", HFILL }},
708
709                 { &hf_rx_min_level, {
710                         "Min Level", "rx.min_level", FT_UINT32, BASE_DEC,
711                         NULL, 0, "Min Level", HFILL }},
712
713                 { &hf_rx_level, {
714                         "Level", "rx.level", FT_UINT32, BASE_DEC,
715                         NULL, 0, "Level", HFILL }},
716
717                 { &hf_rx_response, {
718                         "RESPONSE Packet", "rx.response", FT_NONE, BASE_NONE,
719                         NULL, 0, "RESPONSE Packet", HFILL }},
720
721                 { &hf_rx_abort, {
722                         "ABORT Packet", "rx.abort", FT_NONE, BASE_NONE,
723                         NULL, 0, "ABORT Packet", HFILL }},
724
725                 { &hf_rx_encrypted, {
726                         "Encrypted", "rx.encrypted", FT_NONE, BASE_NONE,
727                         NULL, 0, "Encrypted part of response packet", HFILL }},
728
729                 { &hf_rx_kvno, {
730                         "kvno", "rx.kvno", FT_UINT32, BASE_DEC,
731                         NULL, 0, "kvno", HFILL }},
732
733                 { &hf_rx_ticket_len, {
734                         "Ticket len", "rx.ticket_len", FT_UINT32, BASE_DEC,
735                         NULL, 0, "Ticket Length", HFILL }},
736
737                 { &hf_rx_ticket, {
738                         "ticket", "rx.ticket", FT_BYTES, BASE_HEX,
739                         NULL, 0, "Ticket", HFILL }},
740
741                 { &hf_rx_ifmtu, {
742                         "Interface MTU", "rx.if_mtu", FT_UINT32, BASE_DEC,
743                         NULL, 0, "Interface MTU", HFILL }},
744
745                 { &hf_rx_maxmtu, {
746                         "Max MTU", "rx.max_mtu", FT_UINT32, BASE_DEC,
747                         NULL, 0, "Max MTU", HFILL }},
748
749                 { &hf_rx_rwind, {
750                         "rwind", "rx.rwind", FT_UINT32, BASE_DEC,
751                         NULL, 0, "rwind", HFILL }},
752
753                 { &hf_rx_maxpackets, {
754                         "Max Packets", "rx.max_packets", FT_UINT32, BASE_DEC,
755                         NULL, 0, "Max Packets", HFILL }},
756
757                 { &hf_rx_abortcode, {
758                         "Abort Code", "rx.abort_code", FT_UINT32, BASE_DEC,
759                         NULL, 0, "Abort Code", HFILL }},
760
761         };
762         static gint *ett[] = {
763                 &ett_rx,
764                 &ett_rx_flags,
765                 &ett_rx_ack,
766                 &ett_rx_challenge,
767                 &ett_rx_response,
768                 &ett_rx_encrypted,
769                 &ett_rx_abort
770         };
771
772         proto_rx = proto_register_protocol("RX Protocol", "RX", "rx");
773         proto_register_field_array(proto_rx, hf, array_length(hf));
774         proto_register_subtree_array(ett, array_length(ett));
775 }
776
777 void
778 proto_reg_handoff_rx(void)
779 {
780         dissector_handle_t rx_handle;
781
782         int port;
783
784         /*
785          * Get handle for the AFS dissector.
786          */
787         afs_handle = find_dissector("afs");
788
789         /* Ports in the range UDP_PORT_RX_LOW to UDP_PORT_RX_HIGH
790            are all used for various AFS services. */
791         rx_handle = create_dissector_handle(dissect_rx, proto_rx);
792         for (port = UDP_PORT_RX_LOW; port <= UDP_PORT_RX_HIGH; port++)
793                 dissector_add("udp.port", port, rx_handle);
794         dissector_add("udp.port", UDP_PORT_RX_AFS_BACKUPS, rx_handle);
795 }