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