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 <packet-tcp.h>
47 /* heuristic subdissectors */
48 static heur_dissector_list_t heur_subdissector_list;
50 /* data dissector handle */
51 static dissector_handle_t data_handle;
53 /* Initialize the protocol and registered fields */
54 static int proto_turnchannel = -1;
56 static int hf_turnchannel_id = -1;
57 static int hf_turnchannel_len = -1;
59 #define TURNCHANNEL_HDR_LEN ((guint)4)
62 /* Initialize the subtree pointers */
63 static gint ett_turnchannel = -1;
66 dissect_turnchannel_message(tvbuff_t *tvb, packet_info *pinfo,
73 proto_tree *turnchannel_tree;
75 len = tvb_length(tvb);
76 /* First, make sure we have enough data to do the check. */
77 if (len < TURNCHANNEL_HDR_LEN) {
81 channel_id = tvb_get_ntohs(tvb, 0);
82 data_len = tvb_get_ntohs(tvb, 2);
84 if ((channel_id < 0x4000) || (channel_id > 0xFFFE)) {
88 if (len != TURNCHANNEL_HDR_LEN + data_len) {
92 /* Seems to be a decent TURN channel message */
93 if (check_col(pinfo->cinfo, COL_PROTOCOL))
94 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TURN CHANNEL");
96 if (check_col(pinfo->cinfo, COL_INFO))
97 col_add_fstr(pinfo->cinfo, COL_INFO, "Channel Id 0x%x", channel_id);
100 return tvb_length(tvb);
102 ti = proto_tree_add_item(tree, proto_turnchannel, tvb, 0, -1, FALSE);
104 turnchannel_tree = proto_item_add_subtree(ti, ett_turnchannel);
106 proto_tree_add_uint(turnchannel_tree, hf_turnchannel_id, tvb, 0, 2, channel_id);
107 proto_tree_add_uint(turnchannel_tree, hf_turnchannel_len, tvb, 2, 2, data_len);
110 if (len > TURNCHANNEL_HDR_LEN) {
112 guint reported_len, new_len;
114 new_len = tvb_length_remaining(tvb, TURNCHANNEL_HDR_LEN);
115 reported_len = tvb_reported_length_remaining(tvb,
116 TURNCHANNEL_HDR_LEN);
117 if (data_len < reported_len) {
118 reported_len = data_len;
120 next_tvb = tvb_new_subset(tvb, TURNCHANNEL_HDR_LEN, new_len,
124 if (!dissector_try_heuristic(heur_subdissector_list,
125 next_tvb, pinfo, tree)) {
126 call_dissector(data_handle,next_tvb, pinfo, tree);
130 return tvb_length(tvb);
135 dissect_turnchannel_message_no_return(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
137 dissect_turnchannel_message(tvb, pinfo, tree);
142 get_turnchannel_message_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
144 return (guint)tvb_get_ntohs(tvb, offset+2) + TURNCHANNEL_HDR_LEN;
148 dissect_turnchannel_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
150 tcp_dissect_pdus(tvb, pinfo, tree, TRUE, TURNCHANNEL_HDR_LEN,
151 get_turnchannel_message_len, dissect_turnchannel_message_no_return);
156 dissect_turnchannel_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
162 len = tvb_length(tvb);
163 /* First, make sure we have enough data to do the check. */
164 if (len < TURNCHANNEL_HDR_LEN) {
168 channel_id = tvb_get_ntohs(tvb, 0);
169 data_len = tvb_get_ntohs(tvb, 2);
171 if ((channel_id < 0x4000) || (channel_id > 0xFFFE)) {
175 if (len != TURNCHANNEL_HDR_LEN + data_len) {
179 return dissect_turnchannel_message(tvb, pinfo, tree);
183 proto_register_turnchannel(void)
185 static hf_register_info hf[] = {
186 { &hf_turnchannel_id,
187 { "TURN Channel ID", "turnchannel.id", FT_UINT16,
188 BASE_HEX, NULL, 0x0, NULL, HFILL }
190 { &hf_turnchannel_len,
191 { "Data Length", "turnchannel.length", FT_UINT16,
192 BASE_DEC, NULL, 0x0, NULL, HFILL }
196 /* Setup protocol subtree array */
197 static gint *ett[] = {
201 /* Register the protocol name and description */
202 proto_turnchannel = proto_register_protocol("TURN Channel",
203 "TURNCHANNEL", "turnchannel");
205 new_register_dissector("turnchannel", dissect_turnchannel_message,
209 register_heur_dissector_list("turnchannel", &heur_subdissector_list);
211 /* Required function calls to register the header fields and subtrees used */
212 proto_register_field_array(proto_turnchannel, hf, array_length(hf));
213 proto_register_subtree_array(ett, array_length(ett));
219 proto_reg_handoff_turnchannel(void)
221 dissector_handle_t turnchannel_tcp_handle;
222 dissector_handle_t turnchannel_udp_handle;
224 turnchannel_tcp_handle = create_dissector_handle(dissect_turnchannel_tcp, proto_turnchannel);
225 turnchannel_udp_handle = find_dissector("turnchannel");
227 dissector_add_handle("tcp.port", turnchannel_tcp_handle); /* for decode-as */
228 dissector_add_handle("udp.port", turnchannel_udp_handle); /* ... */
230 heur_dissector_add("udp", dissect_turnchannel_heur, proto_turnchannel);
231 heur_dissector_add("tcp", dissect_turnchannel_heur, proto_turnchannel);
233 data_handle = find_dissector("data");