2 * Routines for handling DVB-SI character tables (as defined in EN 300 468)
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/proto.h>
16 #include <epan/tvbuff.h>
17 #include <epan/value_string.h>
19 #include "dvb_chartbl.h"
22 static const value_string dvb_string_encoding_vals
[] = {
23 { DVB_ENCODING_INVALID
, "Incorrect length for encoding" },
24 { DVB_ENCODING_RESERVED
, "Reserved for future use" },
25 { DVB_ENCODING_UNKNOWN
, "Unknown/undefined encoding" },
27 { DVB_ENCODING_LATIN
, "Latin (default table)" },
29 { DVB_ENCODING_ISO_8859_1
, "ISO/IEC 8859-1 (West European)" },
30 { DVB_ENCODING_ISO_8859_2
, "ISO/IEC 8859-2 (East European)" },
31 { DVB_ENCODING_ISO_8859_3
, "ISO/IEC 8859-3 (South European)" },
32 { DVB_ENCODING_ISO_8859_4
, "ISO/IEC 8859-4 (North and North-East European)" },
33 { DVB_ENCODING_ISO_8859_5
, "ISO/IEC 8859-5 (Latin/Cyrillic)" },
34 { DVB_ENCODING_ISO_8859_6
, "ISO/IEC 8859-6 (Latin/Arabic)" },
35 { DVB_ENCODING_ISO_8859_7
, "ISO/IEC 8859-7 (Latin/Greek)" },
36 { DVB_ENCODING_ISO_8859_8
, "ISO/IEC 8859-8 (Latin/Hebrew)" },
37 { DVB_ENCODING_ISO_8859_9
, "ISO/IEC 8859-9 (West European & Turkish)" },
38 { DVB_ENCODING_ISO_8859_10
, "ISO/IEC 8859-10 (North European)" },
39 { DVB_ENCODING_ISO_8859_11
, "ISO/IEC 8859-11 (Thai)" },
40 { DVB_ENCODING_ISO_8859_13
, "ISO/IEC 8859-13 (Baltic)" },
41 { DVB_ENCODING_ISO_8859_14
, "ISO/IEC 8859-14 (Celtic)" },
42 { DVB_ENCODING_ISO_8859_15
, "ISO/IEC 8859-15 (West European)" },
43 { DVB_ENCODING_ISO_10646_BMP
, "ISO/IEC 10646 Basic Multilingual Plane" },
44 { DVB_ENCODING_KSX_1001
, "KSX 1001-2004 (Korean character set)" },
45 { DVB_ENCODING_GB_2312
, "GB-2312-1980 (Simplified Chinese)" },
46 { DVB_ENCODING_ISO_10646_BIG5
, "ISO/IEC 10646 BIG5 subset" },
47 { DVB_ENCODING_ISO_10646_UTF8_BMP
,
48 "ISO/IEC 10646 Basic Multilingual Plane, UTF-8 encoded" },
55 dvb_analyze_string_charset0(uint8_t byte0
)
59 return DVB_ENCODING_ISO_8859_5
;
61 return DVB_ENCODING_ISO_8859_6
;
63 return DVB_ENCODING_ISO_8859_7
;
65 return DVB_ENCODING_ISO_8859_8
;
67 return DVB_ENCODING_ISO_8859_9
;
69 return DVB_ENCODING_ISO_8859_10
;
71 return DVB_ENCODING_ISO_8859_11
;
73 return DVB_ENCODING_RESERVED
; /* was reserved for ISO-8859-12 */
75 return DVB_ENCODING_ISO_8859_13
;
77 return DVB_ENCODING_ISO_8859_14
;
79 return DVB_ENCODING_ISO_8859_15
;
81 return DVB_ENCODING_ISO_10646_BMP
;
83 return DVB_ENCODING_KSX_1001
;
85 return DVB_ENCODING_GB_2312
;
87 return DVB_ENCODING_ISO_10646_BIG5
;
89 return DVB_ENCODING_ISO_10646_UTF8_BMP
;
92 return DVB_ENCODING_UNKNOWN
;
98 dvb_analyze_string_charset0_10(uint16_t byte12
)
102 return DVB_ENCODING_RESERVED
;
104 return DVB_ENCODING_ISO_8859_1
;
106 return DVB_ENCODING_ISO_8859_2
;
108 return DVB_ENCODING_ISO_8859_3
;
110 return DVB_ENCODING_ISO_8859_4
;
112 return DVB_ENCODING_ISO_8859_5
;
114 return DVB_ENCODING_ISO_8859_6
;
116 return DVB_ENCODING_ISO_8859_7
;
118 return DVB_ENCODING_ISO_8859_8
;
120 return DVB_ENCODING_ISO_8859_9
;
122 return DVB_ENCODING_ISO_8859_10
;
124 return DVB_ENCODING_ISO_8859_11
;
126 return DVB_ENCODING_RESERVED
;
128 return DVB_ENCODING_ISO_8859_13
;
130 return DVB_ENCODING_ISO_8859_14
;
132 return DVB_ENCODING_ISO_8859_15
;
134 default: /* 0x10 XX XX */
135 return DVB_ENCODING_UNKNOWN
;
140 static dvb_encoding_e
141 dvb_analyze_string_charset0_1F(uint8_t byte1
)
143 /* http://www.dvbservices.com/identifiers/encoding_type_id */
146 case 0x00: /* 0x1F 0x00 */
147 return DVB_ENCODING_RESERVED
;
153 return DVB_ENCODING_RESERVED
;
156 /* XXX: Malaysian Technical Standards Forum Bhd */
157 return DVB_ENCODING_RESERVED
;
159 default: /* 0x1F XX */
160 return DVB_ENCODING_RESERVED
;
166 dvb_analyze_string_charset(tvbuff_t
*tvb
, int offset
, int length
, dvb_encoding_e
*encoding
)
169 uint8_t byte0
= tvb_get_uint8(tvb
, offset
+ 0);
172 /* the first byte is a normal character, not the number of a character table */
173 *encoding
= DVB_ENCODING_LATIN
;
176 } else if (byte0
== 0x1F) {
178 *encoding
= dvb_analyze_string_charset0_1F(tvb_get_uint8(tvb
, offset
+ 1));
181 *encoding
= DVB_ENCODING_INVALID
;
184 } else if (byte0
>= 0x16) { /* 16 ... 1E */
185 *encoding
= DVB_ENCODING_RESERVED
;
188 } else if (byte0
== 0x10) {
190 *encoding
= dvb_analyze_string_charset0_10(tvb_get_ntohs(tvb
, offset
+ 1));
193 *encoding
= DVB_ENCODING_INVALID
;
196 } else if ((byte0
>= 0x0C && byte0
<= 0x0F)) {
197 *encoding
= DVB_ENCODING_RESERVED
;
200 *encoding
= dvb_analyze_string_charset0(byte0
);
204 *encoding
= DVB_ENCODING_LATIN
;
211 dvb_enc_to_item_enc(dvb_encoding_e encoding
)
213 /* XXX: take ISO control codes into account,
214 e.g. 0x86 - turn emphasis on ; 0x87 - turn emphasis off */
217 case DVB_ENCODING_ISO_8859_1
:
218 return ENC_ISO_8859_1
| ENC_NA
;
220 case DVB_ENCODING_ISO_8859_2
:
221 return ENC_ISO_8859_2
| ENC_NA
;
223 case DVB_ENCODING_ISO_8859_3
:
224 return ENC_ISO_8859_3
| ENC_NA
;
226 case DVB_ENCODING_ISO_8859_4
:
227 return ENC_ISO_8859_4
| ENC_NA
;
229 case DVB_ENCODING_ISO_8859_5
:
230 return ENC_ISO_8859_5
| ENC_NA
;
232 case DVB_ENCODING_ISO_8859_6
:
233 return ENC_ISO_8859_6
| ENC_NA
;
235 case DVB_ENCODING_ISO_8859_7
:
236 return ENC_ISO_8859_7
| ENC_NA
;
238 case DVB_ENCODING_ISO_8859_8
:
239 return ENC_ISO_8859_8
| ENC_NA
;
241 case DVB_ENCODING_ISO_8859_9
:
242 return ENC_ISO_8859_9
| ENC_NA
;
244 case DVB_ENCODING_ISO_8859_10
:
245 return ENC_ISO_8859_10
| ENC_NA
;
247 case DVB_ENCODING_ISO_8859_11
:
248 return ENC_ISO_8859_11
| ENC_NA
;
250 case DVB_ENCODING_ISO_8859_13
:
251 return ENC_ISO_8859_13
| ENC_NA
;
253 case DVB_ENCODING_ISO_8859_14
:
254 return ENC_ISO_8859_14
| ENC_NA
;
256 case DVB_ENCODING_ISO_8859_15
:
257 return ENC_ISO_8859_15
| ENC_NA
;
259 case DVB_ENCODING_ISO_10646_UTF8_BMP
:
260 return ENC_UTF_8
| ENC_NA
;
262 default: /* not supported */
263 return ENC_ASCII
| ENC_NA
;
269 dvb_add_chartbl(proto_tree
*tree
, int hf
,
270 tvbuff_t
*tvb
, int offset
, int length
, dvb_encoding_e encoding
)
278 pi
= proto_tree_add_bytes_format(tree
, hf
, tvb
, 0, 0, NULL
,
279 "Default character table (Latin)");
280 proto_item_set_generated(pi
);
283 proto_tree_add_bytes_format_value(tree
, hf
,
284 tvb
, offset
, length
, NULL
, "%s (%s)",
285 val_to_str_const(encoding
, dvb_string_encoding_vals
, "Unknown"),
286 tvb_bytes_to_str_punct(PNODE_POOL(tree
), tvb
, offset
, length
, ' '));
291 * Editor modelines - https://www.wireshark.org/tools/modelines.html
296 * indent-tabs-mode: nil
299 * vi: set shiftwidth=4 tabstop=8 expandtab:
300 * :indentSize=4:tabSize=8:noTabs=true: