1 /* packet-turnchannel.c
2 * Routines for TURN channel dissection (TURN negociation is handled
3 * in the STUN2 dissector
4 * Copyright 2008, 8x8 Inc. <petithug@8x8.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Please refer to the following specs for protocol detail:
25 * - draft-ietf-behave-rfc3489bis-15
26 * - draft-ietf-mmusic-ice-19
27 * - draft-ietf-behave-nat-behavior-discovery-03
28 * - draft-ietf-behave-turn-07
29 * - draft-ietf-behave-turn-ipv6-03
34 #include <epan/packet.h>
35 #include "packet-tcp.h"
37 void proto_register_turnchannel(void);
38 void proto_reg_handoff_turnchannel(void);
40 /* heuristic subdissectors */
41 static heur_dissector_list_t heur_subdissector_list;
43 /* data dissector handle */
44 static dissector_handle_t data_handle;
46 /* Initialize the protocol and registered fields */
47 static int proto_turnchannel = -1;
49 static int hf_turnchannel_id = -1;
50 static int hf_turnchannel_len = -1;
52 #define TURNCHANNEL_HDR_LEN ((guint)4)
55 /* Initialize the subtree pointers */
56 static gint ett_turnchannel = -1;
59 dissect_turnchannel_message(tvbuff_t *tvb, packet_info *pinfo,
60 proto_tree *tree, void *data _U_)
66 proto_tree *turnchannel_tree;
67 heur_dtbl_entry_t *hdtbl_entry;
69 len = tvb_captured_length(tvb);
70 /* First, make sure we have enough data to do the check. */
71 if (len < TURNCHANNEL_HDR_LEN) {
75 channel_id = tvb_get_ntohs(tvb, 0);
76 data_len = tvb_get_ntohs(tvb, 2);
78 if ((channel_id < 0x4000) || (channel_id > 0xFFFE)) {
82 if (len != TURNCHANNEL_HDR_LEN + data_len) {
86 /* Seems to be a decent TURN channel message */
87 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TURN CHANNEL");
89 col_add_fstr(pinfo->cinfo, COL_INFO, "Channel Id 0x%x", channel_id);
91 ti = proto_tree_add_item(tree, proto_turnchannel, tvb, 0, -1, ENC_NA);
93 turnchannel_tree = proto_item_add_subtree(ti, ett_turnchannel);
95 proto_tree_add_uint(turnchannel_tree, hf_turnchannel_id, tvb, 0, 2, channel_id);
96 proto_tree_add_uint(turnchannel_tree, hf_turnchannel_len, tvb, 2, 2, data_len);
99 if (len > TURNCHANNEL_HDR_LEN) {
101 guint reported_len, new_len;
103 new_len = tvb_captured_length_remaining(tvb, TURNCHANNEL_HDR_LEN);
104 reported_len = tvb_reported_length_remaining(tvb,
105 TURNCHANNEL_HDR_LEN);
106 if (data_len < reported_len) {
107 reported_len = data_len;
109 next_tvb = tvb_new_subset(tvb, TURNCHANNEL_HDR_LEN, new_len,
113 if (!dissector_try_heuristic(heur_subdissector_list,
114 next_tvb, pinfo, tree, &hdtbl_entry, NULL)) {
115 call_dissector(data_handle,next_tvb, pinfo, tree);
119 return tvb_captured_length(tvb);
123 get_turnchannel_message_len(packet_info *pinfo _U_, tvbuff_t *tvb,
124 int offset, void *data _U_)
126 return (guint)tvb_get_ntohs(tvb, offset+2) + TURNCHANNEL_HDR_LEN;
130 dissect_turnchannel_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
132 tcp_dissect_pdus(tvb, pinfo, tree, TRUE, TURNCHANNEL_HDR_LEN,
133 get_turnchannel_message_len, dissect_turnchannel_message, data);
134 return tvb_captured_length(tvb);
139 dissect_turnchannel_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
145 len = tvb_captured_length(tvb);
146 /* First, make sure we have enough data to do the check. */
147 if (len < TURNCHANNEL_HDR_LEN) {
151 channel_id = tvb_get_ntohs(tvb, 0);
152 data_len = tvb_get_ntohs(tvb, 2);
154 if ((channel_id < 0x4000) || (channel_id > 0xFFFE)) {
158 if (len != TURNCHANNEL_HDR_LEN + data_len) {
162 return dissect_turnchannel_message(tvb, pinfo, tree, NULL);
166 proto_register_turnchannel(void)
168 static hf_register_info hf[] = {
169 { &hf_turnchannel_id,
170 { "TURN Channel ID", "turnchannel.id", FT_UINT16,
171 BASE_HEX, NULL, 0x0, NULL, HFILL }
173 { &hf_turnchannel_len,
174 { "Data Length", "turnchannel.length", FT_UINT16,
175 BASE_DEC, NULL, 0x0, NULL, HFILL }
179 /* Setup protocol subtree array */
180 static gint *ett[] = {
184 /* Register the protocol name and description */
185 proto_turnchannel = proto_register_protocol("TURN Channel",
186 "TURNCHANNEL", "turnchannel");
188 new_register_dissector("turnchannel", dissect_turnchannel_message,
192 heur_subdissector_list = register_heur_dissector_list("turnchannel");
194 /* Required function calls to register the header fields and subtrees used */
195 proto_register_field_array(proto_turnchannel, hf, array_length(hf));
196 proto_register_subtree_array(ett, array_length(ett));
202 proto_reg_handoff_turnchannel(void)
204 dissector_handle_t turnchannel_tcp_handle;
205 dissector_handle_t turnchannel_udp_handle;
207 turnchannel_tcp_handle = create_dissector_handle(dissect_turnchannel_tcp, proto_turnchannel);
208 turnchannel_udp_handle = find_dissector("turnchannel");
210 /* Register for "Decode As" in case STUN negotiation isn't captured */
211 dissector_add_for_decode_as("tcp.port", turnchannel_tcp_handle);
212 dissector_add_for_decode_as("udp.port", turnchannel_udp_handle);
214 /* TURN negotiation is handled through STUN2 dissector (packet-stun.c),
215 so only it should be able to determine if a packet is a TURN packet */
216 heur_dissector_add("stun", dissect_turnchannel_heur, "TURN Channel over STUN", "turnchannel_stun", proto_turnchannel, HEURISTIC_ENABLE);
218 data_handle = find_dissector("data");
222 * Editor modelines - http://www.wireshark.org/tools/modelines.html
227 * indent-tabs-mode: t
230 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
231 * :indentSize=8:tabSize=8:noTabs=false: