/src/wireshark/epan/dissectors/packet-etv.c
Line | Count | Source |
1 | | /* packet-etv.c |
2 | | * |
3 | | * Routines for ETV-AM from OC-SP-ETV-AM1.0-IO5 |
4 | | * Copyright 2012, Weston Schmidt <weston_schmidt@alumni.purdue.edu> |
5 | | * |
6 | | * Wireshark - Network traffic analyzer |
7 | | * By Gerald Combs <gerald@wireshark.org> |
8 | | * Copyright 1998 Gerald Combs |
9 | | * |
10 | | * SPDX-License-Identifier: GPL-2.0-or-later |
11 | | */ |
12 | | |
13 | | #include "config.h" |
14 | | |
15 | | #include <epan/packet.h> |
16 | | #include <epan/expert.h> |
17 | | #include "packet-mpeg-sect.h" |
18 | | |
19 | | void proto_register_etv(void); |
20 | | void proto_reg_handoff_etv(void); |
21 | | |
22 | | static dissector_handle_t etv_dii_handle; |
23 | | static dissector_handle_t etv_ddb_handle; |
24 | | |
25 | | static int proto_etv_dii; |
26 | | static int proto_etv_ddb; |
27 | | |
28 | | static dissector_handle_t dsmcc_handle; |
29 | | |
30 | | static int hf_etv_dii_filter_info; |
31 | | static int hf_etv_dii_reserved; |
32 | | |
33 | | static expert_field ei_etv_dii_invalid_section_syntax_indicator; |
34 | | static expert_field ei_etv_dii_invalid_section_length; |
35 | | static expert_field ei_etv_dii_invalid_reserved_bits; |
36 | | static expert_field ei_etv_dii_filter_info; |
37 | | |
38 | | static int hf_etv_ddb_filter_info; |
39 | | static int hf_etv_ddb_reserved; |
40 | | |
41 | | static expert_field ei_etv_ddb_invalid_section_syntax_indicator; |
42 | | static expert_field ei_etv_ddb_invalid_section_length; |
43 | | static expert_field ei_etv_ddb_invalid_reserved_bits; |
44 | | static expert_field ei_etv_ddb_filter_info; |
45 | | |
46 | | static int ett_etv; |
47 | | static int ett_etv_payload; |
48 | | |
49 | | static void |
50 | | dissect_etv_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int proto, |
51 | | int hf_filter_info, int hf_reserved, |
52 | | expert_field* ei_section_syntax_indicator, expert_field* ei_reserved, |
53 | | expert_field* ei_section_length, expert_field* ei_filter_info) |
54 | 6 | { |
55 | 6 | tvbuff_t *sub_tvb; |
56 | 6 | unsigned offset = 0; |
57 | 6 | proto_item *ti; |
58 | 6 | proto_item *pi; |
59 | 6 | proto_tree *etv_tree; |
60 | 6 | proto_item *items[PACKET_MPEG_SECT_PI__SIZE]; |
61 | 6 | bool ssi; |
62 | 6 | unsigned reserved; |
63 | 6 | uint8_t reserved2; |
64 | 6 | uint16_t filter_info; |
65 | 6 | unsigned sect_len; |
66 | | |
67 | 6 | ti = proto_tree_add_item(tree, proto, tvb, offset, -1, ENC_NA); |
68 | 6 | etv_tree = proto_item_add_subtree(ti, ett_etv); |
69 | | |
70 | 6 | offset += packet_mpeg_sect_header_extra(tvb, offset, etv_tree, §_len, |
71 | 6 | &reserved, &ssi, items); |
72 | | |
73 | 6 | if (false != ssi) { |
74 | 4 | proto_item *msg_error; |
75 | 4 | msg_error = items[PACKET_MPEG_SECT_PI__SSI]; |
76 | | |
77 | 4 | proto_item_set_generated(msg_error); |
78 | 4 | expert_add_info(pinfo, msg_error, ei_section_syntax_indicator); |
79 | 4 | } |
80 | | |
81 | 6 | if (4 != reserved) { |
82 | 6 | proto_item *msg_error; |
83 | 6 | msg_error = items[PACKET_MPEG_SECT_PI__RESERVED]; |
84 | | |
85 | 6 | proto_item_set_generated(msg_error); |
86 | 6 | expert_add_info(pinfo, msg_error, ei_reserved); |
87 | 6 | } |
88 | | |
89 | 6 | col_append_fstr(pinfo->cinfo, COL_INFO, ", Length: %u", sect_len); |
90 | 6 | proto_item_append_text(ti, " Length=%u", sect_len); |
91 | 6 | if (1021 < sect_len) { |
92 | 1 | proto_item *msg_error; |
93 | 1 | msg_error = items[PACKET_MPEG_SECT_PI__LENGTH]; |
94 | | |
95 | 1 | proto_item_set_generated(msg_error); |
96 | 1 | expert_add_info(pinfo, msg_error, ei_section_length); |
97 | 1 | } |
98 | | |
99 | 6 | filter_info = tvb_get_ntohs(tvb, offset); |
100 | 6 | col_append_fstr(pinfo->cinfo, COL_INFO, ", Filter: 0x%x", filter_info); |
101 | 6 | proto_item_append_text(ti, " Filter=0x%x", filter_info); |
102 | 6 | pi = proto_tree_add_item(etv_tree, hf_filter_info, tvb, offset, 2, ENC_BIG_ENDIAN); |
103 | 6 | if ((proto_etv_dii == proto) && (0xFBFB != filter_info)) { |
104 | 4 | expert_add_info_format(pinfo, pi, ei_filter_info, |
105 | 4 | "Invalid filter_info value (must be 0xFBFB)"); |
106 | 4 | } else if ((proto_etv_ddb == proto) && |
107 | 1 | ((filter_info < 1) || (0xfbef < filter_info))) |
108 | 0 | { |
109 | 0 | expert_add_info_format(pinfo, pi, ei_filter_info, |
110 | 0 | "Invalid filter_info value (must be [0x0001-0xFBEF] inclusive)"); |
111 | 0 | } |
112 | 6 | offset += 2; |
113 | | |
114 | 6 | reserved2 = tvb_get_uint8(tvb, offset); |
115 | 6 | pi = proto_tree_add_item(etv_tree, hf_reserved, tvb, offset, 1, ENC_BIG_ENDIAN); |
116 | 6 | if (0 != reserved2) { |
117 | 5 | expert_add_info_format(pinfo, pi, ei_reserved, |
118 | 5 | "Invalid reserved2 bits (should all be 0)"); |
119 | 5 | } |
120 | 6 | offset += 1; |
121 | | |
122 | 6 | sub_tvb = tvb_new_subset_length(tvb, offset, sect_len-7); |
123 | 6 | call_dissector(dsmcc_handle, sub_tvb, pinfo, tree); |
124 | | |
125 | 6 | sect_len += 3 - 4; /* add header, remove crc */ |
126 | | |
127 | 6 | packet_mpeg_sect_crc(tvb, pinfo, etv_tree, 0, sect_len); |
128 | 6 | } |
129 | | |
130 | | |
131 | | static int |
132 | | dissect_etv_ddb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) |
133 | 1 | { |
134 | 1 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "ETV-DDB"); |
135 | 1 | col_set_str(pinfo->cinfo, COL_INFO, "ETV DDB"); |
136 | | |
137 | 1 | dissect_etv_common(tvb, pinfo, tree, proto_etv_ddb, hf_etv_ddb_filter_info, |
138 | 1 | hf_etv_ddb_reserved, &ei_etv_ddb_invalid_section_syntax_indicator, |
139 | 1 | &ei_etv_ddb_invalid_reserved_bits, &ei_etv_ddb_invalid_section_length, |
140 | 1 | &ei_etv_ddb_filter_info); |
141 | 1 | return tvb_captured_length(tvb); |
142 | 1 | } |
143 | | |
144 | | |
145 | | static int |
146 | | dissect_etv_dii(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) |
147 | 5 | { |
148 | 5 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "ETV-DII"); |
149 | 5 | col_set_str(pinfo->cinfo, COL_INFO, "ETV DII"); |
150 | 5 | dissect_etv_common(tvb, pinfo, tree, proto_etv_dii, hf_etv_dii_filter_info, |
151 | 5 | hf_etv_dii_reserved, &ei_etv_dii_invalid_section_syntax_indicator, |
152 | 5 | &ei_etv_dii_invalid_reserved_bits, &ei_etv_dii_invalid_section_length, |
153 | 5 | &ei_etv_dii_filter_info); |
154 | 5 | return tvb_captured_length(tvb); |
155 | 5 | } |
156 | | |
157 | | |
158 | | void |
159 | | proto_register_etv(void) |
160 | 14 | { |
161 | 14 | static hf_register_info hf_ddb[] = { |
162 | 14 | { &hf_etv_ddb_filter_info, { |
163 | 14 | "Filter Info", "etv-ddb.filter_info", |
164 | 14 | FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL |
165 | 14 | } }, |
166 | | |
167 | 14 | { &hf_etv_ddb_reserved, { |
168 | 14 | "Reserved", "etv-ddb.reserved", |
169 | 14 | FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL |
170 | 14 | } } |
171 | 14 | }; |
172 | | |
173 | 14 | static hf_register_info hf_dii[] = { |
174 | 14 | { &hf_etv_dii_filter_info, { |
175 | 14 | "Filter Info", "etv-dii.filter_info", |
176 | 14 | FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL |
177 | 14 | } }, |
178 | | |
179 | 14 | { &hf_etv_dii_reserved, { |
180 | 14 | "Reserved", "etv-dii.reserved", |
181 | 14 | FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL |
182 | 14 | } } |
183 | 14 | }; |
184 | | |
185 | 14 | static int *ett[] = { |
186 | 14 | &ett_etv, |
187 | 14 | &ett_etv_payload |
188 | 14 | }; |
189 | | |
190 | 14 | static ei_register_info ei_ddb[] = { |
191 | 14 | { &ei_etv_ddb_invalid_section_syntax_indicator, { "etv-ddb.invalid_section_syntax_indicator", PI_MALFORMED, PI_ERROR, "Invalid section_syntax_indicator (should be 0)", EXPFILL }}, |
192 | 14 | { &ei_etv_ddb_invalid_reserved_bits, { "etv-ddb.invalid_reserved_bits", PI_MALFORMED, PI_ERROR, "Invalid reserved bits", EXPFILL }}, |
193 | 14 | { &ei_etv_ddb_invalid_section_length, { "etv-ddb.invalid_section_length", PI_MALFORMED, PI_ERROR, "Invalid section_length (must not exceed 1021)", EXPFILL }}, |
194 | 14 | { &ei_etv_ddb_filter_info, { "etv-ddb.filter_info.invalid", PI_MALFORMED, PI_ERROR, "Invalid filter info", EXPFILL }}, |
195 | 14 | }; |
196 | | |
197 | 14 | static ei_register_info ei_dii[] = { |
198 | 14 | { &ei_etv_dii_invalid_section_syntax_indicator, { "etv-dii.invalid_section_syntax_indicator", PI_MALFORMED, PI_ERROR, "Invalid section_syntax_indicator (should be 0)", EXPFILL }}, |
199 | 14 | { &ei_etv_dii_invalid_reserved_bits, { "etv-dii.invalid_reserved_bits", PI_MALFORMED, PI_ERROR, "Invalid reserved bits", EXPFILL }}, |
200 | 14 | { &ei_etv_dii_invalid_section_length, { "etv-dii.invalid_section_length", PI_MALFORMED, PI_ERROR, "Invalid section_length (must not exceed 1021)", EXPFILL }}, |
201 | 14 | { &ei_etv_dii_filter_info, { "etv-dii.filter_info.invalid", PI_MALFORMED, PI_ERROR, "Invalid filter info", EXPFILL }}, |
202 | 14 | }; |
203 | | |
204 | 14 | expert_module_t* expert_etv_dii; |
205 | 14 | expert_module_t* expert_etv_ddb; |
206 | | |
207 | 14 | proto_etv_dii = proto_register_protocol("ETV-AM DII Section", "ETV-AM DII", "etv-dii"); |
208 | 14 | proto_etv_ddb = proto_register_protocol("ETV-AM DDB Section", "ETV-AM DDB", "etv-ddb"); |
209 | | |
210 | 14 | proto_register_field_array(proto_etv_dii, hf_dii, array_length(hf_dii)); |
211 | 14 | proto_register_field_array(proto_etv_ddb, hf_ddb, array_length(hf_ddb)); |
212 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
213 | 14 | expert_etv_dii = expert_register_protocol(proto_etv_dii); |
214 | 14 | expert_register_field_array(expert_etv_dii, ei_dii, array_length(ei_dii)); |
215 | 14 | expert_etv_ddb = expert_register_protocol(proto_etv_ddb); |
216 | 14 | expert_register_field_array(expert_etv_ddb, ei_ddb, array_length(ei_ddb)); |
217 | | |
218 | 14 | etv_dii_handle = register_dissector("etv-dii", dissect_etv_dii, proto_etv_dii); |
219 | 14 | etv_ddb_handle = register_dissector("etv-ddb", dissect_etv_ddb, proto_etv_ddb); |
220 | 14 | } |
221 | | |
222 | | |
223 | | void |
224 | | proto_reg_handoff_etv(void) |
225 | 14 | { |
226 | 14 | dissector_add_uint("mpeg_sect.tid", ETV_TID_DII_SECTION, etv_dii_handle); |
227 | 14 | dissector_add_uint("mpeg_sect.tid", ETV_TID_DDB_SECTION, etv_ddb_handle); |
228 | 14 | dsmcc_handle = find_dissector_add_dependency("mp2t-dsmcc", proto_etv_dii); |
229 | 14 | find_dissector_add_dependency("mp2t-dsmcc", proto_etv_ddb); |
230 | 14 | } |
231 | | |
232 | | /* |
233 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
234 | | * |
235 | | * Local variables: |
236 | | * c-basic-offset: 8 |
237 | | * tab-width: 8 |
238 | | * indent-tabs-mode: t |
239 | | * End: |
240 | | * |
241 | | * vi: set shiftwidth=8 tabstop=8 noexpandtab: |
242 | | * :indentSize=8:tabSize=8:noTabs=false: |
243 | | */ |