MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / dissectors / packet-exported_pdu.c
blob85a9f8ba0c9e3893fd1b19be6f5f30468de4506c
1 /* packet-exported_pdu.c
2 * Routines for exported_pdu dissection
3 * Copyright 2013, Anders Broman <anders-broman@ericsson.com>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
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.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
30 #include <epan/packet.h>
31 #include <epan/to_str.h>
32 #include <epan/tap.h>
33 #include <epan/exported_pdu.h>
34 #include <epan/wmem/wmem.h>
36 #include "packet-mtp3.h"
37 #include "packet-dvbci.h"
39 void proto_reg_handoff_exported_pdu(void);
41 static int proto_exported_pdu = -1;
42 static int hf_exported_pdu_tag = -1;
43 static int hf_exported_pdu_tag_len = -1;
44 static int hf_exported_pdu_unknown_tag = -1;
45 static int hf_exported_pdu_prot_name = -1;
46 static int hf_exported_pdu_ipv4_src = -1;
47 static int hf_exported_pdu_ipv4_dst = -1;
48 static int hf_exported_pdu_ipv6_src = -1;
49 static int hf_exported_pdu_ipv6_dst = -1;
50 static int hf_exported_pdu_port_type = -1;
51 static int hf_exported_pdu_src_port = -1;
52 static int hf_exported_pdu_dst_port = -1;
53 static int hf_exported_pdu_sctp_ppid = -1;
54 static int hf_exported_pdu_ss7_opc = -1;
55 static int hf_exported_pdu_ss7_dpc = -1;
56 static int hf_exported_pdu_orig_fno = -1;
57 static int hf_exported_pdu_dvbci_evt = -1;
60 /* Initialize the subtree pointers */
61 static gint ett_exported_pdu = -1;
62 static gint ett_exported_pdu_tag = -1;
64 #define EXPORTED_PDU_NEXT_PROTO_STR 0
65 static const value_string exported_pdu_tag_vals[] = {
66 { EXP_PDU_TAG_END_OF_OPT, "End-of-options" },
67 /* 1 - 9 reserved */
68 { EXP_PDU_TAG_OPTIONS_LENGTH, "Total length of the options excluding this TLV" },
69 { EXP_PDU_TAG_LINKTYPE, "Linktype value" },
70 { EXP_PDU_TAG_PROTO_NAME, "PDU content protocol name" },
71 /* Add protocol type related tags here */
72 /* 13 - 19 reserved */
73 { EXP_PDU_TAG_IPV4_SRC, "IPv4 Source Address" },
74 { EXP_PDU_TAG_IPV4_DST, "IPv4 Destination Address" },
75 { EXP_PDU_TAG_IPV6_SRC, "IPv6 Source Address" },
76 { EXP_PDU_TAG_IPV6_DST, "IPv6 Destination Address" },
78 { EXP_PDU_TAG_PORT_TYPE, "Port Type" },
79 { EXP_PDU_TAG_SRC_PORT, "Source Port" },
80 { EXP_PDU_TAG_DST_PORT, "Destination Port" },
82 { EXP_PDU_TAG_SCTP_PPID, "SCTP PPID" },
84 { EXP_PDU_TAG_SS7_OPC, "SS7 OPC" },
85 { EXP_PDU_TAG_SS7_DPC, "SS7 DPC" },
87 { EXP_PDU_TAG_ORIG_FNO, "Original Frame number" },
89 { EXP_PDU_TAG_DVBCI_EVT, "DVB-CI event" },
91 { 0, NULL }
94 /* Code to actually dissect the packets */
95 static void
96 dissect_exported_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
98 proto_item *ti;
99 proto_tree *exported_pdu_tree, *tag_tree;
100 tvbuff_t * payload_tvb = NULL;
101 int offset = 0;
102 guint number_of_ppids = 0;
103 guint16 tag;
104 int tag_len;
105 int next_proto_type = -1;
106 char *proto_name = NULL;
107 const guchar *src_addr, *dst_addr;
108 dissector_handle_t proto_handle;
109 mtp3_addr_pc_t *mtp3_addr;
110 guint8 dvb_ci_dir;
112 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Exported PDU");
114 /* create display subtree for the protocol */
115 ti = proto_tree_add_item(tree, proto_exported_pdu, tvb, offset, -1, ENC_NA);
116 exported_pdu_tree = proto_item_add_subtree(ti, ett_exported_pdu);
118 do {
119 tag = tvb_get_ntohs(tvb, offset);
120 ti = proto_tree_add_item(exported_pdu_tree, hf_exported_pdu_tag, tvb, offset, 2, ENC_BIG_ENDIAN);
121 offset+=2;
122 tag_tree = proto_item_add_subtree(ti, ett_exported_pdu_tag);
123 proto_tree_add_item(tag_tree, hf_exported_pdu_tag_len, tvb, offset, 2, ENC_BIG_ENDIAN);
124 tag_len = tvb_get_ntohs(tvb, offset);
125 offset+=2;
127 switch(tag) {
128 case EXP_PDU_TAG_PROTO_NAME:
129 next_proto_type = EXPORTED_PDU_NEXT_PROTO_STR;
130 proto_name = tvb_get_string(wmem_packet_scope(), tvb, offset, tag_len);
131 proto_tree_add_item(tag_tree, hf_exported_pdu_prot_name, tvb, offset, tag_len, ENC_ASCII|ENC_NA);
132 break;
133 case EXP_PDU_TAG_IPV4_SRC:
134 proto_tree_add_item(tag_tree, hf_exported_pdu_ipv4_src, tvb, offset, 4, ENC_BIG_ENDIAN);
135 src_addr = tvb_get_ptr(tvb, offset, 4);
136 SET_ADDRESS(&pinfo->net_src, AT_IPv4, 4, src_addr);
137 SET_ADDRESS(&pinfo->src, AT_IPv4, 4, src_addr);
138 break;
139 case EXP_PDU_TAG_IPV4_DST:
140 proto_tree_add_item(tag_tree, hf_exported_pdu_ipv4_dst, tvb, offset, 4, ENC_BIG_ENDIAN);
141 dst_addr = tvb_get_ptr(tvb, offset, 4);
142 SET_ADDRESS(&pinfo->net_dst, AT_IPv4, 4, dst_addr);
143 SET_ADDRESS(&pinfo->dst, AT_IPv4, 4, dst_addr);
144 break;
145 case EXP_PDU_TAG_IPV6_SRC:
146 proto_tree_add_item(tag_tree, hf_exported_pdu_ipv6_src, tvb, offset, 16, ENC_NA);
147 src_addr = tvb_get_ptr(tvb, offset, 16);
148 SET_ADDRESS(&pinfo->net_src, AT_IPv6, 16, src_addr);
149 SET_ADDRESS(&pinfo->src, AT_IPv6, 16, src_addr);
150 break;
151 case EXP_PDU_TAG_IPV6_DST:
152 proto_tree_add_item(tag_tree, hf_exported_pdu_ipv6_dst, tvb, offset, 16, ENC_NA);
153 dst_addr = tvb_get_ptr(tvb, offset, 16);
154 SET_ADDRESS(&pinfo->net_dst, AT_IPv6, 16, dst_addr);
155 SET_ADDRESS(&pinfo->dst, AT_IPv6, 16, dst_addr);
156 break;
157 case EXP_PDU_TAG_PORT_TYPE:
158 pinfo->ptype = (port_type)tvb_get_ntohl(tvb, offset);
159 proto_tree_add_uint_format_value(tag_tree, hf_exported_pdu_port_type, tvb, offset, 4, pinfo->ptype,
160 "%s (%u)", port_type_to_str(pinfo->ptype), pinfo->ptype);
161 break;
162 case EXP_PDU_TAG_SRC_PORT:
163 proto_tree_add_item(tag_tree, hf_exported_pdu_src_port, tvb, offset, 4, ENC_BIG_ENDIAN);
164 pinfo->srcport = tvb_get_ntohl(tvb, offset);
165 break;
166 case EXP_PDU_TAG_DST_PORT:
167 proto_tree_add_item(tag_tree, hf_exported_pdu_dst_port, tvb, offset, 4, ENC_BIG_ENDIAN);
168 pinfo->destport = tvb_get_ntohl(tvb, offset);
169 break;
170 case EXP_PDU_TAG_SCTP_PPID:
171 proto_tree_add_item(tag_tree, hf_exported_pdu_sctp_ppid, tvb, offset, 4, ENC_BIG_ENDIAN);
172 if (number_of_ppids < MAX_NUMBER_OF_PPIDS) {
173 pinfo->ppids[number_of_ppids++] = tvb_get_ntohl(tvb, offset);
175 break;
176 case EXP_PDU_TAG_SS7_OPC:
177 proto_tree_add_item(tag_tree, hf_exported_pdu_ss7_opc, tvb, offset, 4, ENC_BIG_ENDIAN);
178 mtp3_addr = (mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t));
179 mtp3_addr->pc = tvb_get_ntohl(tvb, offset);
180 mtp3_addr->type = (Standard_Type)tvb_get_ntohs(tvb, offset+4);
181 mtp3_addr->ni = tvb_get_guint8(tvb, offset+6);
182 SET_ADDRESS(&pinfo->src, AT_SS7PC, sizeof(mtp3_addr_pc_t), (guint8 *) mtp3_addr);
183 break;
184 case EXP_PDU_TAG_SS7_DPC:
185 proto_tree_add_item(tag_tree, hf_exported_pdu_ss7_dpc, tvb, offset, 4, ENC_BIG_ENDIAN);
186 mtp3_addr = (mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t));
187 mtp3_addr->pc = tvb_get_ntohl(tvb, offset);
188 mtp3_addr->type = (Standard_Type)tvb_get_ntohs(tvb, offset+4);
189 mtp3_addr->ni = tvb_get_guint8(tvb, offset+6);
190 SET_ADDRESS(&pinfo->dst, AT_SS7PC, sizeof(mtp3_addr_pc_t), (guint8 *) mtp3_addr);
191 break;
192 case EXP_PDU_TAG_ORIG_FNO:
193 proto_tree_add_item(tag_tree, hf_exported_pdu_orig_fno, tvb, offset, 4, ENC_BIG_ENDIAN);
194 break;
195 case EXP_PDU_TAG_DVBCI_EVT:
196 dvb_ci_dir = tvb_get_guint8(tvb, offset);
197 proto_tree_add_item(tag_tree, hf_exported_pdu_dvbci_evt,
198 tvb, offset, 1, ENC_BIG_ENDIAN);
199 dvbci_set_addrs(dvb_ci_dir, pinfo);
200 break;
201 default:
202 proto_tree_add_item(tag_tree, hf_exported_pdu_unknown_tag, tvb, offset, tag_len, ENC_NA);
203 /* Add an expert item too? */
204 break;
207 offset = offset + tag_len;
209 } while(tag != 0);
211 payload_tvb = tvb_new_subset_remaining(tvb, offset);
213 switch(next_proto_type) {
214 case EXPORTED_PDU_NEXT_PROTO_STR:
215 proto_handle = find_dissector(proto_name);
216 if (proto_handle) {
217 call_dissector(find_dissector(proto_name), payload_tvb, pinfo, tree);
219 break;
220 default:
221 break;
224 proto_tree_add_text(exported_pdu_tree, payload_tvb, 0, -1,"Exported PDU");
227 /* Register the protocol with Wireshark.
230 void
231 proto_register_exported_pdu(void)
233 /*module_t *exported_pdu_module;*/
235 static hf_register_info hf[] = {
236 { &hf_exported_pdu_tag,
237 { "Tag", "exported_pdu.tag",
238 FT_UINT16, BASE_DEC, VALS(exported_pdu_tag_vals), 0,
239 NULL, HFILL }
241 { &hf_exported_pdu_tag_len,
242 { "Length", "exported_pdu.tag_len",
243 FT_UINT16, BASE_DEC, NULL, 0,
244 NULL, HFILL }
246 { &hf_exported_pdu_unknown_tag,
247 { "Unkown tag", "exported_pdu.unknown_tag",
248 FT_BYTES, BASE_NONE, NULL, 0,
249 NULL, HFILL }
251 { &hf_exported_pdu_prot_name,
252 { "Protocol Name", "exported_pdu.prot_name",
253 FT_STRING, BASE_NONE, NULL, 0,
254 NULL, HFILL }
256 { &hf_exported_pdu_ipv4_src,
257 { "IPv4 Src", "exported_pdu.ipv4_src",
258 FT_IPv4, BASE_NONE, NULL, 0,
259 NULL, HFILL }
261 { &hf_exported_pdu_ipv4_dst,
262 { "IPv4 Dst", "exported_pdu.ipv4_dst",
263 FT_IPv4, BASE_NONE, NULL, 0,
264 NULL, HFILL }
266 { &hf_exported_pdu_ipv6_src,
267 { "IPv6 Src", "exported_pdu.ipv6_src",
268 FT_IPv6, BASE_NONE, NULL, 0,
269 NULL, HFILL }
271 { &hf_exported_pdu_ipv6_dst,
272 { "IPv6 Dst", "exported_pdu.ipv6_dst",
273 FT_IPv6, BASE_NONE, NULL, 0,
274 NULL, HFILL }
276 { &hf_exported_pdu_port_type,
277 { "Port Type", "exported_pdu.port_type",
278 FT_UINT32, BASE_DEC, NULL, 0,
279 NULL, HFILL }
281 { &hf_exported_pdu_src_port,
282 { "Src Port", "exported_pdu.src_port",
283 FT_UINT32, BASE_DEC, NULL, 0,
284 NULL, HFILL }
286 { &hf_exported_pdu_dst_port,
287 { "Dst Port", "exported_pdu.dst_port",
288 FT_UINT32, BASE_DEC, NULL, 0,
289 NULL, HFILL }
291 { &hf_exported_pdu_sctp_ppid,
292 { "SCTP PPID", "exported_pdu.sctp_ppid",
293 FT_UINT32, BASE_DEC, NULL, 0,
294 NULL, HFILL }
296 { &hf_exported_pdu_ss7_opc,
297 { "SS7 OPC", "exported_pdu.ss7_opc",
298 FT_UINT32, BASE_DEC, NULL, 0,
299 NULL, HFILL }
301 { &hf_exported_pdu_ss7_dpc,
302 { "SS7 DPC", "exported_pdu.ss7_dpc",
303 FT_UINT32, BASE_DEC, NULL, 0,
304 NULL, HFILL }
306 { &hf_exported_pdu_orig_fno,
307 { "Original Frame Number", "exported_pdu.orig_fno",
308 FT_UINT32, BASE_DEC, NULL, 0,
309 NULL, HFILL }
311 { &hf_exported_pdu_dvbci_evt,
312 { "DVB-CI event", "exported_pdu.dvb-ci.event",
313 FT_UINT8, BASE_HEX, VALS(dvbci_event), 0,
314 NULL, HFILL }
318 /* Setup protocol subtree array */
319 static gint *ett[] = {
320 &ett_exported_pdu,
321 &ett_exported_pdu_tag
324 /* Register the protocol name and description */
325 proto_exported_pdu = proto_register_protocol("EXPORTED_PDU",
326 "exported_pdu", "exported_pdu");
328 register_dissector("exported_pdu", dissect_exported_pdu, proto_exported_pdu);
330 /* Required function calls to register the header fields and subtrees */
331 proto_register_field_array(proto_exported_pdu, hf, array_length(hf));
332 proto_register_subtree_array(ett, array_length(ett));
334 #if 0
335 exported_pdu_module = prefs_register_protocol(exported_pdu,
336 proto_reg_handoff_exported_pdu);
338 prefs_register_bool_preference(exported_pdu_module, "show_hex",
339 "Display numbers in Hex",
340 "Enable to display numerical values in hexadecimal.",
341 &gPREF_HEX);
343 * Register an example port preference */
344 prefs_register_uint_preference(exported_pdu_module, "tcp.port", "exported_pdu TCP Port",
345 " exported_pdu TCP port if other than the default",
346 10, &gPORT_PREF);
347 #endif
348 /* Register for tapping
349 * The tap is registered here but it is to be used by dissectors that
350 * want to export their PDUs, see packet-sip.c
352 register_tap(EXPORT_PDU_TAP_NAME_LAYER_3);
353 register_tap(EXPORT_PDU_TAP_NAME_LAYER_7);
354 register_tap(EXPORT_PDU_TAP_NAME_DVB_CI);
357 void
358 proto_reg_handoff_exported_pdu(void)
360 static gboolean initialized = FALSE;
361 static dissector_handle_t exported_pdu_handle;
363 if (!initialized) {
364 exported_pdu_handle = find_dissector("exported_pdu");
365 dissector_add_uint("wtap_encap", WTAP_ENCAP_WIRESHARK_UPPER_PDU, exported_pdu_handle);
366 initialized = TRUE;
372 * Editor modelines - http://www.wireshark.org/tools/modelines.html
374 * Local variables:
375 * c-basic-offset: 4
376 * tab-width: 8
377 * indent-tabs-mode: nil
378 * End:
380 * vi: set shiftwidth=4 tabstop=8 expandtab:
381 * :indentSize=4:tabSize=8:noTabs=true: