Move 3 ASN1 dissectors to 'clean' group; move 1 PIDL dissector to 'dirty' group.
[metze/wireshark/wip.git] / epan / dissectors / packet-cosine.c
1 /* packet-cosine.c
2  * Routines for decoding CoSine IPNOS L2 debug output
3  *
4  * $Id$
5  *
6  * Motonori Shindo <motonori@shin.do>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 /*
27  * XXX TODO:
28  *    o PPoATM and PPoFR encapsulation needs more test.
29  *
30  */
31
32 #include "config.h"
33
34 #include <glib.h>
35 #include <epan/packet.h>
36
37 static int proto_cosine = -1;
38 static int hf_pro = -1;
39 static int hf_off = -1;
40 static int hf_pri = -1;
41 static int hf_rm = -1;
42 static int hf_err = -1;
43
44 static gint ett_raw = -1;
45
46 static dissector_handle_t eth_withoutfcs_handle;
47 static dissector_handle_t ppp_hdlc_handle;
48 static dissector_handle_t llc_handle;
49 static dissector_handle_t chdlc_handle;
50 static dissector_handle_t fr_handle;
51 static dissector_handle_t data_handle;
52
53 static void
54 dissect_cosine(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
55 {
56   proto_tree               *fh_tree;
57   proto_item               *ti;
58   union wtap_pseudo_header *pseudo_header = pinfo->pseudo_header;
59
60   /* load the top pane info. This should be overwritten by
61      the next protocol in the stack */
62   col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A");
63   col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A");
64   col_set_str(pinfo->cinfo, COL_PROTOCOL, "N/A");
65   col_set_str(pinfo->cinfo, COL_INFO, "CoSine IPNOS L2 debug output");
66
67   /* populate a tree in the second pane with the status of the link
68      layer (ie none) */
69   if(tree) {
70     ti = proto_tree_add_protocol_format(tree, proto_cosine, tvb, 0, 0,
71                                         "CoSine IPNOS L2 debug output (%s)",
72                                         pseudo_header->cosine.if_name);
73     fh_tree = proto_item_add_subtree(ti, ett_raw);
74     proto_tree_add_uint(fh_tree, hf_pro, tvb, 0, 0, pseudo_header->cosine.pro);
75     proto_tree_add_uint(fh_tree, hf_off, tvb, 0, 0, pseudo_header->cosine.off);
76     proto_tree_add_uint(fh_tree, hf_pri, tvb, 0, 0, pseudo_header->cosine.pri);
77     proto_tree_add_uint(fh_tree, hf_rm,  tvb, 0, 0, pseudo_header->cosine.rm);
78     proto_tree_add_uint(fh_tree, hf_err, tvb, 0, 0, pseudo_header->cosine.err);
79
80     switch (pseudo_header->cosine.encap) {
81       case COSINE_ENCAP_ETH:
82         break;
83       case COSINE_ENCAP_ATM:
84       case COSINE_ENCAP_PPoATM:
85         proto_tree_add_text(fh_tree, tvb, 0, 16, "SAR header");
86         break;
87       case COSINE_ENCAP_PPP:
88       case COSINE_ENCAP_FR:
89       case COSINE_ENCAP_PPoFR:
90         proto_tree_add_text(fh_tree, tvb, 0, 4, "Channel handle ID");
91         break;
92       case COSINE_ENCAP_HDLC:
93         if (pseudo_header->cosine.direction == COSINE_DIR_TX) {
94           proto_tree_add_text(fh_tree, tvb, 0, 2,
95                               "Channel handle ID");
96         } else if (pseudo_header->cosine.direction == COSINE_DIR_RX) {
97           proto_tree_add_text(fh_tree, tvb, 0, 4,
98                               "Channel handle ID");
99         }
100         break;
101       default:
102         break;
103     }
104   }
105
106   switch (pseudo_header->cosine.encap) {
107     case COSINE_ENCAP_ETH:
108       call_dissector(eth_withoutfcs_handle, tvb_new_subset_remaining(tvb, 0),
109                      pinfo, tree);
110       break;
111     case COSINE_ENCAP_ATM:
112     case COSINE_ENCAP_PPoATM:
113       call_dissector(llc_handle, tvb_new_subset_remaining(tvb, 16),
114                      pinfo, tree);
115       break;
116     case COSINE_ENCAP_PPP:
117       call_dissector(ppp_hdlc_handle, tvb_new_subset_remaining(tvb, 4),
118                      pinfo, tree);
119       break;
120     case COSINE_ENCAP_HDLC:
121       if (pseudo_header->cosine.direction == COSINE_DIR_TX) {
122         call_dissector(chdlc_handle, tvb_new_subset_remaining(tvb, 2),
123                        pinfo, tree);
124       } else if (pseudo_header->cosine.direction == COSINE_DIR_RX) {
125         call_dissector(chdlc_handle, tvb_new_subset_remaining(tvb, 4),
126                        pinfo, tree);
127       }
128       break;
129     case COSINE_ENCAP_FR:
130     case COSINE_ENCAP_PPoFR:
131       call_dissector(fr_handle, tvb_new_subset_remaining(tvb, 4),
132                      pinfo, tree);
133       break;
134     case COSINE_ENCAP_TEST:
135     case COSINE_ENCAP_UNKNOWN:
136       call_dissector(data_handle, tvb, pinfo, tree);
137       break;
138     default:
139       break;
140   }
141 }
142
143 void
144 proto_register_cosine(void)
145 {
146   static hf_register_info hf[] = {
147     { &hf_pro,
148       { "Protocol", "cosine.pro", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
149     { &hf_off,
150       { "Offset", "cosine.off", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
151     { &hf_pri,
152       { "Priority", "cosine.pri", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
153     { &hf_rm,
154       { "Rate Marking", "cosine.rm",  FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
155     { &hf_err,
156       { "Error Code", "cosine.err", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
157   };
158
159   static gint *ett[] = {
160     &ett_raw,
161   };
162
163   proto_cosine = proto_register_protocol("CoSine IPNOS L2 debug output",
164                                          "CoSine", "cosine");
165   proto_register_field_array(proto_cosine, hf, array_length(hf));
166   proto_register_subtree_array(ett, array_length(ett));
167 }
168
169 void
170 proto_reg_handoff_cosine(void)
171 {
172   dissector_handle_t cosine_handle;
173
174   /*
175    * Get handles for dissectors.
176    */
177   eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
178   ppp_hdlc_handle       = find_dissector("ppp_hdlc");
179   llc_handle            = find_dissector("llc");
180   chdlc_handle          = find_dissector("chdlc");
181   fr_handle             = find_dissector("fr");
182   data_handle           = find_dissector("data");
183
184   cosine_handle = create_dissector_handle(dissect_cosine, proto_cosine);
185   dissector_add_uint("wtap_encap", WTAP_ENCAP_COSINE, cosine_handle);
186 }