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