create_dissector_handle -> new_create_dissector_handle
[metze/wireshark/wip.git] / epan / dissectors / packet-lge_monitor.c
1 /* packet-lge_monitor.c
2  * Routines for LGE Monitor packet dissection
3  * Copyright 2006, Anders Broman <anders.broman[at]ericsson.com>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  *
23  * LGE Monitor is a trace tool from Nortel.
24  */
25
26 #include "config.h"
27
28 #include <epan/packet.h>
29 #include <epan/prefs.h>
30
31 void proto_reg_handoff_lge_monitor(void);
32 void proto_register_lge_monitor(void);
33
34 /* Initialize the protocol and registered fields */
35 static int proto_lge_monitor            = -1;
36
37 static int hf_lge_monitor_dir = -1;
38 static int hf_lge_monitor_prot = -1;
39 static int hf_lge_monitor_length = -1;
40 static int hf_lge_monitor_data = -1;
41
42 /* Initialize the subtree pointers */
43 static int ett_lge_monitor = -1;
44 static int ett_lge_header = -1;
45
46 static guint LGEMonitorUDPPort = 0;
47 static dissector_handle_t mtp3_handle, m3ua_handle, sccp_handle, sctp_handle;
48
49 static const value_string lge_monitor_dir_vals[] = {
50         { 0x00, "TX(Transmit Message Signaling Unit)" },
51         { 0x01, "RX(Receive Message Signaling Unit)" },
52         { 0,    NULL }
53 };
54
55 static const value_string lge_monitor_prot_vals[] = {
56         { 0x00, "MTP-3(Message Transfer Part 3)" },
57         { 0x01, "SCCP(Signaling Connection Control Part)"},
58         { 0x02, "SCTP(Stream Control Transmission Protocol)"},
59         { 0x03, "M3UA(MTP-3 User Adaptation)"},
60         { 0,    NULL }
61 };
62
63 #define LGEMON_PROTO_HEADER_LENGTH 12
64
65 /* Code to actually dissect the packets */
66 static int
67 dissect_lge_monitor(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
68 {
69         int offset = 0;
70         guint32 lge_monitor_proto_id;
71         tvbuff_t* next_tvb = NULL;
72         proto_tree* header_tree;
73
74 /* Set up structures needed to add the protocol subtree and manage it */
75         proto_item *ti;
76         proto_tree *lge_monitor_tree;
77
78 /* Make entries in Protocol column and Info column on summary display */
79         col_set_str(pinfo->cinfo, COL_PROTOCOL, "LGE Monitor");
80
81         ti = proto_tree_add_item(tree, proto_lge_monitor, tvb, 0, LGEMON_PROTO_HEADER_LENGTH, ENC_NA);
82         lge_monitor_tree = proto_item_add_subtree(ti, ett_lge_monitor);
83
84         header_tree = proto_tree_add_subtree(lge_monitor_tree, tvb, offset, LGEMON_PROTO_HEADER_LENGTH, ett_lge_header, NULL, "LGE Monitor PDU");
85         proto_tree_add_item(header_tree, hf_lge_monitor_dir, tvb, offset, 4, ENC_BIG_ENDIAN);
86         offset += 4;
87         lge_monitor_proto_id = tvb_get_ntohl(tvb,offset);
88         proto_tree_add_item(header_tree, hf_lge_monitor_prot, tvb, offset, 4, ENC_BIG_ENDIAN);
89         offset += 4;
90         proto_tree_add_item(header_tree, hf_lge_monitor_length, tvb, offset, 4, ENC_BIG_ENDIAN);
91         offset += 4;
92
93         next_tvb = tvb_new_subset_remaining(tvb, offset);
94
95         switch (lge_monitor_proto_id){
96         case 0: /* MTP3 */
97                 call_dissector(mtp3_handle, next_tvb, pinfo, tree);
98                 break;
99         case 1: /* SCCP */
100                 call_dissector(sccp_handle, next_tvb, pinfo, tree);
101                 break;
102         case 2: /* SCTP */
103                 call_dissector(sctp_handle, next_tvb, pinfo, tree);
104                 break;
105         case 3: /* M3UA */
106                 call_dissector(m3ua_handle, next_tvb, pinfo, tree);
107                 break;
108         default:
109                 proto_tree_add_item(lge_monitor_tree, hf_lge_monitor_data, tvb, offset, -1, ENC_NA);
110                 break;
111         }
112         return tvb_captured_length(tvb);
113 }
114
115
116 void
117 proto_reg_handoff_lge_monitor(void)
118 {
119         static dissector_handle_t lge_monitor_handle;
120         static guint saved_udp_port;
121         static gboolean lge_monitor_prefs_initialized = FALSE;
122
123         if (!lge_monitor_prefs_initialized) {
124                 lge_monitor_handle = new_create_dissector_handle(dissect_lge_monitor, proto_lge_monitor);
125                 dissector_add_for_decode_as("udp.port", lge_monitor_handle);
126                 mtp3_handle  = find_dissector("mtp3");
127                 m3ua_handle  = find_dissector("m3ua");
128                 sccp_handle  = find_dissector("sccp");
129                 sctp_handle  = find_dissector("sctp");
130                 lge_monitor_prefs_initialized = TRUE;
131           }
132         else {
133                 if (saved_udp_port != 0) {
134                         dissector_delete_uint("udp.port", saved_udp_port, lge_monitor_handle);
135                 }
136         }
137
138         if (LGEMonitorUDPPort != 0) {
139                 dissector_add_uint("udp.port", LGEMonitorUDPPort, lge_monitor_handle);
140         }
141         saved_udp_port = LGEMonitorUDPPort;
142 }
143
144 void
145 proto_register_lge_monitor(void)
146 {
147
148         module_t *lge_monitor_module;
149
150 /* Setup list of header fields  */
151         static hf_register_info hf[] = {
152                 { &hf_lge_monitor_dir,
153                         { "Direction",           "lge_monitor.dir",
154                         FT_UINT32, BASE_DEC, VALS(lge_monitor_dir_vals), 0x0,
155                         NULL, HFILL }
156                 },
157                 { &hf_lge_monitor_prot,
158                         { "Protocol Identifier",           "lge_monitor.prot",
159                         FT_UINT32, BASE_DEC, VALS(lge_monitor_prot_vals), 0x0,
160                         NULL, HFILL }
161                 },
162                 { &hf_lge_monitor_length,
163                         { "Payload Length",           "lge_monitor.length",
164                         FT_UINT32, BASE_DEC, NULL, 0x0,
165                         NULL, HFILL }
166                 },
167                 { &hf_lge_monitor_data,
168                         { "LGE Monitor data",           "lge_monitor.monitor_data",
169                         FT_BYTES, BASE_NONE, NULL, 0x0,
170                         NULL, HFILL }
171                 },
172         };
173
174 /* Setup protocol subtree array */
175         static gint *ett[] = {
176                 &ett_lge_monitor,
177                 &ett_lge_header
178         };
179
180 /* Register the protocol name and description */
181         proto_lge_monitor = proto_register_protocol("LGE Monitor","LGE_Monitor", "lge_monitor");
182
183 /* Required function calls to register the header fields and subtrees used */
184         proto_register_field_array(proto_lge_monitor, hf, array_length(hf));
185         proto_register_subtree_array(ett, array_length(ett));
186         /* Register a configuration option for port */
187
188
189         lge_monitor_module = prefs_register_protocol(proto_lge_monitor, proto_reg_handoff_lge_monitor);
190
191         prefs_register_uint_preference(lge_monitor_module, "udp.port",
192                                                                    "LGE Monitor UDP Port",
193                                                                    "Set UDP port for LGE Monitor messages",
194                                                                    10,
195                                                                    &LGEMonitorUDPPort);
196
197 }
198
199 /*
200  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
201  *
202  * Local variables:
203  * c-basic-offset: 8
204  * tab-width: 8
205  * indent-tabs-mode: t
206  * End:
207  *
208  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
209  * :indentSize=8:tabSize=8:noTabs=false:
210  */