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