checkAPIs.pl: support for new-style dissectors in check_hf_entries
[metze/wireshark/wip.git] / epan / dissectors / packet-cosine.c
1 /* packet-cosine.c
2  * Routines for decoding CoSine IPNOS L2 debug output
3  *
4  * Motonori Shindo <motonori@shin.do>
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11
12 /*
13  * XXX TODO:
14  *    o PPoATM and PPoFR encapsulation needs more test.
15  *
16  */
17
18 #include "config.h"
19
20 #include <epan/packet.h>
21 #include <wiretap/wtap.h>
22
23 void proto_register_cosine(void);
24 void proto_reg_handoff_cosine(void);
25
26 static int proto_cosine = -1;
27 static int hf_pro = -1;
28 static int hf_off = -1;
29 static int hf_pri = -1;
30 static int hf_rm = -1;
31 static int hf_err = -1;
32 static int hf_sar = -1;
33 static int hf_channel_id = -1;
34
35 static gint ett_raw = -1;
36
37 static dissector_handle_t eth_withoutfcs_handle;
38 static dissector_handle_t ppp_hdlc_handle;
39 static dissector_handle_t llc_handle;
40 static dissector_handle_t chdlc_handle;
41 static dissector_handle_t fr_handle;
42
43 static int
44 dissect_cosine(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
45 {
46   proto_tree               *fh_tree;
47   proto_item               *ti;
48   union wtap_pseudo_header *pseudo_header = pinfo->pseudo_header;
49
50   /* load the top pane info. This should be overwritten by
51      the next protocol in the stack */
52   col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A");
53   col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A");
54   col_set_str(pinfo->cinfo, COL_PROTOCOL, "N/A");
55   col_set_str(pinfo->cinfo, COL_INFO, "CoSine IPNOS L2 debug output");
56
57   /* populate a tree in the second pane with the status of the link
58      layer (ie none) */
59   if(tree) {
60     ti = proto_tree_add_protocol_format(tree, proto_cosine, tvb, 0, 0,
61                                         "CoSine IPNOS L2 debug output (%s)",
62                                         pseudo_header->cosine.if_name);
63     fh_tree = proto_item_add_subtree(ti, ett_raw);
64     proto_tree_add_uint(fh_tree, hf_pro, tvb, 0, 0, pseudo_header->cosine.pro);
65     proto_tree_add_uint(fh_tree, hf_off, tvb, 0, 0, pseudo_header->cosine.off);
66     proto_tree_add_uint(fh_tree, hf_pri, tvb, 0, 0, pseudo_header->cosine.pri);
67     proto_tree_add_uint(fh_tree, hf_rm,  tvb, 0, 0, pseudo_header->cosine.rm);
68     proto_tree_add_uint(fh_tree, hf_err, tvb, 0, 0, pseudo_header->cosine.err);
69
70     switch (pseudo_header->cosine.encap) {
71       case COSINE_ENCAP_ETH:
72         break;
73       case COSINE_ENCAP_ATM:
74       case COSINE_ENCAP_PPoATM:
75         proto_tree_add_item(fh_tree, hf_sar, tvb, 0, 16, ENC_NA);
76         break;
77       case COSINE_ENCAP_PPP:
78       case COSINE_ENCAP_FR:
79       case COSINE_ENCAP_PPoFR:
80         proto_tree_add_item(fh_tree, hf_channel_id, tvb, 0, 4, ENC_NA);
81         break;
82       case COSINE_ENCAP_HDLC:
83         if (pseudo_header->cosine.direction == COSINE_DIR_TX) {
84           proto_tree_add_item(fh_tree, hf_channel_id, tvb, 0, 2, ENC_NA);
85         } else if (pseudo_header->cosine.direction == COSINE_DIR_RX) {
86           proto_tree_add_item(fh_tree, hf_channel_id, tvb, 0, 4, ENC_NA);
87         }
88         break;
89       default:
90         break;
91     }
92   }
93
94   switch (pseudo_header->cosine.encap) {
95     case COSINE_ENCAP_ETH:
96       call_dissector(eth_withoutfcs_handle, tvb_new_subset_remaining(tvb, 0),
97                      pinfo, tree);
98       break;
99     case COSINE_ENCAP_ATM:
100     case COSINE_ENCAP_PPoATM:
101       call_dissector(llc_handle, tvb_new_subset_remaining(tvb, 16),
102                      pinfo, tree);
103       break;
104     case COSINE_ENCAP_PPP:
105       call_dissector(ppp_hdlc_handle, tvb_new_subset_remaining(tvb, 4),
106                      pinfo, tree);
107       break;
108     case COSINE_ENCAP_HDLC:
109       if (pseudo_header->cosine.direction == COSINE_DIR_TX) {
110         call_dissector(chdlc_handle, tvb_new_subset_remaining(tvb, 2),
111                        pinfo, tree);
112       } else if (pseudo_header->cosine.direction == COSINE_DIR_RX) {
113         call_dissector(chdlc_handle, tvb_new_subset_remaining(tvb, 4),
114                        pinfo, tree);
115       }
116       break;
117     case COSINE_ENCAP_FR:
118     case COSINE_ENCAP_PPoFR:
119       call_dissector(fr_handle, tvb_new_subset_remaining(tvb, 4),
120                      pinfo, tree);
121       break;
122     case COSINE_ENCAP_TEST:
123     case COSINE_ENCAP_UNKNOWN:
124       call_data_dissector(tvb, pinfo, tree);
125       break;
126     default:
127       break;
128   }
129   return tvb_captured_length(tvb);
130 }
131
132 void
133 proto_register_cosine(void)
134 {
135   static hf_register_info hf[] = {
136     { &hf_pro,
137       { "Protocol", "cosine.pro", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
138     { &hf_off,
139       { "Offset", "cosine.off", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
140     { &hf_pri,
141       { "Priority", "cosine.pri", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
142     { &hf_rm,
143       { "Rate Marking", "cosine.rm",  FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
144     { &hf_err,
145       { "Error Code", "cosine.err", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
146     { &hf_sar,
147       { "SAR header", "cosine.sar", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
148     { &hf_channel_id,
149       { "Channel handle ID", "cosine.channel_id", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
150   };
151
152   static gint *ett[] = {
153     &ett_raw,
154   };
155
156   proto_cosine = proto_register_protocol("CoSine IPNOS L2 debug output",
157                                          "CoSine", "cosine");
158   proto_register_field_array(proto_cosine, hf, array_length(hf));
159   proto_register_subtree_array(ett, array_length(ett));
160 }
161
162 void
163 proto_reg_handoff_cosine(void)
164 {
165   dissector_handle_t cosine_handle;
166
167   /*
168    * Get handles for dissectors.
169    */
170   eth_withoutfcs_handle = find_dissector_add_dependency("eth_withoutfcs", proto_cosine);
171   ppp_hdlc_handle       = find_dissector_add_dependency("ppp_hdlc", proto_cosine);
172   llc_handle            = find_dissector_add_dependency("llc", proto_cosine);
173   chdlc_handle          = find_dissector_add_dependency("chdlc", proto_cosine);
174   fr_handle             = find_dissector_add_dependency("fr", proto_cosine);
175
176   cosine_handle = create_dissector_handle(dissect_cosine, proto_cosine);
177   dissector_add_uint("wtap_encap", WTAP_ENCAP_COSINE, cosine_handle);
178 }
179
180 /*
181  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
182  *
183  * Local Variables:
184  * c-basic-offset: 2
185  * tab-width: 8
186  * indent-tabs-mode: nil
187  * End:
188  *
189  * ex: set shiftwidth=2 tabstop=8 expandtab:
190  * :indentSize=2:tabSize=8:noTabs=true:
191  */