2 * Dissector for the RTI TCP Transport Protocol.
3 * Layer on top of TCP used to send Control messages
4 * to establish and maintain the connections as well as
7 * (c) 2005-2015 Copyright, Real-Time Innovations, Inc.
8 * Real-Time Innovations, Inc.
12 * Wireshark - Network traffic analyzer
13 * By Gerald Combs <gerald@wireshark.org>
14 * Copyright 1998 Gerald Combs
16 * SPDX-License-Identifier: GPL-2.0-or-later
21 #include <epan/packet.h>
22 #include <epan/expert.h>
23 #include <epan/prefs.h>
24 #include <epan/addr_resolv.h>
25 #include <epan/wmem_scopes.h>
26 #include <epan/conversation.h>
27 #include "packet-tcp.h"
29 #define RTITCP_MAGIC_NUMBER 0xdd54dd55
30 #define RTPS_MAGIC_NUMBER 0x52545053
31 #define RTITCP_CONTROL_MAGIC_COOKIE 0x2112A442
32 #define RTITCP_CRC_MAGIC_NUMBER 0x43524332
34 /* A sample #define of the minimum length (in bytes) of the protocol data.
35 * If data is received with fewer than this many bytes it is rejected by
36 * the current dissector. */
37 #define RTITCP_MIN_LENGTH 8
38 #define NUMBER_2E30 1073741824
40 #define IDENTITY_BIND_REQUEST (0x0C01)
41 #define IDENTITY_BIND_INDICATION (0x0C11)
42 #define IDENTITY_BIND_RESPONSE (0x0D01)
43 #define IDENTITY_BIND_ERROR (0x0D11)
45 #define SERVER_LOGICAL_PORT_REQUEST (0x0C02)
46 #define SERVER_LOGICAL_PORT_INDICATION (0x0C12)
47 #define SERVER_LOGICAL_PORT_RESPONSE (0x0D02)
48 #define SERVER_LOGICAL_PORT_ERROR (0x0D12)
50 #define CLIENT_LOGICAL_PORT_REQUEST (0x0C03)
51 #define CLIENT_LOGICAL_PORT_INDICATION (0x0C13)
52 #define CLIENT_LOGICAL_PORT_RESPONSE (0x0D03)
53 #define CLIENT_LOGICAL_PORT_ERROR (0x0D13)
55 #define CONNECTION_BIND_REQUEST (0x0C04)
56 #define CONNECTION_BIND_INDICATION (0x0C14)
57 #define CONNECTION_BIND_RESPONSE (0x0D04)
58 #define CONNECTION_BIND_ERROR (0x0D14)
60 #define SESSION_ID_REQUEST (0x0C05)
61 #define SESSION_ID_INDICATION (0x0C15)
62 #define SESSION_ID_RESPONSE (0x0D05)
63 #define SESSION_ID_ERROR (0x0D15)
65 #define LIVELINESS_REQUEST (0x0C06)
66 #define LIVELINESS_RESPONSE (0x0D06)
68 #define FINALIZE_SESSION_REQUEST (0x0C0F)
69 #define FINALIZE_SESSION_INDICATION (0x0C1F)
70 #define FINALIZE_SESSION_RESPONSE (0x0D0F)
71 #define FINALIZE_SESSION_ERRROR (0x0D1F)
73 #define LOCATOR_KIND_IPV4 (1)
74 #define LOCATOR_KIND_IPV6 (2)
76 #define RTPS_LOCATOR_ADDRESS_ATTRIBUTE_TYPE (0x3D01)
77 #define RTPS_LOCATOR_PORT_ATTRIBUTE_TYPE (0x3D02)
78 #define CONNECTION_TYPE_ATTRIBUTE_TYPE (0x3D03)
79 #define CONNECTION_COOKIE_ATTRIBUTE_TYPE (0x3D04)
80 #define PORT_OPTIONS_ATTRIBUTE_TYPE (0x3D05)
81 #define TRANSPORT_PRIORITY_ATTRIBUTE_TYPE (0x3D06)
82 #define SESSION_ID_ATTRIBUTE_TYPE (0x3D07)
84 #define MAPPED_ADDRESS_ATTRIBUTE_TYPE (0x0001)
85 #define XOR_MAPPED_ADDRESS_ATTRIBUTE_TYPE (0x0020)
86 #define ERROR_CODE_ATTRIBUTE_TYPE (0x0009)
87 #define UNKNOWN_ATTRIBUTES_ATTRIBUTE_TYPE (0x000A)
89 #define SOFTWARE_ATTRIBUTE_TYPE (0x8022)
90 #define ALTERNATE_SERVER_ATTRIBUTE_TYPE (0x8023)
92 #define CLASS_ID_TCPV4_LAN (0x00)
93 #define CLASS_ID_TCPV4_WAN (0x40)
94 #define CLASS_ID_TLSV4_LAN (0x80)
95 #define CLASS_ID_TLSV4_WAN (0xC0)
98 #define NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_OK 0
99 /* client requested a transport class not supported by the server */
100 #define NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_TRANSPORT_CLASS_MISMATCH 1
101 /* required attribute is missing */
102 #define NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_ATTRIBUTE_MISSING 2
103 /* no matching receive resource for requested port */
104 #define NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_NO_MATCHING_RECVRESOURCE 3
105 /* no matching cookie found on server */
106 #define NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_NO_MATCH_COOKIE 4
107 /* fatal internal processing error (caller is not responsible) */
108 #define NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_INTERNAL 5
109 /* the operation should be retried at the first occurrence */
110 #define NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_RETRY 6
111 #define NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_BAD_REQUEST_ID 400
112 #define NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_UNKNOWN_ATTRIBUTE_ID 420
113 #define NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_ALLOCATION_MISMATCH_ID 437
114 #define NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_UNSUPPORTED_TRANSPORT_PROTOCOL_ID 442
115 #define NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_CONNECTION_ALREADY_EXISTS_ID 446
116 #define NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_SERVER_ERROR_ID 500
118 /* Forward declaration that is needed below if using the
119 * proto_reg_handoff_rtitcp function as a callback for when protocol
120 * preferences get changed. For now we don't have preferences but we
121 * may have them in the future.*/
123 void proto_reg_handoff_rtitcp(void);
124 void proto_register_rtitcp(void);
126 /* Initialize the protocol and registered fields */
127 static int proto_rtitcp
;
128 static int hf_rtitcp_header_control_byte
;
129 static int hf_rtitcp_header_magic_number
;
130 static int hf_rtitcp_header_message_length
;
131 static int hf_rtitcp_control_transaction_id
;
132 static int hf_rtitcp_control_kind
;
133 static int hf_rtitcp_control_attribute_type
;
134 static int hf_rtitcp_control_attribute_length
;
135 static int hf_rtitcp_control_attribute_port
;
136 static int hf_rtitcp_attributes_list_length
;
137 static int hf_rtitcp_control_magic_cookie
;
138 static int hf_rtitcp_control_attribute_connection_cookie
;
139 static int hf_rtitcp_control_attribute_connection_type
;
140 static int hf_rtitcp_control_attribute_session_id
;
141 static int hf_rtitcp_control_attribute_error_code_value
;
142 static int hf_rtitcp_control_attribute_error_code_description
;
143 static int hf_rtitcp_locator_ipv4
;
144 static int hf_rtitcp_locator_port
;
145 static int hf_rtitcp_locator_ipv6
;
146 static int hf_rtitcp_locator_kind
;
147 static int hf_rtitcp_crc_magic_cookie
;
148 static int hf_rtitcp_control_crc_value
;
150 static int hf_rtitcp_response_in
;
151 static int hf_rtitcp_response_to
;
152 static int hf_rtitcp_response_time
;
154 #define RTITCP_FLAG_NOT_REQUEST 0x0100
156 typedef struct _rtitcp_transaction_t
{
160 } rtitcp_transaction_t
;
162 typedef struct _rtitcp_conv_info_t
{
164 } rtitcp_conv_info_t
;
166 /* Subtree pointers */
167 static int ett_rtitcp
;
168 static int ett_rtitcp_signalling_protocol
;
169 static int ett_rtitcp_message
;
170 static int ett_rtitcp_attributes_list
;
171 static int ett_rtitcp_attribute
;
173 static header_field_info
*hfi_rtitcp
;
174 static heur_dissector_list_t heur_subdissector_list
;
176 static const value_string ctrl_message_types_vals
[] = {
177 { IDENTITY_BIND_REQUEST
, "Identity Bind Request" },
178 { IDENTITY_BIND_INDICATION
, "Identity Bind Indication" },
179 { IDENTITY_BIND_RESPONSE
, "Identity Bind Response" },
180 { IDENTITY_BIND_ERROR
, "Identity Bind Error" },
181 { SERVER_LOGICAL_PORT_REQUEST
, "Server Logical Port Request" },
182 { SERVER_LOGICAL_PORT_RESPONSE
, "Server Logical Port Response" },
183 { SERVER_LOGICAL_PORT_ERROR
, "Server Logical Port Error" },
184 { CLIENT_LOGICAL_PORT_REQUEST
, "Client Logical Port Request" },
185 { CLIENT_LOGICAL_PORT_RESPONSE
, "Client Logical Port Response" },
186 { CLIENT_LOGICAL_PORT_ERROR
, "Client Logical Port Error" },
187 { CONNECTION_BIND_REQUEST
, "Connection Bind Request" },
188 { CONNECTION_BIND_RESPONSE
, "Connection Bind Response" },
189 { CONNECTION_BIND_ERROR
, "Connection Bind Error" },
190 { SESSION_ID_REQUEST
, "Session ID Request" },
191 { SESSION_ID_INDICATION
, "Session ID Indication" },
192 { SESSION_ID_RESPONSE
, "Session ID Response" },
193 { SESSION_ID_ERROR
, "Session ID Error" },
194 { LIVELINESS_REQUEST
, "Liveliness Request" },
195 { LIVELINESS_RESPONSE
, "Liveliness Response" },
196 { FINALIZE_SESSION_INDICATION
, "Finalize Session Indication" },
200 static const value_string attribute_types_vals
[] = {
201 { RTPS_LOCATOR_ADDRESS_ATTRIBUTE_TYPE
, "Locator Address" },
202 { RTPS_LOCATOR_PORT_ATTRIBUTE_TYPE
, "Locator Port" },
203 { CONNECTION_TYPE_ATTRIBUTE_TYPE
, "Connection Type" },
204 { CONNECTION_COOKIE_ATTRIBUTE_TYPE
, "Connection Cookie" },
205 { PORT_OPTIONS_ATTRIBUTE_TYPE
, "Port options" },
206 { TRANSPORT_PRIORITY_ATTRIBUTE_TYPE
, "Transport priority" },
207 { SESSION_ID_ATTRIBUTE_TYPE
, "Session ID" },
208 { MAPPED_ADDRESS_ATTRIBUTE_TYPE
, "Mapped Address" },
209 { XOR_MAPPED_ADDRESS_ATTRIBUTE_TYPE
, "XOR Mapped Address" },
210 { ERROR_CODE_ATTRIBUTE_TYPE
, "Error Code" },
211 { UNKNOWN_ATTRIBUTES_ATTRIBUTE_TYPE
, "Unknown attribute" },
212 { SOFTWARE_ATTRIBUTE_TYPE
, "Software" },
213 { ALTERNATE_SERVER_ATTRIBUTE_TYPE
, "Alternate Server" },
217 static const value_string error_code_kind_vals
[] = {
218 { NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_OK
,
220 { NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_TRANSPORT_CLASS_MISMATCH
,
221 "PROTOCOL_ERROR_TRANSPORT_CLASS_MISMATCH" },
222 { NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_ATTRIBUTE_MISSING
,
223 "PROTOCOL_ERROR_ATTRIBUTE_MISSING" },
224 { NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_NO_MATCHING_RECVRESOURCE
,
225 "PROTOCOL_ERROR_NO_MATCHING_RECVRESOURCE" },
226 { NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_NO_MATCH_COOKIE
,
227 "PROTOCOL_ERROR_NO_MATCH_COOKIE" },
228 { NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_INTERNAL
,
229 "PROTOCOL_ERROR_INTERNAL" },
230 { NDDS_TRANSPORT_TCPV4_CONTROL_PROTOCOL_ERROR_RETRY
,
231 "PROTOCOL_ERROR_RETRY" },
232 { NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_BAD_REQUEST_ID
,
233 "ERROR_CODE_ATTRIBUTE_BAD_REQUEST_ID" },
234 { NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_UNKNOWN_ATTRIBUTE_ID
,
235 "ERROR_CODE_ATTRIBUTE_UNKNOWN_ATTRIBUTE_ID" },
236 { NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_ALLOCATION_MISMATCH_ID
,
237 "ERROR_CODE_ATTRIBUTE_ALLOCATION_MISMATCH_ID" },
238 { NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_UNSUPPORTED_TRANSPORT_PROTOCOL_ID
,
239 "ERROR_CODE_ATTRIBUTE_UNSUPPORTED_TRANSPORT_PROTOCOL_ID" },
240 { NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_CONNECTION_ALREADY_EXISTS_ID
,
241 "ERROR_CODE_ATTRIBUTE_CONNECTION_ALREADY_EXISTS_ID" },
242 { NDDS_TRANSPORT_TCP_CONTROL_ERROR_CODE_ATTRIBUTE_SERVER_ERROR_ID
,
243 "ERROR_CODE_ATTRIBUTE_SERVER_ERROR_ID" },
247 static const value_string rtitcp_locator_kind_vals
[] = {
248 { LOCATOR_KIND_IPV4
, "IPV4" },
249 { LOCATOR_KIND_IPV6
, "Unreachable peer" },
253 static const value_string rtitcp_attribute_connection_type_vals
[] = {
254 { CLASS_ID_TCPV4_LAN
, "TCPV4_LAN" },
255 { CLASS_ID_TCPV4_WAN
, "TCPV4_WAN" },
256 { CLASS_ID_TLSV4_LAN
, "TLSV4_LAN" },
257 { CLASS_ID_TLSV4_WAN
, "TLSV4_WAN" },
261 static void rtitcp_util_add_error_attribute(proto_tree
*attribute
, tvbuff_t
* tvb
,
262 int offset
, unsigned size
) {
263 proto_tree_add_item(attribute
, hf_rtitcp_control_attribute_error_code_value
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
264 proto_tree_add_item(attribute
, hf_rtitcp_control_attribute_error_code_description
, tvb
, offset
+ 4,
265 size
- 4, ENC_ASCII
);
268 static void rtitcp_util_add_locator_t(proto_tree
*tree
, packet_info
*pinfo _U_
, tvbuff_t
* tvb
,
269 int offset
, bool little_endian
,
270 proto_item
* rtitcp_message
, bool * first_attribute
) {
273 kind
= tvb_get_uint16(tvb
, offset
+8, little_endian
? ENC_LITTLE_ENDIAN
: ENC_BIG_ENDIAN
);
275 if (kind
== 0xFFFF) {
276 kind
= LOCATOR_KIND_IPV4
;
278 kind
= LOCATOR_KIND_IPV6
;
280 proto_tree_add_uint(tree
, hf_rtitcp_locator_kind
, tvb
, offset
+8, 2, kind
);
282 if (kind
== LOCATOR_KIND_IPV4
) {
283 proto_tree_add_item(tree
, hf_rtitcp_locator_port
, tvb
, offset
+10, 2, ENC_BIG_ENDIAN
);
284 proto_tree_add_item(tree
, hf_rtitcp_locator_ipv4
, tvb
, offset
+12, 4, ENC_BIG_ENDIAN
);
286 port
= tvb_get_uint16(tvb
, offset
+10, little_endian
? ENC_LITTLE_ENDIAN
: ENC_BIG_ENDIAN
);
287 if (*first_attribute
) {
288 proto_item_append_text(rtitcp_message
," (");
289 col_append_str(pinfo
->cinfo
, COL_INFO
, " (");
291 proto_item_append_text(rtitcp_message
, "%s%s:%u",
292 *first_attribute
? "" : ", ", tvb_ip_to_str(pinfo
->pool
, tvb
, offset
+ 12), port
);
293 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "%s%s:%u",
294 *first_attribute
? "" : ", ", tvb_ip_to_str(pinfo
->pool
, tvb
, offset
+ 12), port
);
296 proto_tree_add_item(tree
, hf_rtitcp_locator_ipv6
, tvb
, offset
, 16, ENC_NA
);
297 if (*first_attribute
) {
298 proto_item_append_text(rtitcp_message
," (");
299 col_append_str(pinfo
->cinfo
, COL_INFO
, " (");
301 proto_item_append_text(rtitcp_message
, "%s%s",
302 *first_attribute
? "" : ", ", tvb_ip6_to_str(pinfo
->pool
, tvb
, offset
));
303 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "%s%s",
304 *first_attribute
? "" : ", ", tvb_ip6_to_str(pinfo
->pool
, tvb
, offset
));
308 static unsigned dissect_attribute(tvbuff_t
*tvb
, packet_info
*pinfo
,
309 proto_tree
*attributes_list
, unsigned offset
, unsigned attributes_list_offset
,
310 proto_item
* rtitcp_message
, bool * first_attribute
) {
312 uint16_t attribute_length
, attribute_type
;
314 proto_item
*attribute
;
316 attribute_type
= tvb_get_uint16(tvb
, attributes_list_offset
+offset
, ENC_BIG_ENDIAN
);
317 attribute_length
= tvb_get_uint16(tvb
, attributes_list_offset
+offset
+2, ENC_BIG_ENDIAN
);
319 attribute
= proto_tree_add_subtree_format(attributes_list
, tvb
,
320 attributes_list_offset
+offset
, attribute_length
+4,
321 ett_rtitcp_attribute
, NULL
, "Unknown Attribute");
323 proto_tree_add_item(attribute
, hf_rtitcp_control_attribute_type
, tvb
,
324 attributes_list_offset
+offset
, 2, ENC_BIG_ENDIAN
);
325 proto_tree_add_item(attribute
, hf_rtitcp_control_attribute_length
, tvb
,
326 attributes_list_offset
+offset
+2, 2, ENC_BIG_ENDIAN
);
327 proto_item_set_text(attribute
,"%s", val_to_str_const(attribute_type
, attribute_types_vals
, "Unknown attribute"));
329 switch (attribute_type
) {
330 case RTPS_LOCATOR_PORT_ATTRIBUTE_TYPE
: {
332 port
= tvb_get_uint32(tvb
, attributes_list_offset
+offset
+4, ENC_BIG_ENDIAN
);
333 if (*first_attribute
) {
334 proto_item_append_text(rtitcp_message
," (");
335 col_append_str(pinfo
->cinfo
, COL_INFO
, " (");
337 proto_item_append_text(rtitcp_message
, "%s%u",
338 *first_attribute
? "" : ", ", port
);
339 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "%s%u",
340 *first_attribute
? "" : ", ", port
);
341 (*first_attribute
) = false;
342 proto_item_append_text(attribute
, " (Port = %u)", port
);
343 proto_tree_add_item(attribute
, hf_rtitcp_control_attribute_port
, tvb
,
344 attributes_list_offset
+offset
+4, attribute_length
, ENC_BIG_ENDIAN
);
347 case RTPS_LOCATOR_ADDRESS_ATTRIBUTE_TYPE
: {
348 rtitcp_util_add_locator_t(attribute
, pinfo
, tvb
, attributes_list_offset
+offset
+4,
349 ENC_BIG_ENDIAN
, rtitcp_message
, first_attribute
);
350 (*first_attribute
) = false;
354 case CONNECTION_COOKIE_ATTRIBUTE_TYPE
: {
355 proto_tree_add_item(attribute
, hf_rtitcp_control_attribute_connection_cookie
,
356 tvb
, attributes_list_offset
+offset
+4, attribute_length
, ENC_NA
);
357 if (*first_attribute
) {
358 proto_item_append_text(rtitcp_message
," (");
359 col_append_str(pinfo
->cinfo
, COL_INFO
, " (");
361 proto_item_append_text(rtitcp_message
, "%s%s",
362 (*first_attribute
) ? "" : ", ",
363 tvb_bytes_to_str(pinfo
->pool
, tvb
, attributes_list_offset
+offset
+4, 16));
364 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "%s%s",
365 (*first_attribute
) ? "" : ", ",
366 tvb_bytes_to_str(pinfo
->pool
, tvb
, attributes_list_offset
+offset
+4, 16));
367 (*first_attribute
) = false;
370 case CONNECTION_TYPE_ATTRIBUTE_TYPE
: {
371 uint8_t attribute_connection_type
= tvb_get_uint8(tvb
, attributes_list_offset
+offset
+4);
372 proto_tree_add_item(attribute
, hf_rtitcp_control_attribute_connection_type
, tvb
,
373 attributes_list_offset
+offset
+4, attribute_length
, ENC_BIG_ENDIAN
);
374 if (*first_attribute
) {
375 proto_item_append_text(rtitcp_message
," (");
376 col_append_str(pinfo
->cinfo
, COL_INFO
, " (");
378 proto_item_append_text(rtitcp_message
, "%s%s",
379 (*first_attribute
) ? "" : ", ",
380 val_to_str_const(attribute_connection_type
, rtitcp_attribute_connection_type_vals
, "Unknown attribute"));
381 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "%s%s",
382 (*first_attribute
) ? "" : ", ",
383 val_to_str_const(attribute_connection_type
, rtitcp_attribute_connection_type_vals
, "Unknown attribute"));
384 (*first_attribute
) = false;
387 case SESSION_ID_ATTRIBUTE_TYPE
: {
388 proto_tree_add_item(attribute
, hf_rtitcp_control_attribute_session_id
, tvb
,
389 attributes_list_offset
+offset
+4, attribute_length
, ENC_NA
);
392 case ERROR_CODE_ATTRIBUTE_TYPE
: {
393 rtitcp_util_add_error_attribute(attribute
, tvb
, attributes_list_offset
+offset
+4, attribute_length
);
400 padding
= (4 - attribute_length
%4)%4;
401 return (attribute_length
+padding
+4);
403 static proto_tree
* print_header(proto_tree
*tree
, proto_tree
*rtitcp_message
, tvbuff_t
*tvb
, unsigned offset
,
404 uint16_t msg_length
, bool printCRC
, bool is_data
) {
408 rtitcp_message
= proto_tree_add_subtree_format(tree
, tvb
, offset
, msg_length
,
409 ett_rtitcp_message
, NULL
, "RTI TCP Data Message");
411 rtitcp_message
= proto_tree_add_subtree_format(tree
, tvb
, offset
, msg_length
,
412 ett_rtitcp_message
, NULL
, "RTI TCP Control Message");
415 uint32_t msg_length32
;
416 proto_tree_add_item(rtitcp_message
, hf_rtitcp_header_control_byte
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
417 ti
= proto_tree_add_item(rtitcp_message
, hf_rtitcp_header_message_length
,
418 tvb
, offset
+1, 3, ENC_BIG_ENDIAN
);
419 msg_length32
= tvb_get_uint32(tvb
, offset
, ENC_BIG_ENDIAN
);
420 msg_length32
= msg_length32
% NUMBER_2E30
;
421 proto_item_set_text(ti
,"RTI TCP Message Length: %d", msg_length32
);
423 proto_tree_add_item(rtitcp_message
, hf_rtitcp_header_control_byte
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
424 proto_tree_add_item(rtitcp_message
, hf_rtitcp_header_message_length
, tvb
, offset
+2, 2, ENC_BIG_ENDIAN
);
426 proto_tree_add_item(rtitcp_message
, hf_rtitcp_header_magic_number
, tvb
, offset
+4, 4, ENC_BIG_ENDIAN
);
428 proto_tree_add_item(rtitcp_message
, hf_rtitcp_crc_magic_cookie
, tvb
, offset
+8, 4, ENC_BIG_ENDIAN
);
429 proto_tree_add_item(rtitcp_message
, hf_rtitcp_control_crc_value
, tvb
, offset
+12, 4, ENC_BIG_ENDIAN
);
432 return rtitcp_message
;
434 static uint16_t dissect_control_message(proto_tree
*rtitcp_tree
, tvbuff_t
*tvb
, packet_info
*pinfo
,
437 /* 0...2...........7...............15.............23...............31
438 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
439 * | Not Used | msg_length |
440 * +---------------+---------------+---------------+---------------+
441 * | RTITCP_MAGIC_NUMBER |
442 * +---------------+---------------+---------------+---------------+
443 * | control_message_kind | attributes_list_length |
444 * +---------------+---------------+---------------+---------------+
445 * | RTITCP_CONTROL_MAGIC_COOKIE |
446 * +---------------+---------------+---------------+---------------+
452 * +---------------+---------------+---------------+---------------+ ---------------------------------
453 * | attribute_type | attribute_length .. Repeat |
454 * +---------------+---------------+---------------+---------------+ until |
455 * | ATTRIBUTE (length) | attributes_list_length expires |
456 * +---------------+---------------+---------------+---------------+ --------------------------------*/
458 proto_tree
*attributes_list
, *rtitcp_message
= NULL
;
459 uint16_t msg_length
, control_message_kind
, attributes_list_length
, header_length
;
460 unsigned attributes_list_offset
, attribute_offset
, offset_header
= offset
;
461 unsigned attributes_count
;
462 bool is_data
= false, printCRC
= false, first_attribute
;
463 char * transaction_id_str
;
465 conversation_t
*conversation
;
466 rtitcp_conv_info_t
*rtitcp_info
;
467 rtitcp_transaction_t
*rtitcp_trans
;
468 uint64_t * conversation_info_key
= NULL
;
470 /* The header length is 8 if it doesn't contain optional fields */
473 msg_length
= tvb_get_uint16(tvb
, offset
+2, ENC_BIG_ENDIAN
);
476 /* Check if CRC is present */
477 if (tvb_get_ntohl(tvb
, offset
) == RTITCP_CRC_MAGIC_NUMBER
) {
480 offset
+= 8; /* Because of 0xCRC32 + actual CRC (4 bytes) */
483 /* Time to print the header */
484 rtitcp_message
= print_header(rtitcp_tree
, rtitcp_message
, tvb
, offset_header
, msg_length
+ header_length
, printCRC
, is_data
);
486 /* Check the control message kind */
487 control_message_kind
= tvb_get_uint16(tvb
, offset
, ENC_BIG_ENDIAN
);
488 col_append_sep_str(pinfo
->cinfo
, COL_INFO
, ", ",
489 val_to_str_const(control_message_kind
,ctrl_message_types_vals
, "Unknown control message"));
490 proto_tree_add_uint(rtitcp_message
, hf_rtitcp_control_kind
, tvb
, offset
, 2, control_message_kind
);
491 proto_item_set_text(rtitcp_message
,"RTI TCP Control Message , Kind: %s",
492 val_to_str_const(control_message_kind
,ctrl_message_types_vals
, "Unknown control message"));
495 /* Take the length in bytes of the attributes list */
496 attributes_list_length
= tvb_get_uint16(tvb
, offset
, ENC_BIG_ENDIAN
);
497 proto_tree_add_item(rtitcp_message
, hf_rtitcp_attributes_list_length
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
500 /* We expect now the RTI TCP Control Magic Cookie */
501 if (tvb_get_ntohl(tvb
, offset
) != RTITCP_CONTROL_MAGIC_COOKIE
) {
502 return msg_length
+ header_length
;
504 proto_tree_add_item(rtitcp_message
, hf_rtitcp_control_magic_cookie
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
507 /* Now we dissect the transaction id */
508 proto_tree_add_item(rtitcp_message
, hf_rtitcp_control_transaction_id
, tvb
, offset
, 12, ENC_NA
);
509 transaction_id_str
= tvb_bytes_to_str(pinfo
->pool
, tvb
, offset
, 12);
511 /* Get the transaction identifier. Not the whole transaction but the middle part, which
512 * shouldn't coincide */
513 seq_num
= tvb_get_ntoh64(tvb
, offset
);
516 * We need to track some state for this protocol on a per conversation
517 * basis so we can do neat things like request/response tracking
519 conversation
= find_or_create_conversation(pinfo
);
521 rtitcp_info
= (rtitcp_conv_info_t
*)conversation_get_proto_data(conversation
, proto_rtitcp
);
524 * No. Attach that information to the conversation, and add
525 * it to the list of information structures.
527 rtitcp_info
= wmem_new(wmem_file_scope(), rtitcp_conv_info_t
);
528 rtitcp_info
->pdus
=wmem_map_new(wmem_file_scope(), g_int64_hash
, g_int64_equal
);
530 conversation_add_proto_data(conversation
, proto_rtitcp
, rtitcp_info
);
532 if (!pinfo
->fd
->visited
) {
533 if (!(control_message_kind
& RTITCP_FLAG_NOT_REQUEST
)) {
534 /* This is a request */
535 rtitcp_trans
=wmem_new(wmem_file_scope(), rtitcp_transaction_t
);
536 rtitcp_trans
->req_frame
= pinfo
->num
;
537 rtitcp_trans
->rep_frame
= 0;
538 rtitcp_trans
->req_time
= pinfo
->abs_ts
;
539 conversation_info_key
= wmem_new0(wmem_file_scope(), uint64_t);
540 *conversation_info_key
= seq_num
;
541 wmem_map_insert(rtitcp_info
->pdus
, conversation_info_key
, (void *)rtitcp_trans
);
543 conversation_info_key
= &seq_num
;
544 rtitcp_trans
=(rtitcp_transaction_t
*)wmem_map_lookup(rtitcp_info
->pdus
, conversation_info_key
);
546 rtitcp_trans
->rep_frame
= pinfo
->num
;
550 conversation_info_key
= &seq_num
;
551 rtitcp_trans
=(rtitcp_transaction_t
*)wmem_map_lookup(rtitcp_info
->pdus
, conversation_info_key
);
554 /* create a "fake" rtitcp_trans structure */
555 rtitcp_trans
=wmem_new(pinfo
->pool
, rtitcp_transaction_t
);
556 rtitcp_trans
->req_frame
= 0;
557 rtitcp_trans
->rep_frame
= 0;
558 rtitcp_trans
->req_time
= pinfo
->abs_ts
;
561 /* print state tracking in the tree */
562 if (!(control_message_kind
& RTITCP_FLAG_NOT_REQUEST
)) {
563 /* This is a request */
564 if (rtitcp_trans
->rep_frame
) {
566 it
= proto_tree_add_uint(rtitcp_message
, hf_rtitcp_response_in
,
567 tvb
, 0, 0, rtitcp_trans
->rep_frame
);
568 proto_item_set_generated(it
);
571 /* This is a reply */
572 if (rtitcp_trans
->req_frame
) {
575 it
= proto_tree_add_uint(rtitcp_message
, hf_rtitcp_response_to
,
576 tvb
, 0, 0, rtitcp_trans
->req_frame
);
577 proto_item_set_generated(it
);
579 nstime_delta(&ns
, &pinfo
->abs_ts
, &rtitcp_trans
->req_time
);
580 it
= proto_tree_add_time(rtitcp_message
, hf_rtitcp_response_time
, tvb
, 0, 0, &ns
);
581 proto_item_set_generated(it
);
588 /* Finally, dissect the list of attributes */
589 attributes_list_offset
= 0;
590 attributes_list
= proto_tree_add_subtree_format(rtitcp_message
, tvb
,
591 attributes_list_offset
+offset
, attributes_list_length
,
592 ett_rtitcp_attributes_list
, NULL
, "Attributes List");
594 attributes_count
= 0;
595 first_attribute
= true;
596 while (attributes_list_offset
< attributes_list_length
) {
598 attribute_offset
= dissect_attribute(tvb
, pinfo
, attributes_list
,
599 offset
, attributes_list_offset
, rtitcp_message
, &first_attribute
);
600 attributes_list_offset
+= attribute_offset
;
602 if (!first_attribute
) {
603 proto_item_append_text(rtitcp_message
,")");
604 col_append_str(pinfo
->cinfo
, COL_INFO
, ")");
606 /* Now that we have the number of attributes, update the text to show it */
607 proto_item_set_text(attributes_list
, "Attributes list [%d attribute%s",
608 attributes_count
, attributes_count
> 1 ? "s]" : "]");
610 proto_item_append_text(rtitcp_message
,", Transaction ID: %s, Len: %d",
611 transaction_id_str
, msg_length
);
613 return msg_length
+ header_length
;
616 /* This function dissects all the control messages found */
617 static unsigned dissect_rtitcp_control_protocol(proto_tree
*rtitcp_tree
, tvbuff_t
*tvb
, packet_info
*pinfo
) {
623 tvb_len
= tvb_reported_length(tvb
);
625 while (offset
< tvb_len
) {
626 msg_length
= dissect_control_message(rtitcp_tree
, tvb
, pinfo
, offset
);
627 offset
+= msg_length
;
633 static int dissect_rtitcp_common(tvbuff_t
*tvb
, packet_info
*pinfo
,
634 proto_tree
*tree
, void *data _U_
) {
636 /* FORMAT OF THE CONTROL MESSAGE
638 0...2...........7...............15.............23...............31
639 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
640 * | control bytes | RTI TCP message length |
641 * +---------------+---------------+---------------+---------------+
642 * | RTITCP_MAGIC_NUMBER |
643 * +---------------+---------------+---------------+---------------+
644 * | control_message_kind | attributes_list_length |
645 * +---------------+---------------+---------------+---------------+
646 * | RTITCP_CONTROL_MAGIC_COOKIE |
647 * +---------------+---------------+---------------+---------------+
653 * +---------------+---------------+---------------+---------------+ ---------------------------------
654 * | attribute_type | attribute_length .. Repeat |
655 * +---------------+---------------+---------------+---------------+ until |
656 * | ATTRIBUTE (length) | attributes_list_length expires |
657 * +---------------+---------------+---------------+---------------+ --------------------------------*/
660 proto_tree
*rtitcp_tree
, *rtitcp_message
= NULL
;
661 unsigned offset
, offset_header
;
662 uint16_t rtitcp_msg_length
, header_length
;
663 uint32_t tvb_len
, rtitcp_rtps_msg_length
;
664 bool printCRC
= false, is_data
= false;
666 heur_dtbl_entry_t
*hdtbl_entry
;
669 tvb_len
= tvb_reported_length(tvb
);
671 /* From this point, we can consider that this is a RTI TCP message */
672 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "RTI-TCP");
674 rtitcp_msg_length
= tvb_get_uint16(tvb
, offset
+2, ENC_BIG_ENDIAN
);
676 ti
= proto_tree_add_item(tree
, proto_rtitcp
, tvb
, offset
, -1, ENC_NA
);
677 rtitcp_tree
= proto_item_add_subtree(ti
, ett_rtitcp
);
679 offset_header
= 0; /* Remember the offset that delimits the header */
680 header_length
= 8; /* the header is 8 bytes length + 8 optional (CRC) */
681 offset
+= 2; /* First two bytes are CTRL bytes */
682 offset
+= 2; /* rtitcp_msg_length */
683 offset
+= 4; /* RTITCP_MAGIC_NUMBER has already been checked */
685 /* if bytes 8 to 12 are RTITCP_CRC_MAGIC_NUMBER, we got a CRC */
686 if (tvb_get_ntohl(tvb
, offset
) == RTITCP_CRC_MAGIC_NUMBER
) {
687 printCRC
= true; /* To specify later that CRC must be printed */
688 header_length
+= 8; /* header increases in 8 bytes */
689 offset
+= 8; /* Because of 0xCRC32 + actual CRC (4 bytes) */
691 proto_item_set_len(ti
, rtitcp_msg_length
+ header_length
);
693 /* At this point, offset is 8 or 16 bytes and we have now data.
694 This data can be RTPS or RTI TCP Signaling messages */
695 if (tvb_get_ntohl(tvb
, offset
) == RTPS_MAGIC_NUMBER
) {
697 /* IMPORTANT NOTE: We assume always one RTPS message per RTITCP message */
698 /* If the TCP layer has provided us with garbage at the end of the buffer,
699 process only the length specified by rtitcp_msg_length */
700 if (tvb_len
> (uint32_t)(rtitcp_msg_length
+ header_length
)) {
701 tvb_set_reported_length(tvb
, (rtitcp_msg_length
+ header_length
));
704 /* When we encapsulate RTPS, packet length is given by the 30 less
705 significant bits of the first four bytes */
706 rtitcp_rtps_msg_length
= tvb_get_uint32(tvb
, 0, ENC_BIG_ENDIAN
);
707 rtitcp_rtps_msg_length
= rtitcp_rtps_msg_length
% NUMBER_2E30
;
708 /* Add RTI TCP Data Message subtree and print header */
710 rtitcp_message
= print_header(rtitcp_tree
, rtitcp_message
, tvb
, offset_header
,
711 rtitcp_rtps_msg_length
+ header_length
, printCRC
, is_data
);
713 proto_item_set_text(rtitcp_message
,"RTI TCP Data Message, Len: %d",
714 rtitcp_rtps_msg_length
);
716 /* Take the payload and call the registered sub-dissectors. So far, RTPS */
717 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
718 dissector_try_heuristic(heur_subdissector_list
, next_tvb
, pinfo
, tree
, &hdtbl_entry
, NULL
);
719 return tvb_captured_length(tvb
);
722 return dissect_rtitcp_control_protocol(rtitcp_tree
, tvb
, pinfo
);
726 static unsigned get_rtitcp_pdu_len(packet_info
*pinfo _U_
, tvbuff_t
*tvb
,
727 int offset
, void * data _U_
) {
729 uint16_t header_length
= 8;
731 * Get the length of the RTITCP packet.
733 plen
= tvb_get_uint16(tvb
, offset
+2, ENC_BIG_ENDIAN
);
735 * That length doesn't include the header field itself; add that in.
737 if (tvb_get_ntohl(tvb
, offset
+8) == RTITCP_CRC_MAGIC_NUMBER
)
739 /* We don't expect plen to be greater than 0xfff8 since adding the header
740 * exceeds the size */
744 return plen
+ header_length
;
746 static int dissect_rtitcp(tvbuff_t
*tvb
, packet_info
*pinfo
,
747 proto_tree
*tree
, void *data _U_
) {
749 bool desegmentation
= true;
751 if (tvb_captured_length(tvb
) < 8)
754 /* Check if the RTITCP_MAGIC_NUMBER is here */
755 if (tvb_get_ntohl(tvb
, 4) != RTITCP_MAGIC_NUMBER
)
758 col_clear(pinfo
->cinfo
, COL_INFO
);
760 tcp_dissect_pdus(tvb
, pinfo
, tree
, desegmentation
, RTITCP_MIN_LENGTH
,
761 get_rtitcp_pdu_len
, dissect_rtitcp_common
, data
);
763 return tvb_captured_length(tvb
);
768 dissect_rtitcp_heur(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
770 return dissect_rtitcp(tvb
, pinfo
, tree
, data
) > 0;
773 /* Register the protocol with Wireshark.
775 * This format is required because a script is used to build the C function that
776 * calls all the protocol registration.
779 proto_register_rtitcp(void)
781 /* module_t *rtitcp_module; */
782 /* expert_module_t* expert_rtitcp; */
784 static hf_register_info hf
[] = {
786 { &hf_rtitcp_header_control_byte
, {
787 "Control Byte", "rtitcp.header.control_byte",
788 FT_UINT16
, BASE_HEX
, NULL
, 0,
792 { &hf_rtitcp_header_message_length
, {
793 "Message Length", "rtitcp.header.message_length",
794 FT_UINT24
, BASE_DEC
, NULL
, 0,
798 { &hf_rtitcp_header_magic_number
, {
799 "Magic Cookie", "rtitcp.header.magic_cookie",
800 FT_UINT32
, BASE_HEX
, NULL
, 0,
804 { &hf_rtitcp_crc_magic_cookie
, {
805 "CRC Magic Cookie", "rtitcp.header.crc_magic_cookie",
806 FT_UINT32
, BASE_HEX
, NULL
, 0,
810 { &hf_rtitcp_control_kind
,
811 { "Kind", "rtitcp.control.kind",
812 FT_UINT16
, BASE_HEX
, VALS(ctrl_message_types_vals
), 0,
816 { &hf_rtitcp_control_magic_cookie
, {
817 "Control Magic Cookie", "rtitcp.control.magic_cookie",
818 FT_UINT32
, BASE_HEX
, NULL
, 0,
822 { &hf_rtitcp_control_transaction_id
, {
823 "Transaction ID", "rtitcp.control.transaction_id",
824 FT_BYTES
, BASE_NONE
, NULL
, 0,
828 { &hf_rtitcp_control_attribute_session_id
, {
829 "Session ID", "rtitcp.control.attribute.session_id",
830 FT_BYTES
, BASE_NONE
, NULL
, 0,
834 { &hf_rtitcp_control_attribute_type
,
835 { "Attribute Type", "rtitcp.control.attribute_type",
836 FT_UINT16
, BASE_HEX
, VALS(attribute_types_vals
), 0,
840 { &hf_rtitcp_control_attribute_error_code_value
,
841 { "Kind", "rtitcp.control.attribute.error_code",
842 FT_UINT32
, BASE_HEX
, VALS(error_code_kind_vals
), 0,
846 { &hf_rtitcp_control_attribute_error_code_description
, {
847 "Description", "rtitcp.control.attribute.error_code.description",
848 FT_STRING
, BASE_NONE
, NULL
, 0,
852 { &hf_rtitcp_control_attribute_connection_cookie
, {
853 "Connection Cookie", "rtitcp.control.attribute.connection_cookie",
854 FT_BYTES
, BASE_NONE
, NULL
, 0,
858 { &hf_rtitcp_control_attribute_connection_type
, {
859 "Class ID", "rtitcp.control_attribute.connection_type",
860 FT_UINT8
, BASE_HEX
, VALS(rtitcp_attribute_connection_type_vals
), 0,
864 { &hf_rtitcp_attributes_list_length
, {
865 "Attributes list length", "rtitcp.attributes_list_length",
866 FT_UINT16
, BASE_DEC
, NULL
, 0,
870 { &hf_rtitcp_control_attribute_length
, {
871 "Attribute Length", "rtitcp.control.attribute.length",
872 FT_UINT16
, BASE_DEC
, NULL
, 0,
876 { &hf_rtitcp_control_attribute_port
, {
877 "Port", "rtitcp.control.attribute_port",
878 FT_UINT32
, BASE_DEC
, NULL
, 0,
882 { &hf_rtitcp_locator_kind
,
883 { "Kind", "rtitcp.locator.kind",
884 FT_UINT16
, BASE_DEC
, VALS(rtitcp_locator_kind_vals
), 0,
888 { &hf_rtitcp_locator_ipv4
,
889 { "Address", "rtitcp.locator.ipv4",
890 FT_IPv4
, BASE_NONE
, NULL
, 0,
894 { &hf_rtitcp_locator_port
,
895 { "Port", "rtitcp.locator.port",
896 FT_UINT16
, BASE_DEC
, NULL
, 0,
900 { &hf_rtitcp_locator_ipv6
,
901 { "Address", "rtitcp.locator.ipv6",
902 FT_IPv6
, BASE_NONE
, NULL
, 0,
906 { &hf_rtitcp_control_crc_value
,
907 { "CRC", "rtitcp.control.crc",
908 FT_UINT32
, BASE_HEX
, NULL
, 0,
912 { &hf_rtitcp_response_in
,
913 { "Response In", "rtitcp.response_in",
914 FT_FRAMENUM
, BASE_NONE
, FRAMENUM_TYPE(FT_FRAMENUM_RESPONSE
), 0x0,
915 "The response to this RTITCP request is in this frame", HFILL
}
918 { &hf_rtitcp_response_to
,
919 { "Request In", "rtitcp.response_to",
920 FT_FRAMENUM
, BASE_NONE
, FRAMENUM_TYPE(FT_FRAMENUM_REQUEST
), 0x0,
921 "This is a response to the RTITCP request in this frame", HFILL
}
924 { &hf_rtitcp_response_time
,
925 { "Response Time", "rtitcp.response_time",
926 FT_RELATIVE_TIME
, BASE_NONE
, NULL
, 0x0,
927 "The time between the Request and the Reply", HFILL
}
931 static int *ett
[] = {
933 &ett_rtitcp_signalling_protocol
,
935 &ett_rtitcp_attributes_list
,
936 &ett_rtitcp_attribute
939 /* Setup protocol expert items */
940 /* static ei_register_info ei[] = {}; */
942 /* Register the protocol name and description */
943 proto_rtitcp
= proto_register_protocol("RTI TCP Transport Protocol",
946 hfi_rtitcp
= proto_registrar_get_nth(proto_rtitcp
);
947 /* Required function calls to register the header fields and subtrees */
948 proto_register_field_array(proto_rtitcp
, hf
, array_length(hf
));
949 proto_register_subtree_array(ett
, array_length(ett
));
951 /* Required function calls to register expert items */
952 /* expert_rtitcp = expert_register_protocol(proto_rtitcp);
953 expert_register_field_array(expert_rtitcp, ei, array_length(ei)); */
955 register_dissector("rtitcp", dissect_rtitcp
, proto_rtitcp
);
956 heur_subdissector_list
= register_heur_dissector_list_with_description("rtitcp", "RTI TCP signalling message", proto_rtitcp
);
960 /* Simpler form of proto_reg_handoff_rtitcp which can be used if there are
961 * no prefs-dependent registration function calls. */
963 proto_reg_handoff_rtitcp(void)
965 heur_dissector_add("tcp", dissect_rtitcp_heur
, "RTI TCP Layer" , "rtitcp", proto_rtitcp
, HEURISTIC_ENABLE
);
969 * Editor modelines - https://www.wireshark.org/tools/modelines.html
974 * indent-tabs-mode: nil
977 * vi: set shiftwidth=4 tabstop=8 expandtab:
978 * :indentSize=4:tabSize=8:noTabs=true: