Obscure more email addresses.
[obnox/wireshark/wip.git] / packet-cosine.c
1 /* packet-cosine.c
2  * Routines for decoding CoSine IPNOS L2 debug output
3  *
4  * $Id: packet-cosine.c,v 1.4 2002/08/28 21:00:08 jmayer Exp $
5  *
6  * Motonori Shindo <mshindo@mshindo.net>
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 /*
27  * XXX TODO:
28  *    o PPoATM and PPoFR encapsulation needs more test.
29  *
30  */
31
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35
36 #include <glib.h>
37 #include <string.h>
38 #include <epan/packet.h>
39
40 static int proto_cosine = -1;
41 static int hf_pro = -1;
42 static int hf_off = -1;
43 static int hf_pri = -1;
44 static int hf_rm = -1;
45 static int hf_err = -1;
46
47 static gint ett_raw = -1;
48
49 static dissector_handle_t eth_handle;
50 static dissector_handle_t ppp_hdlc_handle;
51 static dissector_handle_t llc_handle;
52 static dissector_handle_t chdlc_handle;
53 static dissector_handle_t fr_handle;
54 static dissector_handle_t data_handle;
55
56 static void
57 dissect_cosine(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
58 {
59   proto_tree                    *fh_tree;
60   proto_item                    *ti;
61   union wtap_pseudo_header      *pseudo_header = pinfo->pseudo_header;
62
63   /* load the top pane info. This should be overwritten by
64      the next protocol in the stack */
65   if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
66     col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A" );
67   if(check_col(pinfo->cinfo, COL_RES_DL_DST))
68     col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A" );
69   if(check_col(pinfo->cinfo, COL_PROTOCOL))
70     col_set_str(pinfo->cinfo, COL_PROTOCOL, "N/A" );
71   if(check_col(pinfo->cinfo, COL_INFO))
72     col_set_str(pinfo->cinfo, COL_INFO, "CoSine IPNOS L2 debug output" );
73
74   /* populate a tree in the second pane with the status of the link
75      layer (ie none) */
76   if(tree) {
77     ti = proto_tree_add_protocol_format(tree, proto_cosine, tvb, 0, 4,
78                                         "CoSine IPNOS L2 debug output (%s)",
79                                         pseudo_header->cosine.if_name);
80     fh_tree = proto_item_add_subtree(ti, ett_raw);
81     proto_tree_add_uint(fh_tree, hf_pro, tvb, 0, 0, pseudo_header->cosine.pro);
82     proto_tree_add_uint(fh_tree, hf_off, tvb, 0, 0, pseudo_header->cosine.off);
83     proto_tree_add_uint(fh_tree, hf_pri, tvb, 0, 0, pseudo_header->cosine.pri);
84     proto_tree_add_uint(fh_tree, hf_rm,  tvb, 0, 0, pseudo_header->cosine.rm);
85     proto_tree_add_uint(fh_tree, hf_err, tvb, 0, 0, pseudo_header->cosine.err);
86
87     switch (pseudo_header->cosine.encap) {
88     case COSINE_ENCAP_ETH:
89             break;
90     case COSINE_ENCAP_ATM:
91     case COSINE_ENCAP_PPoATM:
92             proto_tree_add_text(fh_tree, tvb, 0, 16, "SAR header");
93             break;
94     case COSINE_ENCAP_PPP:
95     case COSINE_ENCAP_FR:
96     case COSINE_ENCAP_PPoFR:
97             proto_tree_add_text(fh_tree, tvb, 0, 4, "Channel handle ID");
98             break;
99     case COSINE_ENCAP_HDLC:
100             if (pseudo_header->cosine.direction == COSINE_DIR_TX) {
101                     proto_tree_add_text(fh_tree, tvb, 0, 2,
102                                         "Channel handle ID");
103             } else if (pseudo_header->cosine.direction == COSINE_DIR_RX) {
104                     proto_tree_add_text(fh_tree, tvb, 0, 4,
105                                         "Channel handle ID");
106             }
107             break;
108     default:
109             break;
110     }
111   }
112
113   switch (pseudo_header->cosine.encap) {
114   case COSINE_ENCAP_ETH:
115           call_dissector(eth_handle, tvb_new_subset(tvb, 0, -1, -1),
116                          pinfo, tree);
117           break;
118   case COSINE_ENCAP_ATM:
119   case COSINE_ENCAP_PPoATM:
120           call_dissector(llc_handle, tvb_new_subset(tvb, 16, -1, -1),
121                          pinfo, tree);
122           break;
123   case COSINE_ENCAP_PPP:
124           call_dissector(ppp_hdlc_handle, tvb_new_subset(tvb, 4, -1, -1),
125                          pinfo, tree);
126           break;
127   case COSINE_ENCAP_HDLC:
128           if (pseudo_header->cosine.direction == COSINE_DIR_TX) {
129                   call_dissector(chdlc_handle, tvb_new_subset(tvb, 2, -1, -1),
130                                  pinfo, tree);
131           } else if (pseudo_header->cosine.direction == COSINE_DIR_RX) {
132                   call_dissector(chdlc_handle, tvb_new_subset(tvb, 4, -1, -1),
133                          pinfo, tree);
134           }
135           break;
136   case COSINE_ENCAP_FR:
137   case COSINE_ENCAP_PPoFR:
138           call_dissector(fr_handle, tvb_new_subset(tvb, 4, -1, -1),
139                          pinfo, tree);
140           break;
141   case COSINE_ENCAP_TEST:
142   case COSINE_ENCAP_UNKNOWN:
143           call_dissector(data_handle, tvb, pinfo, tree);
144           break;
145   default:
146           break;
147   }
148 }
149
150 void
151 proto_register_cosine(void)
152 {
153   static hf_register_info hf[] = {
154     { &hf_pro,
155       { "Protocol", "cosine.pro", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL}},
156     { &hf_off,
157       { "Offset", "cosine.off", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL}},
158     { &hf_pri,
159       { "Priority", "cosine.pri", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL}},
160     { &hf_rm,
161       { "Rate Marking", "cosine.rm",  FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL}},
162     { &hf_err,
163       { "Error Code", "cosine.err", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL}},
164   };
165
166   static gint *ett[] = {
167     &ett_raw,
168   };
169
170   proto_cosine = proto_register_protocol("CoSine IPNOS L2 debug output",
171                                          "CoSine", "cosine");
172   proto_register_field_array(proto_cosine, hf, array_length(hf));
173   proto_register_subtree_array(ett, array_length(ett));
174 }
175
176 void
177 proto_reg_handoff_cosine(void)
178 {
179   dissector_handle_t cosine_handle;
180
181   /*
182    * Get handles for dissectors.
183    */
184   eth_handle = find_dissector("eth");
185   ppp_hdlc_handle = find_dissector("ppp_hdlc");
186   llc_handle = find_dissector("llc");
187   chdlc_handle = find_dissector("chdlc");
188   fr_handle = find_dissector("fr");
189   data_handle = find_dissector("data");
190
191   cosine_handle = create_dissector_handle(dissect_cosine, proto_cosine);
192   dissector_add("wtap_encap", WTAP_ENCAP_COSINE, cosine_handle);
193 }