2 * Routines for displaying frames from k12 rf5 files
4 * Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
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.
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.
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.
35 #include <epan/packet.h>
37 #include <epan/report_err.h>
39 static int proto_k12 = -1;
41 static int hf_k12_port_id = -1;
42 static int hf_k12_port_name = -1;
43 static int hf_k12_stack_file = -1;
44 static int hf_k12_port_type = -1;
45 static int hf_k12_atm_vp = -1;
46 static int hf_k12_atm_vc = -1;
48 static int hf_k12_ts = -1;
50 static gint ett_k12 = -1;
51 static gint ett_port = -1;
53 static dissector_handle_t k12_handle;
54 static dissector_handle_t data_handle;
56 static module_t *k12_module;
58 static const char* k12_config_filename = "";
60 static GHashTable* k12_cfg = NULL;
63 static const value_string k12_port_types[] = {
64 { K12_PORT_DS1, "Ds1" },
65 { K12_PORT_DS0S, "Ds0 Range" },
66 { K12_PORT_ATMPVC, "ATM PVC" },
71 static void dissect_k12(tvbuff_t* tvb,packet_info* pinfo,proto_tree* tree) {
74 dissector_handle_t sub_handle;
76 k12_item = proto_tree_add_protocol_format(tree, proto_k12, tvb, 0, 0, "Packet from: '%s' (0x%.8x)",
77 pinfo->pseudo_header->k12.input_name,
78 pinfo->pseudo_header->k12.input);
80 k12_tree = proto_item_add_subtree(k12_item, ett_k12);
82 proto_tree_add_uint(k12_tree, hf_k12_port_id, tvb, 0,0,pinfo->pseudo_header->k12.input);
83 proto_tree_add_string(k12_tree, hf_k12_port_name, tvb, 0,0,pinfo->pseudo_header->k12.input_name);
84 proto_tree_add_string(k12_tree, hf_k12_stack_file, tvb, 0,0,pinfo->pseudo_header->k12.stack_file);
86 k12_item = proto_tree_add_uint(k12_tree, hf_k12_port_type, tvb, 0, 0,
87 pinfo->pseudo_header->k12.input_type);
89 k12_tree = proto_item_add_subtree(k12_item, ett_port);
91 switch ( pinfo->pseudo_header->k12.input_type ) {
93 proto_tree_add_uint(k12_tree, hf_k12_ts, tvb, 0,0,pinfo->pseudo_header->k12.input_info.ds0mask);
96 proto_tree_add_uint(k12_tree, hf_k12_atm_vp, tvb, 0,0,pinfo->pseudo_header->k12.input_info.atm.vp);
97 proto_tree_add_uint(k12_tree, hf_k12_atm_vc, tvb, 0,0,pinfo->pseudo_header->k12.input_info.atm.vc);
104 sub_handle = data_handle;
106 sub_handle = g_hash_table_lookup(k12_cfg,pinfo->pseudo_header->k12.stack_file);
109 sub_handle = data_handle;
112 call_dissector(sub_handle, tvb, pinfo, tree);
116 static gboolean free_just_key (gpointer k, gpointer v _U_, gpointer p _U_) {
122 static GHashTable* k12_load_config(const gchar* filename) {
124 gchar buffer[0x10000];
126 GHashTable* hash = g_hash_table_new(g_str_hash,g_str_equal);
128 gchar** lines = NULL;
130 dissector_handle_t handle;
132 /* XXX: should look for the file in common locations */
134 if (( fp = fopen(filename,"r") )) {
135 len = fread(buffer,1,0xFFFF,fp);
137 report_open_failure(filename, errno, FALSE);
143 lines = g_strsplit(buffer,"\n",0);
145 for (i = 0 ; lines[i]; i++) {
146 g_strstrip(lines[i]);
149 if(*(lines[i]) == '#' || *(lines[i]) == '\0')
152 curr = g_strsplit(lines[i]," ",0);
154 if (! (curr[0] != NULL && *curr[0] != '\0' && curr[1] != NULL && *curr[1] != '\0' ) ) {
155 report_failure("K12xx: Format error in line %u",i+1);
158 g_hash_table_foreach_remove(hash,free_just_key,NULL);
159 g_hash_table_destroy(hash);
165 handle = find_dissector(curr[1]);
168 report_failure("k12: proto %s not found",curr[1]);
169 handle = data_handle;
172 g_hash_table_insert(hash,g_strdup(curr[0]),handle);
182 g_hash_table_destroy(hash);
184 report_read_failure(filename, errno);
190 static void k12_load_prefs(void) {
192 g_hash_table_foreach_remove(k12_cfg,free_just_key,NULL);
193 g_hash_table_destroy(k12_cfg);
197 if (*k12_config_filename != '\0') {
198 k12_cfg = k12_load_config(k12_config_filename);
203 void proto_reg_handoff_k12(void) {
204 k12_handle = find_dissector("k12");
205 data_handle = find_dissector("data");
206 dissector_add("wtap_encap", WTAP_ENCAP_K12, k12_handle);
210 proto_register_k12(void)
212 static hf_register_info hf[] = {
213 { &hf_k12_port_id, { "Port Id", "k12.port_id", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
214 { &hf_k12_port_name, { "Port Name", "k12.port_name", FT_STRING, BASE_NONE, NULL, 0x0,"", HFILL }},
215 { &hf_k12_stack_file, { "Stack file used", "k12.stack_file", FT_STRING, BASE_NONE, NULL, 0x0,"", HFILL }},
216 { &hf_k12_port_type, { "Port type", "k12.input_type", FT_UINT32, BASE_HEX, VALS(k12_port_types), 0x0,"", HFILL }},
217 { &hf_k12_ts, { "Timeslot mask", "k12.ds0.ts", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
218 { &hf_k12_atm_vp, { "ATM VPI", "atm.vpi", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
219 { &hf_k12_atm_vc, { "ATM VCI", "atm.vci", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }}
222 static gint *ett[] = {
227 proto_k12 = proto_register_protocol("K12xx", "K12xx", "k12");
228 proto_register_field_array(proto_k12, hf, array_length(hf));
229 proto_register_subtree_array(ett, array_length(ett));
230 register_dissector("k12", dissect_k12, proto_k12);
232 k12_module = prefs_register_protocol(proto_k12, k12_load_prefs);
234 prefs_register_string_preference(k12_module, "config",
235 "Configuration filename",
236 "K12 module configuration filename",
237 &k12_config_filename);