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