2 * Reliable Multicast Transport (RMT)
3 * ALC Protocol Instantiation dissector
4 * Copyright 2005, Stefano Pettini <spettini@users.sourceforge.net>
5 * Copyright 2023, Sergey V. Lobanov <sergey@lobanov.in>
7 * Asynchronous Layered Coding (ALC):
8 * ----------------------------------
10 * A massively scalable reliable content delivery protocol.
11 * Asynchronous Layered Coding combines the Layered Coding Transport
12 * (LCT) building block, a multiple rate congestion control building
13 * block and the Forward Error Correction (FEC) building block to
14 * provide congestion controlled reliable asynchronous delivery of
15 * content to an unlimited number of concurrent receivers from a single
19 * RFC 3450, Asynchronous Layered Coding protocol instantiation
21 * Wireshark - Network traffic analyzer
22 * By Gerald Combs <gerald@wireshark.org>
23 * Copyright 1998 Gerald Combs
25 * SPDX-License-Identifier: GPL-2.0-or-later
30 #include <epan/packet.h>
31 #include <epan/prefs.h>
32 #include <epan/expert.h>
33 #include <epan/conversation.h>
34 #include <wiretap/wtap.h>
35 #include <wsutil/array.h>
37 #include "packet-rmt-common.h"
38 #include "packet-lls.h"
40 /* Initialize the protocol and registered fields */
41 /* ============================================= */
42 static dissector_handle_t alc_handle
;
44 void proto_register_alc(void);
45 void proto_reg_handoff_alc(void);
47 static int proto_rmt_alc
;
49 static int hf_version
;
51 static int hf_object_start_offset
;
52 static int hf_payload
;
53 static int hf_uncomp_payload
;
56 static int ett_uncomp_payload
;
57 static int ett_uncomp_decode
;
59 static expert_field ei_version1_only
;
61 static dissector_handle_t xml_handle
;
62 static dissector_handle_t rmt_lct_handle
;
63 static dissector_handle_t rmt_fec_handle
;
65 static dissector_table_t media_type_dissector_table
;
67 static bool g_codepoint_as_fec_encoding
= true;
68 static int g_ext_192
= LCT_PREFS_EXT_192_FLUTE
;
69 static int g_ext_193
= LCT_PREFS_EXT_193_FLUTE
;
70 static int g_atsc3_mode
= LCT_ATSC3_MODE_AUTO
;
73 try_decode_payload(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_item
*tree
)
75 uint32_t b03
= tvb_get_uint32(tvb
, 0, ENC_BIG_ENDIAN
);
77 if (b03
== 0x3C3F786D) {
78 call_dissector(xml_handle
, tvb
, pinfo
, tree
);
80 uint32_t b47
= tvb_get_uint32(tvb
, 4, ENC_BIG_ENDIAN
);
81 /* mp4 ("ftyp" or "sidx" or "styp" mp4 box) */
82 if (b47
== 0x66747970 || b47
== 0x73696478 || b47
== 0x73747970) {
83 /* MP4 dissector removes useful info from Protocol and Info columns so store it */
84 char *col_info_text
= wmem_strdup(pinfo
->pool
, col_get_text(pinfo
->cinfo
, COL_INFO
));
85 char *col_protocol_text
= wmem_strdup(pinfo
->pool
, col_get_text(pinfo
->cinfo
, COL_PROTOCOL
));
87 int mp4_dis
= dissector_try_string_with_data(media_type_dissector_table
, "video/mp4", tvb
, pinfo
, tree
, true, NULL
);
88 char *col_protocol_text_mp4
= wmem_strdup(pinfo
->pool
,col_get_text(pinfo
->cinfo
, COL_PROTOCOL
));
90 /* Restore Protocol and Info columns and add MP4 Protocol Info */
91 col_set_str(pinfo
->cinfo
, COL_INFO
, col_info_text
);
92 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, col_protocol_text
);
94 col_append_sep_str(pinfo
->cinfo
, COL_PROTOCOL
, "/", col_protocol_text_mp4
);
101 try_uncompress(tvbuff_t
*tvb
, packet_info
*pinfo
, int offset
, /*int len,*/ proto_item
*ti
)
103 tvbuff_t
*uncompress_tvb
= tvb_uncompress_zlib(tvb
, offset
, tvb_captured_length(tvb
) - offset
);
104 if (uncompress_tvb
) {
105 add_new_data_source(pinfo
, uncompress_tvb
, "Uncompressed Payload");
107 proto_tree
*uncompress_tree
= proto_item_add_subtree(ti
, ett_uncomp_payload
);
108 unsigned decomp_length
= tvb_captured_length(uncompress_tvb
);
109 proto_item
*ti_uncomp
= proto_tree_add_item(uncompress_tree
, hf_uncomp_payload
, uncompress_tvb
, 0, decomp_length
, ENC_ASCII
);
110 proto_item_set_generated(ti_uncomp
);
112 proto_tree
*payload_tree
= proto_item_add_subtree(ti_uncomp
, ett_uncomp_decode
);
113 try_decode_payload(uncompress_tvb
, pinfo
, payload_tree
);
117 /* Code to actually dissect the packets */
118 /* ==================================== */
120 dissect_alc(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
123 lct_data_exchange_t lct
;
124 fec_data_exchange_t fec
;
128 if (g_atsc3_mode
== LCT_ATSC3_MODE_FORCE
) {
130 } else if (g_atsc3_mode
== LCT_ATSC3_MODE_DISABLED
) {
132 } else { /* Auto detect mode*/
133 /* If packet encap is ALP then it is necessary to use ATSC decoding mode*/
134 is_atsc3
= pinfo
->rec
->rec_header
.packet_header
.pkt_encap
== WTAP_ENCAP_ATSC_ALP
;
137 /* Offset for subpacket dissection */
140 /* Set up structures needed to add the protocol subtree and manage it */
142 proto_tree
*alc_tree
;
146 /* Make entries in Protocol column and Info column on summary display */
147 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "ALC");
148 col_clear(pinfo
->cinfo
, COL_INFO
);
150 /* ALC header dissection */
151 /* --------------------- */
153 version
= hi_nibble(tvb_get_uint8(tvb
, offset
));
155 /* Create subtree for the ALC protocol */
156 ti
= proto_tree_add_item(tree
, proto_rmt_alc
, tvb
, offset
, -1, ENC_NA
);
157 alc_tree
= proto_item_add_subtree(ti
, ett_main
);
159 /* Fill the ALC subtree */
160 ti
= proto_tree_add_uint(alc_tree
, hf_version
, tvb
, offset
, 1, version
);
161 PROTO_ITEM_SET_GENERATED(
162 proto_tree_add_boolean(alc_tree
, hf_atsc3
, 0, 0, 0, is_atsc3
)
165 /* This dissector supports only ALCv1 packets.
166 * If version > 1 print only version field and quit.
169 expert_add_info(pinfo
, ti
, &ei_version1_only
);
171 /* Complete entry in Info column on summary display */
172 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Version: %u (not supported)", version
);
176 /* LCT header dissection */
177 /* --------------------- */
178 new_tvb
= tvb_new_subset_remaining(tvb
,offset
);
180 lct
.ext_192
= g_ext_192
;
181 lct
.ext_193
= g_ext_193
;
183 lct
.is_flute
= false;
184 lct
.is_atsc3
= is_atsc3
;
186 len
= call_dissector_with_data(rmt_lct_handle
, new_tvb
, pinfo
, alc_tree
, &lct
);
192 /* FEC header dissection */
193 /* --------------------- */
195 /* Only if LCT dissector has determined FEC Encoding ID */
196 /* FEC dissector needs to be called with encoding_id filled */
197 if (!lct
.is_sp
&& g_codepoint_as_fec_encoding
&& tvb_reported_length(tvb
) > offset
)
199 fec
.encoding_id
= lct
.codepoint
;
201 new_tvb
= tvb_new_subset_remaining(tvb
,offset
);
202 len
= call_dissector_with_data(rmt_fec_handle
, new_tvb
, pinfo
, alc_tree
, &fec
);
209 /* A/331 specifies start_offset field */
210 int64_t object_start_offset
= -1;
212 object_start_offset
= tvb_get_uint32(tvb
, offset
, 4);
213 proto_tree_add_item(alc_tree
, hf_object_start_offset
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
217 /* Add the Payload item */
218 if (tvb_reported_length(tvb
) > offset
){
220 new_tvb
= tvb_new_subset_remaining(tvb
,offset
);
221 call_dissector(xml_handle
, new_tvb
, pinfo
, alc_tree
);
223 ti
= proto_tree_add_item(alc_tree
, hf_payload
, tvb
, offset
, -1, ENC_NA
);
224 if (object_start_offset
== 0 &&
225 tvb_captured_length_remaining(tvb
, offset
) > 18 &&
226 tvb_get_uint16(tvb
, offset
, ENC_BIG_ENDIAN
) == 0x1f8b) {
227 /* gzip is detected */
228 try_uncompress(tvb
, pinfo
, offset
, ti
);
229 } else if (object_start_offset
== 0) {
230 /* gzip is not detected */
231 new_tvb
= tvb_new_subset_remaining(tvb
, offset
);
232 try_decode_payload(new_tvb
, pinfo
, alc_tree
);
237 /* Add Channel info in ATSC3 mode */
239 char *channel_info
= get_slt_channel_info(pinfo
);
240 if (channel_info
!= NULL
) {
241 col_append_sep_str(pinfo
->cinfo
, COL_INFO
, " ", channel_info
);
242 wmem_free(pinfo
->pool
, channel_info
);
246 return tvb_reported_length(tvb
);
251 dissect_alc_heur_udp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
253 /* Lookup over ATSC3 SLT Table*/
254 if (!test_alc_over_slt(pinfo
, tvb
, 0, data
))
257 conversation_t
*conversation
= find_or_create_conversation(pinfo
);
258 conversation_set_dissector(conversation
, alc_handle
);
260 return (dissect_alc(tvb
, pinfo
, tree
, data
) != 0);
263 void proto_register_alc(void)
265 /* Setup ALC header fields */
266 static hf_register_info hf_ptr
[] = {
269 { "Version", "alc.version", FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
272 { "Decode as ATSC3", "alc.atsc3", FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
274 { &hf_object_start_offset
,
275 { "Object Start Offset", "alc.object_start_offset", FT_UINT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
278 { "Payload", "alc.payload", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
280 { &hf_uncomp_payload
,
281 { "Uncompressed Payload", "alc.payload.uncompressed", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
284 /* Setup protocol subtree array */
285 static int *ett_ptr
[] = {
291 static ei_register_info ei
[] = {
292 { &ei_version1_only
, { "alc.version1_only", PI_PROTOCOL
, PI_WARN
, "Sorry, this dissector supports ALC version 1 only", EXPFILL
}},
296 expert_module_t
* expert_rmt_alc
;
298 /* Register the protocol name and description */
299 proto_rmt_alc
= proto_register_protocol("Asynchronous Layered Coding", "ALC", "alc");
300 alc_handle
= register_dissector("alc", dissect_alc
, proto_rmt_alc
);
302 /* Register the header fields and subtrees used */
303 proto_register_field_array(proto_rmt_alc
, hf_ptr
, array_length(hf_ptr
));
304 proto_register_subtree_array(ett_ptr
, array_length(ett_ptr
));
305 expert_rmt_alc
= expert_register_protocol(proto_rmt_alc
);
306 expert_register_field_array(expert_rmt_alc
, ei
, array_length(ei
));
308 /* Register preferences */
309 module
= prefs_register_protocol(proto_rmt_alc
, NULL
);
311 prefs_register_obsolete_preference(module
, "default.udp_port.enabled");
313 prefs_register_bool_preference(module
,
314 "lct.codepoint_as_fec_id",
315 "LCT Codepoint as FEC Encoding ID",
316 "Whether the LCT header Codepoint field should be considered the FEC Encoding ID of carried object",
317 &g_codepoint_as_fec_encoding
);
319 prefs_register_enum_preference(module
,
321 "LCT header extension 192",
322 "How to decode LCT header extension 192",
327 prefs_register_enum_preference(module
,
329 "LCT header extension 193",
330 "How to decode LCT header extension 193",
335 prefs_register_enum_preference(module
,
338 "How to detect ATSC3 data",
344 void proto_reg_handoff_alc(void)
346 dissector_add_for_decode_as_with_preference("udp.port", alc_handle
);
347 xml_handle
= find_dissector_add_dependency("xml", proto_rmt_alc
);
348 rmt_lct_handle
= find_dissector_add_dependency("rmt-lct", proto_rmt_alc
);
349 rmt_fec_handle
= find_dissector_add_dependency("rmt-fec", proto_rmt_alc
);
350 heur_dissector_add("udp", dissect_alc_heur_udp
, "Asynchronous Layered Coding",
351 "alc", proto_rmt_alc
, HEURISTIC_ENABLE
);
353 media_type_dissector_table
= find_dissector_table("media_type");
357 * Editor modelines - https://www.wireshark.org/tools/modelines.html
362 * indent-tabs-mode: nil
365 * ex: set shiftwidth=4 tabstop=8 expandtab:
366 * :indentSize=4:tabSize=8:noTabs=true: