Register the IPX dissector, make it static, and call it through a
[obnox/wireshark/wip.git] / packet-fr.c
1 /* packet-fr.c
2  * Routines for Frame Relay  dissection
3  *
4  * Copyright 2001, Paul Ionescu <paul@acorp.ro>
5  *
6  * $Id: packet-fr.c,v 1.5 2001/01/09 09:59:28 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@zing.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <ctype.h>
35
36 #include <string.h>
37 #include <glib.h>
38 #include "packet.h"
39 #include "packet-ip.h"
40 #include "packet-ipx.h"
41 #include "packet-arp.h"
42
43
44 static gint proto_fr    = -1;
45 static gint ett_fr      = -1;
46 static gint hf_fr_dlci  = -1;
47 static gint hf_fr_cr    = -1;
48 static gint hf_fr_becn  = -1;
49 static gint hf_fr_fecn  = -1;
50 static gint hf_fr_de    = -1;
51 static gint hf_fr_proto = -1;
52
53 static dissector_handle_t ip_handle;
54 static dissector_handle_t ipx_handle;
55
56 static void dissect_fr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
57 {
58   proto_item *ti;
59   proto_tree *fr_tree;
60   guint16 fr_header,fr_proto;
61   tvbuff_t   *next_tvb; 
62     
63   CHECK_DISPLAY_AS_DATA(proto_fr, tvb, pinfo, tree);
64
65   pinfo->current_proto = "Frame Relay";
66   if (check_col(pinfo->fd, COL_PROTOCOL)) 
67       col_set_str(pinfo->fd, COL_PROTOCOL, "FR");
68   if (check_col(pinfo->fd, COL_INFO)) 
69       col_clear(pinfo->fd, COL_INFO);
70
71   fr_header = tvb_get_ntohs( tvb, 0 );
72   fr_proto  = tvb_get_ntohs( tvb, 2 );
73   if (check_col(pinfo->fd, COL_INFO)) 
74       col_add_fstr(pinfo->fd, COL_INFO, "DLCI %u, proto 0x%04x",
75                    ((fr_header&0x00FF)>>4)+((fr_header&0xFC00)>>6),
76                    fr_proto);
77   
78   if (tree) {
79         
80       ti = proto_tree_add_protocol_format(tree, proto_fr, tvb, 0, 4, "Frame Relay");
81       fr_tree = proto_item_add_subtree(ti, ett_fr);
82      
83       proto_tree_add_text(fr_tree,tvb,0,2,"The real DLCI is %u",((fr_header&0x00FF)>>4)+((fr_header&0xFC00)>>6));
84       proto_tree_add_uint(fr_tree, hf_fr_dlci, tvb, 0, 2, fr_header);
85       proto_tree_add_boolean(fr_tree, hf_fr_cr,   tvb, 0, 1, fr_header);
86       proto_tree_add_boolean(fr_tree, hf_fr_fecn, tvb, 1, 1, fr_header);
87       proto_tree_add_boolean(fr_tree, hf_fr_becn, tvb, 1, 1, fr_header);
88       proto_tree_add_boolean(fr_tree, hf_fr_de,   tvb, 1, 1, fr_header);
89       proto_tree_add_uint(fr_tree, hf_fr_proto,tvb, 2, 2, fr_proto );
90   }
91
92   next_tvb =  tvb_new_subset(tvb, 4, -1, -1);
93
94   switch (fr_proto){
95 /*    case 0x0703:
96         dissect_lmi(next_tvb,pinfo,tree);
97         break;
98         this is not yet implemented
99 */
100       case 0x0800:
101         call_dissector(ip_handle,next_tvb,pinfo,tree);
102         break;
103       case 0x8137:
104         call_dissector(ipx_handle,next_tvb,pinfo,tree);
105         break;
106       default:
107         dissect_data(next_tvb,0,pinfo,tree);
108         break;                                  
109   }
110   return;
111 }
112  
113 /* Register the protocol with Ethereal */
114 void proto_register_fr(void)
115 {                 
116   static hf_register_info hf[] = {
117         { &hf_fr_dlci, { 
118            "DLCI", "fr.dlci", FT_UINT16, BASE_DEC, 
119             NULL, 0xFCF0, "Data-Link Connection Identifier" }},
120         { &hf_fr_cr, { 
121            "CR", "fr.cr", FT_BOOLEAN, 16, 
122             NULL, 0x0200, "Command/Response" }},
123         { &hf_fr_fecn, { 
124            "FECN", "fr.fecn", FT_BOOLEAN, 16, 
125             NULL, 0x0008, "Forward Explicit Congestion Notification" }},
126         { &hf_fr_becn, { 
127            "BECN", "fr.becn", FT_BOOLEAN, 16, 
128             NULL, 0x0004, "Backward Explicit Congestion Notification" }},
129         { &hf_fr_de, { 
130            "DE", "fr.de", FT_BOOLEAN, 16, 
131             NULL, 0x0002, "Discard Eligibility" }},
132         { &hf_fr_proto, { 
133            "Encapsulated Protocol", "fr.proto", FT_UINT16, BASE_HEX, 
134             NULL, 0x0, "FrameRelay Encapsulated Protocol" }},
135   };
136
137
138   /* Setup protocol subtree array */
139   static gint *ett[] = {
140     &ett_fr,
141   };
142
143   proto_fr = proto_register_protocol("Frame Relay", "FR", "fr");
144   proto_register_field_array(proto_fr, hf, array_length(hf));
145   proto_register_subtree_array(ett, array_length(ett));
146
147   register_dissector("fr", dissect_fr, proto_fr);
148 };
149
150 void proto_reg_handoff_fr(void)
151 {
152   /*
153    * Get handles for the IP and IPX dissectors.
154    */
155   ip_handle = find_dissector("ip");
156   ipx_handle = find_dissector("ipx");
157
158   dissector_add("wtap_encap", WTAP_ENCAP_FRELAY, dissect_fr, proto_fr);
159 }