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