epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-rmt-fec.c
blob053c43133ca24983b995cbb96fea452b071d15b9
1 /* packet-rmt-fec.c
2 * Reliable Multicast Transport (RMT)
3 * FEC Building Block dissector
4 * Copyright 2005, Stefano Pettini <spettini@users.sourceforge.net>
6 * Forward Error Correction (ALC):
7 * -------------------------------
9 * The goal of the FEC building block is to describe functionality
10 * directly related to FEC codes that is common to all reliable content
11 * delivery IP multicast protocols, and to leave out any additional
12 * functionality that is specific to particular protocols.
14 * References:
15 * RFC 3452, Forward Error Correction Building Block
16 * RFC 3695, Compact Forward Error Correction (FEC) Schemes
17 * Simple XOR, Reed-Solomon, and Parity Check Matrix-based FEC Schemes draft-peltotalo-rmt-bb-fec-supp-xor-pcm-rs-00
18 * IANA RMT FEC parameters (http://www.iana.org/assignments/rmt-fec-parameters)
20 * Wireshark - Network traffic analyzer
21 * By Gerald Combs <gerald@wireshark.org>
22 * Copyright 1998 Gerald Combs
24 * SPDX-License-Identifier: GPL-2.0-or-later
27 #include "config.h"
29 #include <epan/packet.h>
30 #include <epan/expert.h>
31 #include <epan/proto_data.h>
32 #include "packet-rmt-common.h"
34 void proto_register_rmt_fec(void);
36 static int proto_rmt_fec;
38 static int hf_encoding_id;
39 static int hf_instance_id;
40 static int hf_sbn;
41 static int hf_sbn_with_mask;
42 static int hf_sbl;
43 static int hf_esi;
44 static int hf_esi_with_mask;
45 static int hf_fti_transfer_length;
46 static int hf_fti_encoding_symbol_length;
47 static int hf_fti_max_source_block_length;
48 static int hf_fti_max_number_encoding_symbols;
49 static int hf_fti_num_blocks;
50 static int hf_fti_num_subblocks;
51 static int hf_fti_alignment;
53 static int ett_main;
55 static expert_field ei_fec_encoding_id;
57 typedef struct fec_packet_data
59 uint8_t instance_id;
61 } fec_packet_data_t;
64 /* String tables */
65 const value_string string_fec_encoding_id[] =
67 { 0, "Compact No-Code" },
68 { 1, "Raptor" },
69 { 2, "Reed-Solomon Codes over GF(2^^m)" },
70 { 3, "LDPC Staircase Codes" },
71 { 4, "LDPC Triangle Codes" },
72 { 5, "Reed-Solomon Codes over GF(2^^8)" },
73 { 6, "RaptorQ Code" },
74 /* 7-127 Unassigned */
75 { 128, "Small Block, Large Block and Expandable FEC Codes" },
76 { 129, "Small Block Systematic FEC Codes" },
77 { 130, "Compact FEC Codes" },
78 /* 131-255 Unassigned */
79 { 0, NULL }
82 /* Dissection */
83 /* ---------- */
85 /* Decode an EXT_FTI extension and fill FEC array */
86 void fec_decode_ext_fti(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint8_t encoding_id)
88 uint64_t transfer_length;
89 fec_packet_data_t *fec_data;
90 uint8_t instance_id = 0;
91 proto_item *ti;
93 if (encoding_id == 6){
94 /* Raptor Q uses 40-bit transfer length */
95 transfer_length = tvb_get_ntoh40(tvb, offset+2);
97 else {
98 /* Decode 48-bit length field */
99 transfer_length = tvb_get_ntoh48(tvb, offset+2);
102 if (encoding_id >= 128)
104 instance_id = (uint8_t) tvb_get_ntohs(tvb, offset+8);
106 /* Decode FEC Instance ID */
107 fec_data = wmem_new0(wmem_file_scope(), fec_packet_data_t);
108 fec_data->instance_id = instance_id;
110 p_add_proto_data(wmem_file_scope(), pinfo, proto_rmt_fec, 0, fec_data);
113 if (encoding_id == 6){
114 /* Raptor Q uses 40-bit transfer length */
115 proto_tree_add_uint64(tree, hf_fti_transfer_length, tvb, offset+2, 5, transfer_length);
117 else {
118 proto_tree_add_uint64(tree, hf_fti_transfer_length, tvb, offset+2, 6, transfer_length);
119 ti = proto_tree_add_item(tree, hf_instance_id, tvb, offset+8, 2, ENC_BIG_ENDIAN);
120 if ((encoding_id < 128) && (encoding_id != 0)) {
121 expert_add_info(pinfo, ti, &ei_fec_encoding_id);
125 switch (encoding_id)
127 case 1:
128 proto_tree_add_item(tree, hf_fti_encoding_symbol_length, tvb, offset+10, 2, ENC_BIG_ENDIAN);
129 proto_tree_add_item(tree, hf_fti_num_blocks, tvb, offset+12, 2, ENC_BIG_ENDIAN);
130 proto_tree_add_item(tree, hf_fti_num_subblocks, tvb, offset+14, 1, ENC_BIG_ENDIAN);
131 proto_tree_add_item(tree, hf_fti_alignment, tvb, offset+15, 1, ENC_BIG_ENDIAN);
132 break;
134 case 6:
135 proto_tree_add_item(tree, hf_fti_encoding_symbol_length, tvb, offset+8, 2, ENC_BIG_ENDIAN);
136 proto_tree_add_item(tree, hf_fti_num_blocks, tvb, offset+10, 1, ENC_BIG_ENDIAN);
137 proto_tree_add_item(tree, hf_fti_num_subblocks, tvb, offset+11, 2, ENC_BIG_ENDIAN);
138 proto_tree_add_item(tree, hf_fti_alignment, tvb, offset+13, 1, ENC_BIG_ENDIAN);
139 break;
141 case 0:
142 case 2:
143 case 128:
144 case 130:
145 proto_tree_add_item(tree, hf_fti_encoding_symbol_length, tvb, offset+10, 2, ENC_BIG_ENDIAN);
146 proto_tree_add_item(tree, hf_fti_max_source_block_length, tvb, offset+12, 4, ENC_BIG_ENDIAN);
147 break;
149 case 129:
150 proto_tree_add_item(tree, hf_fti_encoding_symbol_length, tvb, offset+10, 2, ENC_BIG_ENDIAN);
151 proto_tree_add_item(tree, hf_fti_max_source_block_length, tvb, offset+12, 2, ENC_BIG_ENDIAN);
152 proto_tree_add_item(tree, hf_fti_max_number_encoding_symbols, tvb, offset+14, 2, ENC_BIG_ENDIAN);
153 break;
155 case 132:
156 proto_tree_add_item(tree, hf_fti_encoding_symbol_length, tvb, offset+10, 2, ENC_BIG_ENDIAN);
157 proto_tree_add_item(tree, hf_fti_max_source_block_length, tvb, offset+12, 4, ENC_BIG_ENDIAN);
158 proto_tree_add_item(tree, hf_fti_max_number_encoding_symbols, tvb, offset+16, 4, ENC_BIG_ENDIAN);
159 break;
163 /* Dissect a FEC header:
164 * fec - ptr to the logical FEC packet representation to fill
165 * hf - ptr to header fields array
166 * ett - ptr to ett array
167 * prefs - ptr to FEC prefs array
168 * tvb - buffer
169 * pinfo - packet info
170 * tree - tree where to add FEC header subtree
171 * offset - ptr to offset to use and update
173 static int
174 dissect_fec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
176 proto_item *ti;
177 proto_tree *fec_tree;
178 unsigned offset = 0;
179 fec_data_exchange_t *fec = (fec_data_exchange_t*)data;
180 uint8_t encoding_id = 0;
181 fec_packet_data_t *packet_data = (fec_packet_data_t*)p_get_proto_data(wmem_file_scope(), pinfo, proto_rmt_fec, 0);
183 if (fec != NULL)
185 encoding_id = fec->encoding_id;
188 /* Create the FEC subtree */
189 ti = proto_tree_add_item(tree, proto_rmt_fec, tvb, offset, -1, ENC_NA);
190 fec_tree = proto_item_add_subtree(ti, ett_main);
192 proto_tree_add_uint(fec_tree, hf_encoding_id, tvb, offset, 0, encoding_id);
194 if (encoding_id >= 128 && (packet_data != NULL))
195 proto_tree_add_uint(fec_tree, hf_instance_id, tvb, offset, 0, packet_data->instance_id);
197 switch (encoding_id)
199 case 0:
200 case 1:
201 case 130:
202 proto_tree_add_item(fec_tree, hf_sbn, tvb, offset, 2, ENC_BIG_ENDIAN);
203 proto_tree_add_item(fec_tree, hf_esi, tvb, offset+2, 2, ENC_BIG_ENDIAN);
205 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "SBN: %u", tvb_get_ntohs(tvb, offset));
206 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "ESI: 0x%X", tvb_get_ntohs(tvb, offset+2));
208 offset += 4;
209 break;
211 case 2:
212 case 128:
213 case 132:
214 proto_tree_add_item(fec_tree, hf_sbn, tvb, offset, 4, ENC_BIG_ENDIAN);
215 proto_tree_add_item(fec_tree, hf_esi, tvb, offset+4, 4, ENC_BIG_ENDIAN);
217 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "SBN: %u", tvb_get_ntohl(tvb, offset));
218 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "ESI: 0x%X", tvb_get_ntohl(tvb, offset+4));
220 offset += 8;
221 break;
223 case 3:
224 case 4:
225 proto_tree_add_item(fec_tree, hf_sbn_with_mask, tvb, offset, 4, ENC_BIG_ENDIAN);
226 proto_tree_add_item(fec_tree, hf_esi_with_mask, tvb, offset, 4, ENC_BIG_ENDIAN);
228 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "SBN: %u", tvb_get_ntohl(tvb, offset) >> 20);
229 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "ESI: 0x%X", tvb_get_ntohl(tvb, offset) & 0xfffff);
231 offset += 4;
232 break;
234 case 6:
235 proto_tree_add_item(fec_tree, hf_sbn, tvb, offset, 1, ENC_BIG_ENDIAN);
236 proto_tree_add_item(fec_tree, hf_esi, tvb, offset+1, 3, ENC_BIG_ENDIAN);
238 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "SBN: %u", tvb_get_uint8(tvb, offset));
239 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "ESI: 0x%X", tvb_get_ntoh24(tvb, offset+1));
241 offset += 4;
242 break;
244 case 129:
245 proto_tree_add_item(fec_tree, hf_sbn, tvb, offset, 4, ENC_BIG_ENDIAN);
246 proto_tree_add_item(fec_tree, hf_sbl, tvb, offset+4, 2, ENC_BIG_ENDIAN);
247 proto_tree_add_item(fec_tree, hf_esi, tvb, offset+6, 2, ENC_BIG_ENDIAN);
249 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "SBN: %u", tvb_get_ntohl(tvb, offset));
250 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "ESI: 0x%X", tvb_get_ntohs(tvb, offset+6));
252 offset += 8;
253 break;
256 return offset;
259 void proto_register_rmt_fec(void)
261 static hf_register_info hf[] = {
262 { &hf_encoding_id,
263 { "FEC Encoding ID", "rmt-fec.encoding_id",
264 FT_UINT8, BASE_DEC, VALS(string_fec_encoding_id), 0x0,
265 NULL, HFILL }
267 { &hf_instance_id,
268 { "FEC Instance ID", "rmt-fec.instance_id",
269 FT_UINT16, BASE_DEC, NULL, 0x0,
270 NULL, HFILL }
272 { &hf_sbn,
273 { "Source Block Number", "rmt-fec.sbn",
274 FT_UINT32, BASE_DEC, NULL, 0x0,
275 NULL, HFILL }
277 { &hf_sbn_with_mask,
278 { "Source Block Number", "rmt-fec.sbn",
279 FT_UINT32, BASE_DEC, NULL, 0xFFF00000,
280 NULL, HFILL }
282 { &hf_sbl,
283 { "Source Block Length", "rmt-fec.sbl",
284 FT_UINT32, BASE_DEC, NULL, 0x0,
285 NULL, HFILL }
287 { &hf_esi,
288 { "Encoding Symbol ID", "rmt-fec.esi",
289 FT_UINT32, BASE_HEX, NULL, 0x0,
290 NULL, HFILL }
292 { &hf_esi_with_mask,
293 { "Encoding Symbol ID", "rmt-fec.esi",
294 FT_UINT32, BASE_HEX, NULL, 0x000FFFFF,
295 NULL, HFILL }
297 { &hf_fti_transfer_length,
298 { "Transfer Length", "rmt-fec.fti.transfer_length",
299 FT_UINT64, BASE_DEC, NULL, 0x0,
300 NULL, HFILL }
302 { &hf_fti_encoding_symbol_length,
303 { "Encoding Symbol Length", "rmt-fec.fti.encoding_symbol_length",
304 FT_UINT32, BASE_DEC, NULL, 0x0,
305 NULL, HFILL }
307 { &hf_fti_max_source_block_length,
308 { "Maximum Source Block Length", "rmt-fec.fti.max_source_block_length",
309 FT_UINT32, BASE_DEC, NULL, 0x0,
310 NULL, HFILL }
312 { &hf_fti_max_number_encoding_symbols,
313 { "Maximum Number of Encoding Symbols", "rmt-fec.fti.max_number_encoding_symbols",
314 FT_UINT32, BASE_DEC, NULL, 0x0,
315 NULL, HFILL }
317 { &hf_fti_num_blocks,
318 { "Number of Source Blocks", "rmt-fec.fti.num_blocks",
319 FT_UINT16, BASE_DEC, NULL, 0x0,
320 NULL, HFILL }
322 { &hf_fti_num_subblocks,
323 { "Number of Sub-Blocks", "rmt-fec.fti.num_subblocks",
324 FT_UINT16, BASE_DEC, NULL, 0x0,
325 NULL, HFILL }
327 { &hf_fti_alignment,
328 { "Symbol Alignment", "rmt-fec.fti.alignment",
329 FT_UINT8, BASE_DEC, NULL, 0x0,
330 NULL, HFILL }
334 /* Setup protocol subtree array */
335 static int *ett[] = {
336 &ett_main,
339 static ei_register_info ei[] = {
340 { &ei_fec_encoding_id, { "rmt-fec.encoding_id.not0", PI_PROTOCOL, PI_WARN, "FEC Encoding ID < 128, should be zero", EXPFILL }},
343 expert_module_t* expert_rmt_fec;
345 /* Register the protocol name and description */
346 proto_rmt_fec = proto_register_protocol("Forward Error Correction (FEC)", "RMT-FEC", "rmt-fec");
347 register_dissector("rmt-fec", dissect_fec, proto_rmt_fec);
349 /* Required function calls to register the header fields and subtrees used */
350 proto_register_field_array(proto_rmt_fec, hf, array_length(hf));
351 proto_register_subtree_array(ett, array_length(ett));
352 expert_rmt_fec = expert_register_protocol(proto_rmt_fec);
353 expert_register_field_array(expert_rmt_fec, ei, array_length(ei));
357 * Editor modelines - https://www.wireshark.org/tools/modelines.html
359 * Local variables:
360 * c-basic-offset: 4
361 * tab-width: 8
362 * indent-tabs-mode: nil
363 * End:
365 * ex: set shiftwidth=4 tabstop=8 expandtab:
366 * :indentSize=4:tabSize=8:noTabs=true: