MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / dissectors / packet-ua.c
blob1eefac4987ef6a8a62c06a2303710178199fd2c2
1 /* packet-ua.c
2 * Routines for UA/UDP (Universal Alcatel over UDP) packet dissection.
3 * Copyright 2012, Alcatel-Lucent Enterprise <lars.ruoff@alcatel-lucent.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
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.
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
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 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/prefs.h"
33 #include "epan/dissectors/packet-rtp.h"
34 #include "epan/dissectors/packet-rtcp.h"
36 #include "packet-uaudp.h"
38 /*-----------------------------------------------------------------------------
39 GLOBALS
40 ---------------------------------------------------------------------------*/
42 #if 0
43 static dissector_table_t ua_opcode_dissector_table;
44 #endif
46 static int proto_ua_msg = -1;
47 static gint ett_ua_msg = -1;
49 static gboolean setup_conversations_enabled = TRUE;
51 static dissector_handle_t noe_handle;
52 static dissector_handle_t ua3g_handle;
54 static void uadecode(e_ua_direction direction,
55 proto_tree *tree,
56 packet_info *pinfo,
57 tvbuff_t *tvb,
58 gint offset,
59 gint opcode,
60 gint length)
62 switch (opcode & 0x7f) /* suppression of the CP bit */
64 case 0x15:
65 case 0x16:
67 call_dissector(noe_handle,
68 tvb_new_subset(tvb, offset, length, length),
69 pinfo,
70 tree);
71 break;
73 case 0x00:
74 case 0x01:
75 case 0x02:
76 case 0x03:
77 case 0x04:
78 case 0x05:
79 case 0x06:
80 case 0x07: /* Only UA NOE */
81 case 0x08: /* Only UA NOE */
82 case 0x09:
83 case 0x0A:
84 case 0x0B:
85 case 0x0C:
86 case 0x0D:
87 case 0x0E:
88 case 0x0F:
89 case 0x11:
90 case 0x12:
91 case 0x13:
92 case 0x14:
93 case 0x17:
94 case 0x18:
95 case 0x1F: /* case 0x9F */
96 case 0x20:
97 case 0x21:
98 case 0x22:
99 case 0x23:
100 case 0x24: /* Only IP NOE */
101 case 0x25: /* Only IP NOE */
102 case 0x26:
103 case 0x27:
104 case 0x28:
105 case 0x29:
106 case 0x2A:
107 case 0x2B: /* Only UA NOE */
108 case 0x2C:
109 case 0x2D:
110 case 0x2E:
111 case 0x30:
112 case 0x31:
113 case 0x32: /* Only UA NOE */
114 case 0x33:
115 case 0x35:
116 case 0x36: /* IP Phone */
117 case 0x38:
118 case 0x39:
119 case 0x3A:
120 case 0x3B:
121 case 0x3C:
122 case 0x3D:
123 case 0x3E:
124 case 0x3F:
125 case 0x40:
126 case 0x41:
127 case 0x42:
128 case 0x43:
129 case 0x44:
130 case 0x45:
131 case 0x46:
132 case 0x47:
133 case 0x48:
134 case 0x49:
135 case 0x4A:
136 case 0x4B:
137 case 0x4C:
138 case 0x4D:
139 case 0x4E:
140 case 0x4F:
141 case 0x50: /* Only UA NOE */
143 call_dissector_with_data(ua3g_handle,
144 tvb_new_subset(tvb, offset, length, length),
145 pinfo,
146 tree, (void*)direction);
147 break;
149 default:
151 /* add text to the frame "INFO" column */
152 col_append_str(pinfo->cinfo, COL_INFO, " - UA3G Message ERR: Opcode Unknown");
154 proto_tree_add_text(tree,
155 tvb,
156 offset,
157 length,
158 "Opcode Unknown 0x%02x",
159 tvb_get_guint8(tvb, (offset + 2)));
160 break;
167 /*-----------------------------------------------------------------------------
168 UA DISSECTOR
169 ---------------------------------------------------------------------------*/
170 static void _dissect_ua_msg(tvbuff_t *tvb,
171 packet_info *pinfo,
172 proto_tree *tree,
173 e_ua_direction direction)
175 gint offset = 0;
176 proto_item *ua_msg_item;
177 proto_tree *ua_msg_tree;
179 ua_msg_item = proto_tree_add_protocol_format(tree, proto_ua_msg, tvb, 0, -1,
180 "Universal Alcatel Protocol, %s",
181 ((direction == SYS_TO_TERM) ?
182 "System -> Terminal" : "Terminal -> System"));
184 ua_msg_tree = proto_item_add_subtree(ua_msg_item, ett_ua_msg);
186 while (tvb_offset_exists(tvb, offset))
188 gint length;
189 gint opcode;
191 length = tvb_get_letohs(tvb, offset) + 2;
192 opcode = tvb_get_guint8(tvb, offset+2);
194 /* RTP/RTCP conversation setup */
195 if (setup_conversations_enabled && (opcode==0x13) && (tvb_get_guint8(tvb, offset+3)==0x01))
197 address remote_rtp_addr;
198 guint32 remote_rtp_port;
199 gint suboffset;
201 remote_rtp_addr.data = NULL;
202 remote_rtp_port = 0;
204 /* StartRTP */
205 suboffset = offset + 5;
207 while (suboffset < offset+length)
209 switch (tvb_get_guint8(tvb, suboffset))
211 case 0x00: /* local port */
213 /*local_rtp_port = tvb_get_ntohs(tvb, suboffset+2);*/
214 break;
216 case 0x01: /* remote IP */
218 remote_rtp_addr.type = AT_IPv4;
219 remote_rtp_addr.len = 4;
220 remote_rtp_addr.data = tvb_get_ptr(tvb, suboffset+2, 4);
221 break;
223 case 0x02: /* remote port */
225 remote_rtp_port = tvb_get_ntohs(tvb, suboffset+2);
226 break;
230 suboffset += tvb_get_guint8(tvb, suboffset+1) + 2;
233 if ((remote_rtp_addr.data != NULL) && (remote_rtp_port != 0))
235 rtp_add_address(pinfo, &remote_rtp_addr, remote_rtp_port, 0,
236 "UA", pinfo->fd->num, 0, NULL);
237 rtcp_add_address(pinfo, &remote_rtp_addr, remote_rtp_port+1, 0,
238 "UA", pinfo->fd->num);
242 uadecode(direction, ua_msg_tree, pinfo, tvb, offset, opcode, length);
244 offset += length;
249 static void dissect_ua_sys_to_term(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
251 _dissect_ua_msg(tvb, pinfo, tree, SYS_TO_TERM);
254 static void dissect_ua_term_to_sys(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
256 _dissect_ua_msg(tvb, pinfo, tree, TERM_TO_SYS);
260 /*-----------------------------------------------------------------------------
261 DISSECTORS REGISTRATION FUNCTIONS
262 ---------------------------------------------------------------------------*/
264 void proto_register_ua_msg(void)
266 module_t *ua_msg_module;
268 static gint *ett[] =
270 &ett_ua_msg,
273 /* UA dissector registration */
274 proto_ua_msg = proto_register_protocol("Universal Alcatel Protocol", "UA", "ua");
276 register_dissector("ua_sys_to_term", dissect_ua_sys_to_term, proto_ua_msg);
277 register_dissector("ua_term_to_sys", dissect_ua_term_to_sys, proto_ua_msg);
279 /* Common subtree array registration */
280 proto_register_subtree_array(ett, array_length(ett));
282 /* Register preferences */
283 ua_msg_module = prefs_register_protocol(proto_ua_msg, NULL);
285 prefs_register_bool_preference(ua_msg_module, "setup_conversations",
286 "Setup RTP/RTCP conversations on Start RTP",
287 "Setup RTP/RTCP conversations when parsing Start RTP messages",
288 &setup_conversations_enabled);
291 void proto_reg_handoff_ua_msg(void)
293 #if 0 /* Future */
294 dissector_handle_t handle_ua_msg;
296 /* hooking of UA on UAUDP */
297 /* XXX: The following is NG since the same 'pattern' is added twice */
298 handle_ua_msg = find_dissector("ua_sys_to_term");
299 dissector_add_uint("uaudp.opcode", UAUDP_DATA, handle_ua_msg);
301 handle_ua_msg = find_dissector("ua_term_to_sys");
302 dissector_add_uint("uaudp.opcode", UAUDP_DATA, handle_ua_msg);
304 /* For hooking dissectors to UA */
305 ua_opcode_dissector_table =
306 register_dissector_table("ua.opcode",
307 "ua.opcode",
308 FT_UINT8,
309 BASE_HEX);
312 #endif
313 noe_handle = find_dissector("noe");
314 ua3g_handle = find_dissector("ua3g");