Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-dvb-data-mpe.c
blobe617d4a0c4ae0a2e287bd71bd330df6b8a810198
1 /* packet-dvb-data-mpe.c
2 * Routines for DVB-DATA (ETSI EN 301 192) MultiProtocol Encapsulation
3 * Copyright 2012, Guy Martin <gmsoft@tuxicoman.be>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/expert.h>
16 #include <epan/to_str.h>
17 #include <epan/tfs.h>
18 #include "packet-mpeg-sect.h"
20 void proto_register_dvb_data_mpe(void);
21 void proto_reg_handoff_dvb_data_mpe(void);
23 static int proto_dvb_data_mpe;
24 static int hf_dvb_data_mpe_reserved;
25 static int hf_dvb_data_mpe_payload_scrambling_control;
26 static int hf_dvb_data_mpe_address_scrambling_control;
27 static int hf_dvb_data_mpe_llc_snap_flag;
28 static int hf_dvb_data_mpe_current_next_indicator;
29 static int hf_dvb_data_mpe_section_number;
30 static int hf_dvb_data_mpe_last_section_number;
31 static int hf_dvb_data_mpe_dst_mac;
32 static int hf_dvb_data_mpe_dst_mac_scrambled;
34 static int ett_dvb_data_mpe;
36 static expert_field ei_dvb_data_mpe_reserved_not_one;
37 static expert_field ei_dvb_data_mpe_payload_scrambled;
38 static expert_field ei_dvb_data_mpe_address_scrambled;
40 static dissector_handle_t dvb_data_mpe_handle;
42 static dissector_handle_t ip_handle;
43 static dissector_handle_t llc_handle;
45 #define DVB_DATA_MPE_RESERVED_MASK 0xC0
46 #define DVB_DATA_MPE_PAYLOAD_SCRAMBLING_MASK 0x30
47 #define DVB_DATA_MPE_ADDRESS_SCRAMBLING_MASK 0x0C
48 #define DVB_DATA_MPE_LLC_SNAP_FLAG_MASK 0x02
49 #define DVB_DATA_MPE_CURRENT_NEXT_INDICATOR_MASK 0x01
51 /* Field positions for the MAC Address */
52 /* It is split into two chunks, one of two octets and a second
53 * one of four octets. Also, the octets are in reverse order. */
54 #define DVB_DATA_MPE_DST_MAC_FIRST 3
55 #define DVB_DATA_MPE_DST_MAC_SECOND 8
57 static const value_string dvb_data_mpe_scrambling_vals[] = {
58 { 0, "Unscrambled" },
59 { 1, "Defined by service" },
60 { 2, "Defined by service" },
61 { 3, "Defined by service" },
62 { 0, NULL }
65 static int
66 dissect_dvb_data_mpe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
69 unsigned offset = 0, tot_len = 0;
70 uint32_t reserved, address_scrambling, payload_scrambling, llc_snap_flag;
71 int i;
73 proto_item *ti;
74 proto_tree *dvb_data_mpe_tree;
75 unsigned char *dst = (unsigned char*)wmem_alloc(pinfo->pool, 6);
76 address dst_addr;
77 tvbuff_t *data_tvb;
79 /* The TVB should start right after the section_length in the Section packet */
81 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DVB-DATA");
82 col_set_str(pinfo->cinfo, COL_INFO, "MultiProtocol Encapsulation");
84 ti = proto_tree_add_item(tree, proto_dvb_data_mpe, tvb, offset, -1, ENC_NA);
85 dvb_data_mpe_tree = proto_item_add_subtree(ti, ett_dvb_data_mpe);
87 offset += packet_mpeg_sect_header(tvb, offset, dvb_data_mpe_tree, &tot_len, NULL);
90 /* Parse the DMC-CC private section header */
92 dst[5] = tvb_get_uint8(tvb, offset);
93 offset += 1;
94 dst[4] = tvb_get_uint8(tvb, offset);
95 offset += 1;
97 ti = proto_tree_add_item_ret_uint(dvb_data_mpe_tree, hf_dvb_data_mpe_reserved, tvb, offset, 1, ENC_BIG_ENDIAN, &reserved);
98 if (reserved != 3) {
99 expert_add_info(pinfo, ti, &ei_dvb_data_mpe_reserved_not_one);
101 ti = proto_tree_add_item_ret_uint(dvb_data_mpe_tree, hf_dvb_data_mpe_payload_scrambling_control, tvb, offset, 1, ENC_BIG_ENDIAN, &payload_scrambling);
102 if (payload_scrambling) {
103 expert_add_info(pinfo, ti, &ei_dvb_data_mpe_payload_scrambled);
105 proto_tree_add_item_ret_uint(dvb_data_mpe_tree, hf_dvb_data_mpe_address_scrambling_control, tvb, offset, 1, ENC_BIG_ENDIAN, &address_scrambling);
106 proto_tree_add_item_ret_uint(dvb_data_mpe_tree, hf_dvb_data_mpe_llc_snap_flag, tvb, offset, 1, ENC_BIG_ENDIAN, &llc_snap_flag);
107 proto_tree_add_item(dvb_data_mpe_tree, hf_dvb_data_mpe_current_next_indicator, tvb, offset, 1, ENC_BIG_ENDIAN);
108 offset += 1;
110 proto_tree_add_item(dvb_data_mpe_tree, hf_dvb_data_mpe_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
111 offset += 1;
113 proto_tree_add_item(dvb_data_mpe_tree, hf_dvb_data_mpe_last_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
114 offset += 1;
116 for (i = 3; i >= 0; i--) {
117 dst[i] = tvb_get_uint8(tvb, offset);
118 offset += 1;
121 if (address_scrambling) {
122 ti = proto_tree_add_bytes_with_length(dvb_data_mpe_tree, hf_dvb_data_mpe_dst_mac_scrambled, tvb, DVB_DATA_MPE_DST_MAC_FIRST, 2, dst, 6);
123 expert_add_info(pinfo, ti, &ei_dvb_data_mpe_address_scrambled);
124 } else {
125 ti = proto_tree_add_ether(dvb_data_mpe_tree, hf_dvb_data_mpe_dst_mac, tvb, DVB_DATA_MPE_DST_MAC_FIRST, 2, dst);
126 set_address(&dst_addr, AT_ETHER, 6, dst);
127 col_add_str(pinfo->cinfo, COL_RES_DL_DST, address_to_str(pinfo->pool, &dst_addr));
129 /* Extend the highlighting for the second chunk. */
130 proto_tree_set_appendix(ti, tvb, DVB_DATA_MPE_DST_MAC_SECOND, 4);
132 data_tvb = tvb_new_subset_remaining(tvb, offset);
134 if (payload_scrambling) {
135 call_data_dissector(data_tvb, pinfo, tree);
136 } else if (llc_snap_flag) {
137 call_dissector(llc_handle, data_tvb, pinfo, tree);
138 } else {
139 call_dissector(ip_handle, data_tvb, pinfo, tree);
142 packet_mpeg_sect_crc(tvb, pinfo, dvb_data_mpe_tree, 0, tot_len - 1);
143 return tvb_captured_length(tvb);
146 void
147 proto_register_dvb_data_mpe(void)
150 static hf_register_info hf[] = {
152 /* DSM-CC common fields */
153 { &hf_dvb_data_mpe_reserved, {
154 "Reserved", "dvb_data_mpe.reserved",
155 FT_UINT8, BASE_HEX, NULL, DVB_DATA_MPE_RESERVED_MASK, NULL, HFILL
156 } },
158 { &hf_dvb_data_mpe_payload_scrambling_control, {
159 "Payload Scrambling Control", "dvb_data_mpe.pload_scrambling",
160 FT_UINT8, BASE_HEX, VALS(dvb_data_mpe_scrambling_vals),
161 DVB_DATA_MPE_PAYLOAD_SCRAMBLING_MASK, NULL, HFILL
162 } },
164 { &hf_dvb_data_mpe_address_scrambling_control, {
165 "Address Scrambling Control", "dvb_data_mpe.addr_scrambling",
166 FT_UINT8, BASE_HEX, VALS(dvb_data_mpe_scrambling_vals),
167 DVB_DATA_MPE_ADDRESS_SCRAMBLING_MASK, NULL, HFILL
168 } },
170 { &hf_dvb_data_mpe_llc_snap_flag, {
171 "LLC SNAP Flag", "dvb_data_mpe.llc_snap_flag",
172 FT_UINT8, BASE_HEX, NULL, DVB_DATA_MPE_LLC_SNAP_FLAG_MASK, NULL, HFILL
173 } },
175 { &hf_dvb_data_mpe_current_next_indicator, {
176 "Current/Next Indicator", "mpeg_sect.cur_next_ind",
177 FT_BOOLEAN, 8, TFS(&tfs_current_not_yet), DVB_DATA_MPE_CURRENT_NEXT_INDICATOR_MASK, NULL, HFILL
178 } },
180 { &hf_dvb_data_mpe_section_number, {
181 "Section Number", "dvb_data_mpe.sect_num",
182 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
183 } },
185 { &hf_dvb_data_mpe_last_section_number, {
186 "Last Section Number", "dvb_data_mpe.last_sect_num",
187 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
188 } },
190 { &hf_dvb_data_mpe_dst_mac, {
191 "Destination MAC address", "dvb_data_mpe.dst_mac",
192 FT_ETHER, BASE_NONE, NULL, 0, NULL, HFILL
193 } },
195 { &hf_dvb_data_mpe_dst_mac_scrambled, {
196 "Destination MAC address (scrambled)",
197 "dvb_data_mpe.dst_mac.scrambled",
198 FT_BYTES, SEP_COLON, NULL, 0, NULL, HFILL
199 } },
203 static int *ett[] = {
204 &ett_dvb_data_mpe,
207 expert_module_t *expert_dvb_data_mpe;
208 static ei_register_info ei[] = {
209 { &ei_dvb_data_mpe_reserved_not_one,
210 { "dvb_data_mpe.reserved.not_one", PI_PROTOCOL, PI_WARN,
211 "Reserved bits not all ones", EXPFILL }},
212 { &ei_dvb_data_mpe_address_scrambled,
213 { "dvb_data_mpe.address_scrambled", PI_UNDECODED, PI_WARN,
214 "Cannot descramble destination MAC address (user private scrambling)", EXPFILL }},
215 { &ei_dvb_data_mpe_payload_scrambled,
216 { "dvb_data_mpe.payload.scrambled", PI_UNDECODED, PI_WARN,
217 "Cannot descramble payload (user private scrambling)", EXPFILL }},
220 proto_dvb_data_mpe = proto_register_protocol("DVB-DATA MultiProtocol Encapsulation", "DVB-DATA MPE", "dvb_data_mpe");
221 proto_register_field_array(proto_dvb_data_mpe, hf, array_length(hf));
222 expert_dvb_data_mpe = expert_register_protocol(proto_dvb_data_mpe);
223 expert_register_field_array(expert_dvb_data_mpe, ei, array_length(ei));
225 proto_register_subtree_array(ett, array_length(ett));
227 dvb_data_mpe_handle = register_dissector("dvb_data_mpe", dissect_dvb_data_mpe, proto_dvb_data_mpe);
231 void
232 proto_reg_handoff_dvb_data_mpe(void)
234 dissector_add_uint("mpeg_sect.tid", DVB_DATA_MPE_TID, dvb_data_mpe_handle);
236 ip_handle = find_dissector_add_dependency("ip", proto_dvb_data_mpe);
237 llc_handle = find_dissector_add_dependency("llc", proto_dvb_data_mpe);
242 * Editor modelines - https://www.wireshark.org/tools/modelines.html
244 * Local variables:
245 * c-basic-offset: 4
246 * tab-width: 8
247 * indent-tabs-mode: nil
248 * End:
250 * vi: set shiftwidth=4 tabstop=8 expandtab:
251 * :indentSize=4:tabSize=8:noTabs=true: