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