3 * Routines for the RTCWeb Data Channel Protocol dissection
5 * http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-03
6 * and the upcoming version specified in
7 * http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-00
8 * We might want to remove the support of
9 * http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-03
10 * in the future, but I'll leave it in for now.
11 * Copyright 2012 - 2013, Michael Tuexen <tuexen@wireshark.org>
15 * Wireshark - Network traffic analyzer
16 * By Gerald Combs <gerald@wireshark.org>
17 * Copyright 1998 Gerald Combs
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38 #include <epan/expert.h>
39 #include <epan/packet.h>
40 #include <epan/prefs.h>
41 #include <epan/sctpppids.h>
43 void proto_reg_handoff_rtcdc(void);
45 /* PPID used for this protocol */
46 static guint32 rtcdc_ppid
= WEBRTC_CONTROL_PAYLOAD_PROTOCOL_ID
;
48 /* Initialize the protocol and registered fields */
49 static int proto_rtcdc
= -1;
50 static int hf_message_type
= -1;
51 static int hf_channel_type
= -1;
52 static int hf_flags
= -1;
53 static int hf_flags_reserved
= -1;
54 static int hf_unordered_allowed
= -1;
55 static int hf_reliability
= -1;
56 static int hf_priority
= -1;
57 static int hf_label
= -1;
58 static int hf_error
= -1;
59 static int hf_sid
= -1;
60 static int hf_new_channel_type
= -1;
61 static int hf_new_reliability
= -1;
62 static int hf_new_priority
= -1;
63 static int hf_new_label_length
= -1;
64 static int hf_new_protocol_length
= -1;
65 static int hf_new_label
= -1;
66 static int hf_new_protocol
= -1;
68 /* Initialize the subtree pointers */
69 static gint ett_rtcdc
= -1;
70 static gint ett_flags
= -1;
72 static expert_field ei_rtcdc_new_reliability_non_zero
= EI_INIT
;
73 static expert_field ei_rtcdc_message_type_unknown
= EI_INIT
;
74 static expert_field ei_rtcdc_inconsistent_label_and_parameter_length
= EI_INIT
;
75 static expert_field ei_rtcdc_message_too_long
= EI_INIT
;
76 static expert_field ei_rtcdc_new_channel_type
= EI_INIT
;
78 #define DATA_CHANNEL_OPEN_REQUEST 0x00
79 #define DATA_CHANNEL_OPEN_RESPONSE 0x01
80 #define DATA_CHANNEL_ACK 0x02
81 #define DATA_CHANNEL_NEW_OPEN_REQUEST 0x03
83 static const value_string message_type_values
[] = {
84 { DATA_CHANNEL_OPEN_REQUEST
, "DATA_CHANNEL_OPEN_REQUEST" },
85 { DATA_CHANNEL_OPEN_RESPONSE
, "DATA_CHANNEL_OPEN_RESPONSE" },
86 { DATA_CHANNEL_ACK
, "DATA_CHANNEL_ACK" },
87 { DATA_CHANNEL_NEW_OPEN_REQUEST
, "DATA_CHANNEL_OPEN_REQUEST" },
91 #define DATA_CHANNEL_RELIABLE 0x00
92 #define DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT 0x01
93 #define DATA_CHANNEL_PARTIAL_RELIABLE_TIMED 0x02
95 static const value_string channel_type_values
[] = {
96 { DATA_CHANNEL_RELIABLE
, "DATA_CHANNEL_RELIABLE" },
97 { DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT
, "DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT" },
98 { DATA_CHANNEL_PARTIAL_RELIABLE_TIMED
, "DATA_CHANNEL_PARTIAL_RELIABLE_TIMED" },
102 #define MESSAGE_TYPE_LENGTH 1
103 #define CHANNEL_TYPE_LENGTH 1
104 #define FLAGS_LENGTH 2
105 #define RELIABILITY_LENGTH 2
106 #define PRIORITY_LENGTH 2
108 #define MESSAGE_TYPE_OFFSET 0
109 #define CHANNEL_TYPE_OFFSET (MESSAGE_TYPE_OFFSET + MESSAGE_TYPE_LENGTH)
110 #define FLAGS_OFFSET (CHANNEL_TYPE_OFFSET + CHANNEL_TYPE_LENGTH)
111 #define RELIABILITY_OFFSET (FLAGS_OFFSET + FLAGS_LENGTH)
112 #define PRIORITY_OFFSET (RELIABILITY_OFFSET + RELIABILITY_LENGTH)
113 #define LABEL_OFFSET (PRIORITY_OFFSET + PRIORITY_LENGTH)
115 #define DATA_CHANNEL_FLAG_OUT_OF_ORDER_ALLOWED_MASK 0x0001
116 #define DATA_CHANNEL_FLAG_RESERVED_MASK 0xFFFE
119 dissect_open_request_message(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*rtcdc_tree
, proto_item
*rtcdc_item _U_
)
122 proto_tree
*flags_tree
;
123 proto_item
*flags_item
;
125 proto_tree_add_item(rtcdc_tree
, hf_channel_type
, tvb
, CHANNEL_TYPE_OFFSET
, CHANNEL_TYPE_LENGTH
, ENC_BIG_ENDIAN
);
126 flags_item
= proto_tree_add_item(rtcdc_tree
, hf_flags
, tvb
, FLAGS_OFFSET
, FLAGS_LENGTH
, ENC_BIG_ENDIAN
);
127 flags_tree
= proto_item_add_subtree(flags_item
, ett_flags
);
128 proto_tree_add_item(flags_tree
, hf_flags_reserved
, tvb
, FLAGS_OFFSET
, FLAGS_LENGTH
, ENC_BIG_ENDIAN
);
129 proto_tree_add_item(flags_tree
, hf_unordered_allowed
, tvb
, FLAGS_OFFSET
, FLAGS_LENGTH
, ENC_BIG_ENDIAN
);
130 proto_tree_add_item(rtcdc_tree
, hf_reliability
, tvb
, RELIABILITY_OFFSET
, RELIABILITY_LENGTH
, ENC_BIG_ENDIAN
);
131 proto_tree_add_item(rtcdc_tree
, hf_priority
, tvb
, PRIORITY_OFFSET
, PRIORITY_LENGTH
, ENC_BIG_ENDIAN
);
132 proto_tree_add_item(rtcdc_tree
, hf_label
, tvb
, LABEL_OFFSET
, -1, ENC_BIG_ENDIAN
);
137 #define ERROR_LENGTH 1
139 #define DATA_CHANNEL_RESPONSE_LENGTH (MESSAGE_TYPE_LENGTH + ERROR_LENGTH + FLAGS_LENGTH + SID_LENGTH)
141 #define ERROR_OFFSET (MESSAGE_TYPE_OFFSET + MESSAGE_TYPE_LENGTH)
142 #define SID_OFFSET (FLAGS_OFFSET + FLAGS_LENGTH)
145 dissect_open_response_message(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*rtcdc_tree
, proto_item
*rtcdc_item
)
147 if (tvb_length(tvb
) > DATA_CHANNEL_RESPONSE_LENGTH
) {
148 expert_add_info(pinfo
, rtcdc_item
, &ei_rtcdc_message_too_long
);
151 proto_tree_add_item(rtcdc_tree
, hf_error
, tvb
, ERROR_OFFSET
, ERROR_LENGTH
, ENC_BIG_ENDIAN
);
152 proto_tree_add_item(rtcdc_tree
, hf_flags
, tvb
, FLAGS_OFFSET
, FLAGS_LENGTH
, ENC_BIG_ENDIAN
);
153 proto_tree_add_item(rtcdc_tree
, hf_sid
, tvb
, SID_OFFSET
, SID_LENGTH
, ENC_BIG_ENDIAN
);
158 #define DATA_CHANNEL_ACK_LENGTH MESSAGE_TYPE_LENGTH
161 dissect_open_ack_message(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*rtcdc_tree _U_
, proto_item
*rtcdc_item
)
163 if (tvb_length(tvb
) > DATA_CHANNEL_ACK_LENGTH
) {
164 expert_add_info(pinfo
, rtcdc_item
, &ei_rtcdc_message_too_long
);
169 #define NEW_DATA_CHANNEL_RELIABLE 0x00
170 #define NEW_DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT 0x01
171 #define NEW_DATA_CHANNEL_PARTIAL_RELIABLE_TIMED 0x02
172 #define NEW_DATA_CHANNEL_RELIABLE_UNORDERED 0x80
173 #define NEW_DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT_UNORDERED 0x81
174 #define NEW_DATA_CHANNEL_PARTIAL_RELIABLE_TIMED_UNORDERED 0x82
176 static const value_string new_channel_type_values
[] = {
177 { NEW_DATA_CHANNEL_RELIABLE
, "DATA_CHANNEL_RELIABLE" },
178 { NEW_DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT
, "DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT" },
179 { NEW_DATA_CHANNEL_PARTIAL_RELIABLE_TIMED
, "DATA_CHANNEL_PARTIAL_RELIABLE_TIMED" },
180 { NEW_DATA_CHANNEL_RELIABLE_UNORDERED
, "DATA_CHANNEL_RELIABLE_UNORDERED" },
181 { NEW_DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT_UNORDERED
, "DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT_UNORDERED" },
182 { NEW_DATA_CHANNEL_PARTIAL_RELIABLE_TIMED_UNORDERED
, "DATA_CHANNEL_PARTIAL_RELIABLE_TIMED_UNORDERED" },
186 #define NEW_MESSAGE_TYPE_LENGTH 1
187 #define NEW_CHANNEL_TYPE_LENGTH 1
188 #define NEW_PRIORITY_LENGTH 2
189 #define NEW_RELIABILITY_LENGTH 4
190 #define NEW_LABEL_LENGTH_LENGTH 2
191 #define NEW_PROTOCOL_LENGTH_LENGTH 2
192 #define NEW_OPEN_REQUEST_HEADER_LENGTH (guint)(NEW_MESSAGE_TYPE_LENGTH + \
193 NEW_CHANNEL_TYPE_LENGTH + \
194 NEW_PRIORITY_LENGTH + \
195 NEW_RELIABILITY_LENGTH + \
196 NEW_LABEL_LENGTH_LENGTH + \
197 NEW_PROTOCOL_LENGTH_LENGTH)
199 #define NEW_MESSAGE_TYPE_OFFSET 0
200 #define NEW_CHANNEL_TYPE_OFFSET (NEW_MESSAGE_TYPE_OFFSET + NEW_MESSAGE_TYPE_LENGTH)
201 #define NEW_PRIORITY_OFFSET (NEW_CHANNEL_TYPE_OFFSET + NEW_CHANNEL_TYPE_LENGTH)
202 #define NEW_RELIABILITY_OFFSET (NEW_PRIORITY_OFFSET + NEW_PRIORITY_LENGTH)
203 #define NEW_LABEL_LENGTH_OFFSET (NEW_RELIABILITY_OFFSET + NEW_RELIABILITY_LENGTH)
204 #define NEW_PROTOCOL_LENGTH_OFFSET (NEW_LABEL_LENGTH_OFFSET + NEW_LABEL_LENGTH_LENGTH)
205 #define NEW_LABEL_OFFSET (NEW_PROTOCOL_LENGTH_OFFSET + NEW_PROTOCOL_LENGTH_LENGTH)
208 dissect_new_open_request_message(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*rtcdc_tree
, proto_item
*rtcdc_item
)
213 guint16 label_length
;
214 guint16 protocol_length
;
216 proto_tree_add_item(rtcdc_tree
, hf_new_channel_type
, tvb
, NEW_CHANNEL_TYPE_OFFSET
, NEW_CHANNEL_TYPE_LENGTH
, ENC_BIG_ENDIAN
);
217 channel_type
= tvb_get_guint8(tvb
, NEW_CHANNEL_TYPE_OFFSET
);
218 if ((channel_type
& 0x7f) > 0x02) {
219 expert_add_info(pinfo
, rtcdc_item
, &ei_rtcdc_new_channel_type
);
221 proto_tree_add_item(rtcdc_tree
, hf_new_priority
, tvb
, NEW_PRIORITY_OFFSET
, NEW_PRIORITY_LENGTH
, ENC_BIG_ENDIAN
);
222 proto_tree_add_item(rtcdc_tree
, hf_new_reliability
, tvb
, NEW_RELIABILITY_OFFSET
, NEW_RELIABILITY_LENGTH
, ENC_BIG_ENDIAN
);
223 reliability
= tvb_get_ntohl(tvb
, NEW_RELIABILITY_OFFSET
);
224 if ((reliability
> 0) && ((channel_type
& 0x80) == 0)) {
225 expert_add_info(pinfo
, rtcdc_item
, &ei_rtcdc_new_reliability_non_zero
);
227 proto_tree_add_item(rtcdc_tree
, hf_new_label_length
, tvb
, NEW_LABEL_LENGTH_OFFSET
, NEW_LABEL_LENGTH_LENGTH
, ENC_BIG_ENDIAN
);
228 proto_tree_add_item(rtcdc_tree
, hf_new_protocol_length
, tvb
, NEW_PROTOCOL_LENGTH_OFFSET
, NEW_PROTOCOL_LENGTH_LENGTH
, ENC_BIG_ENDIAN
);
229 label_length
= tvb_get_ntohs(tvb
, NEW_LABEL_LENGTH_OFFSET
);
230 protocol_length
= tvb_get_ntohs(tvb
, NEW_PROTOCOL_LENGTH_OFFSET
);
231 if (NEW_OPEN_REQUEST_HEADER_LENGTH
+ (guint
)label_length
+ (guint
)protocol_length
!= tvb_length(tvb
)) {
232 expert_add_info(pinfo
, rtcdc_item
, &ei_rtcdc_inconsistent_label_and_parameter_length
);
234 proto_tree_add_item(rtcdc_tree
, hf_new_label
, tvb
, NEW_LABEL_OFFSET
, label_length
, ENC_BIG_ENDIAN
);
235 proto_tree_add_item(rtcdc_tree
, hf_new_protocol
, tvb
, NEW_LABEL_OFFSET
+ label_length
, protocol_length
, ENC_BIG_ENDIAN
);
241 dissect_rtcdc(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
243 proto_item
*rtcdc_item
, *msg_item
;
244 proto_tree
*rtcdc_tree
;
247 message_type
= tvb_get_guint8(tvb
, MESSAGE_TYPE_OFFSET
);
249 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "RTCDC");
250 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s ", val_to_str_const(message_type
, message_type_values
, "reserved"));
251 rtcdc_item
= proto_tree_add_item(tree
, proto_rtcdc
, tvb
, 0, -1, ENC_NA
);
252 rtcdc_tree
= proto_item_add_subtree(rtcdc_item
, ett_rtcdc
);
253 msg_item
= proto_tree_add_item(rtcdc_tree
, hf_message_type
, tvb
, MESSAGE_TYPE_OFFSET
, MESSAGE_TYPE_LENGTH
, ENC_BIG_ENDIAN
);
255 switch (message_type
) {
256 case DATA_CHANNEL_OPEN_REQUEST
:
257 dissect_open_request_message(tvb
, pinfo
, rtcdc_tree
, rtcdc_item
);
259 case DATA_CHANNEL_OPEN_RESPONSE
:
260 dissect_open_response_message(tvb
, pinfo
, rtcdc_tree
, rtcdc_item
);
262 case DATA_CHANNEL_ACK
:
263 dissect_open_ack_message(tvb
, pinfo
, rtcdc_tree
, rtcdc_item
);
265 case DATA_CHANNEL_NEW_OPEN_REQUEST
:
266 dissect_new_open_request_message(tvb
, pinfo
, rtcdc_tree
, rtcdc_item
);
269 expert_add_info(pinfo
, msg_item
, &ei_rtcdc_message_type_unknown
);
272 return tvb_length(tvb
);
276 proto_register_rtcdc(void)
278 module_t
*rtcdc_module
;
279 expert_module_t
* expert_rtcdc
;
280 static hf_register_info hf
[] = {
281 { &hf_message_type
, { "Message type", "rtcdc.message_type", FT_UINT8
, BASE_DEC
, VALS(message_type_values
), 0x0, NULL
, HFILL
} },
282 { &hf_channel_type
, { "Channel type", "rtcdc.channel_type", FT_UINT8
, BASE_DEC
, VALS(channel_type_values
), 0x0, NULL
, HFILL
} },
283 { &hf_flags
, { "Flags", "rtcdc.flags", FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
} },
284 { &hf_flags_reserved
, { "Reserved", "rtcdc.flags_reserved", FT_UINT16
, BASE_HEX
, NULL
, DATA_CHANNEL_FLAG_RESERVED_MASK
, NULL
, HFILL
} },
285 { &hf_unordered_allowed
, { "Unordered allowed", "rtcdc.flags_unordered_allowed", FT_BOOLEAN
, 16, NULL
, DATA_CHANNEL_FLAG_OUT_OF_ORDER_ALLOWED_MASK
, NULL
, HFILL
} },
286 { &hf_reliability
, { "Reliability parameter", "rtcdc.reliability_parameter", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
287 { &hf_priority
, { "Priority", "rtcdc.priority", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
288 { &hf_label
, { "Label", "rtcdc.label", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
} },
289 { &hf_error
, { "Error", "rtcdc.error", FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
290 { &hf_sid
, { "Reverse stream identifier", "rtcdc.reverse_stream_id", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
291 { &hf_new_channel_type
, { "Channel type", "rtcdc.channel_type", FT_UINT8
, BASE_DEC
, VALS(new_channel_type_values
), 0x0, NULL
, HFILL
} },
292 { &hf_new_reliability
, { "Reliability parameter", "rtcdc.reliability_parameter", FT_UINT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
293 { &hf_new_priority
, { "Priority", "rtcdc.priority", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
294 { &hf_new_label_length
, { "Label length", "rtcdc.label_length", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
295 { &hf_new_protocol_length
, { "Protocol length", "rtcdc.protocol_length", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
296 { &hf_new_label
, { "Label", "rtcdc.label", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
} },
297 { &hf_new_protocol
, { "Protocol", "rtcdc.protocol", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
} }
299 static gint
*ett
[] = {
304 static ei_register_info ei
[] = {
305 { &ei_rtcdc_message_too_long
, { "rtcdc.message_too_long", PI_MALFORMED
, PI_ERROR
, "Message too long", EXPFILL
}},
306 { &ei_rtcdc_new_channel_type
, { "rtcdc.channel_type.unknown", PI_PROTOCOL
, PI_WARN
, "Unknown channel type", EXPFILL
}},
307 { &ei_rtcdc_new_reliability_non_zero
, { "rtcdc.reliability_parameter.non_zero", PI_PROTOCOL
, PI_WARN
, "Reliability parameter non zero for reliable channel", EXPFILL
}},
308 { &ei_rtcdc_inconsistent_label_and_parameter_length
, { "rtcdc.inconsistent_label_and_parameter_length", PI_MALFORMED
, PI_ERROR
, "Inconsistent label and parameter length", EXPFILL
}},
309 { &ei_rtcdc_message_type_unknown
, { "rtcdc.message_type.unknown", PI_PROTOCOL
, PI_WARN
, "Unknown message type", EXPFILL
}},
312 proto_rtcdc
= proto_register_protocol("WebRTC Datachannel Protocol", "RTCDC", "rtcdc");
313 proto_register_field_array(proto_rtcdc
, hf
, array_length(hf
));
314 proto_register_subtree_array(ett
, array_length(ett
));
315 expert_rtcdc
= expert_register_protocol(proto_rtcdc
);
316 expert_register_field_array(expert_rtcdc
, ei
, array_length(ei
));
317 rtcdc_module
= prefs_register_protocol(proto_rtcdc
, proto_reg_handoff_rtcdc
);
318 prefs_register_uint_preference(rtcdc_module
, "sctp.ppi", "RTCDC SCTP PPID", "RTCDC SCTP PPID if other than the default", 10, &rtcdc_ppid
);
322 proto_reg_handoff_rtcdc(void)
324 static gboolean initialized
= FALSE
;
325 static dissector_handle_t rtcdc_handle
;
326 static guint32 current_ppid
;
329 rtcdc_handle
= new_create_dissector_handle(dissect_rtcdc
, proto_rtcdc
);
332 dissector_delete_uint("sctp.ppi", current_ppid
, rtcdc_handle
);
334 current_ppid
= rtcdc_ppid
;
335 dissector_add_uint("sctp.ppi", current_ppid
, rtcdc_handle
);
339 * Editor modelines - http://www.wireshark.org/tools/modelines.html
344 * indent-tabs-mode: nil
347 * vi: set shiftwidth=4 tabstop=8 expandtab:
348 * :indentSize=4:tabSize=8:noTabs=true: