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
36 #include <epan/packet.h>
37 #include <packet-tcp.h>
39 void proto_register_turnchannel(void);
40 void proto_reg_handoff_turnchannel(void);
42 /* heuristic subdissectors */
43 static heur_dissector_list_t heur_subdissector_list;
45 /* data dissector handle */
46 static dissector_handle_t data_handle;
48 /* Initialize the protocol and registered fields */
49 static int proto_turnchannel = -1;
51 static int hf_turnchannel_id = -1;
52 static int hf_turnchannel_len = -1;
54 #define TURNCHANNEL_HDR_LEN ((guint)4)
57 /* Initialize the subtree pointers */
58 static gint ett_turnchannel = -1;
61 dissect_turnchannel_message(tvbuff_t *tvb, packet_info *pinfo,
62 proto_tree *tree, void *data _U_)
68 proto_tree *turnchannel_tree;
69 heur_dtbl_entry_t *hdtbl_entry;
71 len = tvb_length(tvb);
72 /* First, make sure we have enough data to do the check. */
73 if (len < TURNCHANNEL_HDR_LEN) {
77 channel_id = tvb_get_ntohs(tvb, 0);
78 data_len = tvb_get_ntohs(tvb, 2);
80 if ((channel_id < 0x4000) || (channel_id > 0xFFFE)) {
84 if (len != TURNCHANNEL_HDR_LEN + data_len) {
88 /* Seems to be a decent TURN channel message */
89 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TURN CHANNEL");
91 col_add_fstr(pinfo->cinfo, COL_INFO, "Channel Id 0x%x", channel_id);
93 ti = proto_tree_add_item(tree, proto_turnchannel, tvb, 0, -1, ENC_NA);
95 turnchannel_tree = proto_item_add_subtree(ti, ett_turnchannel);
97 proto_tree_add_uint(turnchannel_tree, hf_turnchannel_id, tvb, 0, 2, channel_id);
98 proto_tree_add_uint(turnchannel_tree, hf_turnchannel_len, tvb, 2, 2, data_len);
101 if (len > TURNCHANNEL_HDR_LEN) {
103 guint reported_len, new_len;
105 new_len = tvb_length_remaining(tvb, TURNCHANNEL_HDR_LEN);
106 reported_len = tvb_reported_length_remaining(tvb,
107 TURNCHANNEL_HDR_LEN);
108 if (data_len < reported_len) {
109 reported_len = data_len;
111 next_tvb = tvb_new_subset(tvb, TURNCHANNEL_HDR_LEN, new_len,
115 if (!dissector_try_heuristic(heur_subdissector_list,
116 next_tvb, pinfo, tree, &hdtbl_entry, NULL)) {
117 call_dissector(data_handle,next_tvb, pinfo, tree);
121 return tvb_length(tvb);
125 get_turnchannel_message_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
127 return (guint)tvb_get_ntohs(tvb, offset+2) + TURNCHANNEL_HDR_LEN;
131 dissect_turnchannel_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
133 tcp_dissect_pdus(tvb, pinfo, tree, TRUE, TURNCHANNEL_HDR_LEN,
134 get_turnchannel_message_len, dissect_turnchannel_message, data);
135 return tvb_length(tvb);
140 dissect_turnchannel_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
146 len = tvb_length(tvb);
147 /* First, make sure we have enough data to do the check. */
148 if (len < TURNCHANNEL_HDR_LEN) {
152 channel_id = tvb_get_ntohs(tvb, 0);
153 data_len = tvb_get_ntohs(tvb, 2);
155 if ((channel_id < 0x4000) || (channel_id > 0xFFFE)) {
159 if (len != TURNCHANNEL_HDR_LEN + data_len) {
163 return dissect_turnchannel_message(tvb, pinfo, tree, NULL);
167 proto_register_turnchannel(void)
169 static hf_register_info hf[] = {
170 { &hf_turnchannel_id,
171 { "TURN Channel ID", "turnchannel.id", FT_UINT16,
172 BASE_HEX, NULL, 0x0, NULL, HFILL }
174 { &hf_turnchannel_len,
175 { "Data Length", "turnchannel.length", FT_UINT16,
176 BASE_DEC, NULL, 0x0, NULL, HFILL }
180 /* Setup protocol subtree array */
181 static gint *ett[] = {
185 /* Register the protocol name and description */
186 proto_turnchannel = proto_register_protocol("TURN Channel",
187 "TURNCHANNEL", "turnchannel");
189 new_register_dissector("turnchannel", dissect_turnchannel_message,
193 heur_subdissector_list = register_heur_dissector_list("turnchannel");
195 /* Required function calls to register the header fields and subtrees used */
196 proto_register_field_array(proto_turnchannel, hf, array_length(hf));
197 proto_register_subtree_array(ett, array_length(ett));
203 proto_reg_handoff_turnchannel(void)
205 dissector_handle_t turnchannel_tcp_handle;
206 dissector_handle_t turnchannel_udp_handle;
208 turnchannel_tcp_handle = new_create_dissector_handle(dissect_turnchannel_tcp, proto_turnchannel);
209 turnchannel_udp_handle = find_dissector("turnchannel");
211 /* Register for "Decode As" in case STUN negotiation isn't captured */
212 dissector_add_for_decode_as("tcp.port", turnchannel_tcp_handle);
213 dissector_add_for_decode_as("udp.port", turnchannel_udp_handle);
215 /* TURN negotiation is handled through STUN2 dissector (packet-stun.c),
216 so only it should be able to determine if a packet is a TURN packet */
217 heur_dissector_add("stun", dissect_turnchannel_heur, proto_turnchannel);
219 data_handle = find_dissector("data");
223 * Editor modelines - http://www.wireshark.org/tools/modelines.html
228 * indent-tabs-mode: t
231 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
232 * :indentSize=8:tabSize=8:noTabs=false: