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>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * Please refer to the following specs for protocol detail:
27 * - draft-ietf-behave-rfc3489bis-15
28 * - draft-ietf-mmusic-ice-19
29 * - draft-ietf-behave-nat-behavior-discovery-03
30 * - draft-ietf-behave-turn-07
31 * - draft-ietf-behave-turn-ipv6-03
44 #include <epan/packet.h>
45 #include <epan/conversation.h>
46 #include <packet-tcp.h>
48 /* heuristic subdissectors */
49 static heur_dissector_list_t heur_subdissector_list;
51 /* data dissector handle */
52 static dissector_handle_t data_handle;
54 /* Initialize the protocol and registered fields */
55 static int proto_turnchannel = -1;
57 static int hf_turnchannel_id = -1;
58 static int hf_turnchannel_len = -1;
60 /* Structure containing conversation specific information */
61 typedef struct _turn2_conv_info_t {
65 /* Structure containing transaction specific information */
66 typedef struct _turnchannel_t {
71 #define TURNCHANNEL_HDR_LEN ((guint)4)
75 /* Initialize the subtree pointers */
76 static gint ett_turnchannel = -1;
79 dissect_turnchannel_message(tvbuff_t *tvb, packet_info *pinfo,
86 proto_tree *turnchannel_tree;
88 len = tvb_length(tvb);
89 /* First, make sure we have enough data to do the check. */
90 if (len < TURNCHANNEL_HDR_LEN) {
94 channel_id = tvb_get_ntohs(tvb, 0);
95 data_len = tvb_get_ntohs(tvb, 2);
97 if ((channel_id < 0x4000) || (channel_id > 0xFFFE)) {
101 if (len != TURNCHANNEL_HDR_LEN + data_len) {
105 /* Seems to be a decent TURN channel message */
106 if (check_col(pinfo->cinfo, COL_PROTOCOL))
107 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TURN CHANNEL");
109 if (check_col(pinfo->cinfo, COL_INFO))
110 col_add_fstr(pinfo->cinfo, COL_INFO, "Channel Id 0x%x", channel_id);
115 ti = proto_tree_add_item(tree, proto_turnchannel, tvb, 0, -1, FALSE);
117 turnchannel_tree = proto_item_add_subtree(ti, ett_turnchannel);
119 proto_tree_add_uint(turnchannel_tree, hf_turnchannel_id, tvb, 0, 2, channel_id);
120 proto_tree_add_uint(turnchannel_tree, hf_turnchannel_len, tvb, 2, 2, data_len);
123 if (len > TURNCHANNEL_HDR_LEN) {
125 guint reported_len, new_len;
127 new_len = tvb_length_remaining(tvb, TURNCHANNEL_HDR_LEN);
128 reported_len = tvb_reported_length_remaining(tvb,
129 TURNCHANNEL_HDR_LEN);
130 if (data_len < reported_len) {
131 reported_len = data_len;
133 next_tvb = tvb_new_subset(tvb, TURNCHANNEL_HDR_LEN, new_len,
137 if (!dissector_try_heuristic(heur_subdissector_list,
138 next_tvb, pinfo, tree)) {
139 call_dissector(data_handle,next_tvb, pinfo, tree);
148 dissect_turnchannel_message_no_return(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
150 dissect_turnchannel_message(tvb, pinfo, tree);
155 get_turnchannel_message_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
157 return (guint)tvb_get_ntohs(tvb, offset+2) + TURNCHANNEL_HDR_LEN;
161 dissect_turnchannel_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
163 tcp_dissect_pdus(tvb, pinfo, tree, TRUE, TURNCHANNEL_HDR_LEN,
164 get_turnchannel_message_len, dissect_turnchannel_message_no_return);
169 dissect_turnchannel_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
175 len = tvb_length(tvb);
176 /* First, make sure we have enough data to do the check. */
177 if (len < TURNCHANNEL_HDR_LEN) {
181 channel_id = tvb_get_ntohs(tvb, 0);
182 data_len = tvb_get_ntohs(tvb, 2);
184 if ((channel_id < 0x4000) || (channel_id > 0xFFFE)) {
188 if (len != TURNCHANNEL_HDR_LEN + data_len) {
192 return dissect_turnchannel_message(tvb, pinfo, tree);
196 proto_register_turnchannel(void)
198 static hf_register_info hf[] = {
199 { &hf_turnchannel_id,
200 { "TURN Channel ID", "turnchannel.id", FT_UINT16,
201 BASE_HEX, NULL, 0x0, "", HFILL }
203 { &hf_turnchannel_len,
204 { "Data Length", "turnchannel.length", FT_UINT16,
205 BASE_DEC, NULL, 0x0, "", HFILL }
209 /* Setup protocol subtree array */
210 static gint *ett[] = {
214 /* Register the protocol name and description */
215 proto_turnchannel = proto_register_protocol("TURN Channel",
216 "TURNCHANNEL", "turnchannel");
218 register_dissector("turnchannel", dissect_turnchannel_message,
222 register_heur_dissector_list("turnchannel", &heur_subdissector_list);
224 /* Required function calls to register the header fields and subtrees used */
225 proto_register_field_array(proto_turnchannel, hf, array_length(hf));
226 proto_register_subtree_array(ett, array_length(ett));
232 proto_reg_handoff_turnchannel(void)
234 dissector_handle_t turnchannel_tcp_handle;
235 dissector_handle_t turnchannel_udp_handle;
237 turnchannel_tcp_handle = create_dissector_handle(dissect_turnchannel_tcp, proto_turnchannel);
238 turnchannel_udp_handle = new_create_dissector_handle(dissect_turnchannel_message, proto_turnchannel);
240 dissector_add("tcp.port", 0, turnchannel_tcp_handle);
241 dissector_add("udp.port", 0, turnchannel_udp_handle);
243 heur_dissector_add("udp", dissect_turnchannel_heur, proto_turnchannel);
244 heur_dissector_add("tcp", dissect_turnchannel_heur, proto_turnchannel);
246 data_handle = find_dissector("data");