diff options
Diffstat (limited to 'epan/dvb_chartbl.c')
-rw-r--r-- | epan/dvb_chartbl.c | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/epan/dvb_chartbl.c b/epan/dvb_chartbl.c new file mode 100644 index 0000000000..d970340b08 --- /dev/null +++ b/epan/dvb_chartbl.c @@ -0,0 +1,246 @@ +/* dvb_chartbl.c + * Routines for handling DVB-SI character tables (as defined in EN 300 468) + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include <glib.h> + +#include <epan/proto.h> +#include <epan/tvbuff.h> +#include <epan/value_string.h> + +#include "dvb_chartbl.h" + + +static dvb_encoding_e +dvb_analyze_string_charset0(guint8 byte0) +{ + switch (byte0) { + case 0x01: + return DVB_ENCODING_ISO_8859_5; + case 0x02: + return DVB_ENCODING_ISO_8859_6; + case 0x03: + return DVB_ENCODING_ISO_8859_7; + case 0x04: + return DVB_ENCODING_ISO_8859_8; + case 0x05: + return DVB_ENCODING_ISO_8859_9; + case 0x06: + return DVB_ENCODING_ISO_8859_10; + case 0x07: + return DVB_ENCODING_ISO_8859_11; + case 0x08: + return DVB_ENCODING_RESERVED; /* was reserved for ISO-8859-12 */ + case 0x09: /* 0x09 */ + return DVB_ENCODING_ISO_8859_13; + case 0x0A: /* 0x0A */ + return DVB_ENCODING_ISO_8859_14; + case 0x0B: /* 0x0B */ + return DVB_ENCODING_ISO_8859_15; + + /* XXX 0x11 ... 0x15 */ + + default: + return DVB_ENCODING_UNKNOWN; + } +} + +static dvb_encoding_e +dvb_analyze_string_charset0_10(guint16 byte12) +{ + switch (byte12) { + case 0x0000: + return DVB_ENCODING_RESERVED; + case 0x0001: + return DVB_ENCODING_EXT_ISO_8859_1; + case 0x0002: + return DVB_ENCODING_EXT_ISO_8859_2; + case 0x0003: + return DVB_ENCODING_EXT_ISO_8859_3; + case 0x0004: + return DVB_ENCODING_EXT_ISO_8859_4; + case 0x0005: + return DVB_ENCODING_EXT_ISO_8859_5; + case 0x0006: + return DVB_ENCODING_EXT_ISO_8859_6; + case 0x0007: + return DVB_ENCODING_EXT_ISO_8859_7; + case 0x0008: + return DVB_ENCODING_EXT_ISO_8859_8; + case 0x0009: + return DVB_ENCODING_EXT_ISO_8859_9; + case 0x000A: + return DVB_ENCODING_EXT_ISO_8859_10; + case 0x000B: + return DVB_ENCODING_EXT_ISO_8859_11; + case 0x000C: + return DVB_ENCODING_RESERVED; + case 0x000D: + return DVB_ENCODING_EXT_ISO_8859_13; + case 0x000E: + return DVB_ENCODING_EXT_ISO_8859_14; + case 0x000F: + return DVB_ENCODING_EXT_ISO_8859_15; + + default: /* 0x10 XX XX */ + return DVB_ENCODING_UNKNOWN; + } +} + +static dvb_encoding_e +dvb_analyze_string_charset0_1F(guint8 byte1) +{ + /* http://www.dvbservices.com/identifiers/encoding_type_id */ + + switch (byte1) { + case 0x00: /* 0x1F 0x00 */ + return DVB_ENCODING_RESERVED; + case 0x01: + case 0x02: + case 0x03: + case 0x04: + /* XXX: BBC */ + return DVB_ENCODING_RESERVED; + case 0x05: + case 0x06: + /* XXX: Malaysian Technical Standards Forum Bhd */ + return DVB_ENCODING_RESERVED; + + default: /* 0x1F XX */ + return DVB_ENCODING_RESERVED; + } +} + + +guint +dvb_analyze_string_charset(tvbuff_t *tvb, int offset, int length, dvb_encoding_e *encoding) +{ + if (length >= 1) { + guint8 byte0 = tvb_get_guint8(tvb, offset + 0); + + if (byte0 >= 0x20) { + /* the first byte is a normal character, not the number of a character table */ + *encoding = DVB_ENCODING_LATIN; + return 0; + + } else if (byte0 == 0x1F) { + if (length >= 2) { + *encoding = dvb_analyze_string_charset0_1F(tvb_get_guint8(tvb, offset + 1)); + return 2; + } + *encoding = DVB_ENCODING_INVALID; + return 1; + + } else if (byte0 >= 0x16) { /* 16 ... 1E */ + *encoding = DVB_ENCODING_RESERVED; + return 1; + + } else if (byte0 == 0x10) { + if (length >= 3) { + *encoding = dvb_analyze_string_charset0_10(tvb_get_ntohs(tvb, offset + 1)); + return 3; + } + *encoding = DVB_ENCODING_INVALID; + return 1; + + } else if ((byte0 >= 0x0C && byte0 <= 0x0F)) { + *encoding = DVB_ENCODING_RESERVED; + return 1; + } else { + *encoding = dvb_analyze_string_charset0(byte0); + return 1; + } + } else + *encoding = DVB_ENCODING_LATIN; + + return 0; +} + + +guint +dvb_enc_to_item_enc(dvb_encoding_e encoding) +{ + /* XXX: take ISO control codes into account, + e.g. 0x86 - turn emphasis on ; 0x87 - turn emphasis off */ + + switch (encoding) { + case DVB_ENCODING_ISO_8859_9: + case DVB_ENCODING_EXT_ISO_8859_2: + return ENC_ISO_8859_2 | ENC_NA; + + default: /* not supported */ + return ENC_ASCII | ENC_NA; + } +} + + +const value_string dvb_string_encoding_vals[] = { + { DVB_ENCODING_INVALID, "Incorrect length for encoding" }, + { DVB_ENCODING_RESERVED, "Reserved for future use" }, + { DVB_ENCODING_UNKNOWN, "Value not specified by spec" }, + + { DVB_ENCODING_LATIN, "Latin (default table)" }, + + { DVB_ENCODING_ISO_8859_5, "ISO/IEC 8859-5 (Latin/Cyrillic)" }, + { DVB_ENCODING_ISO_8859_6, "ISO/IEC 8859-6 (Latin/Arabic)" }, + { DVB_ENCODING_ISO_8859_7, "ISO/IEC 8859-7 (Latin/Greek)" }, + { DVB_ENCODING_ISO_8859_8, "ISO/IEC 8859-8 (Latin/Hebrew)" }, + { DVB_ENCODING_ISO_8859_9, "ISO/IEC 8859-9 (West European & Turkish)" }, + { DVB_ENCODING_ISO_8859_10, "ISO/IEC 8859-10 (North European)" }, + { DVB_ENCODING_ISO_8859_11, "ISO/IEC 8859-11 (Thai)" }, + { DVB_ENCODING_ISO_8859_13, "ISO/IEC 8859-13 (Baltic)" }, + { DVB_ENCODING_ISO_8859_14, "ISO/IEC 8859-14 (Celtic)" }, + { DVB_ENCODING_ISO_8859_15, "ISO/IEC 8859-15 (West European)" }, + + { DVB_ENCODING_EXT_ISO_8859_1, "ISO/IEC 8859-1 (West European)" }, + { DVB_ENCODING_EXT_ISO_8859_2, "ISO/IEC 8859-2 (East European)" }, + { DVB_ENCODING_EXT_ISO_8859_3, "ISO/IEC 8859-3 (South European)" }, + { DVB_ENCODING_EXT_ISO_8859_4, "ISO/IEC 8859-4 (North and North-East European)" }, + { DVB_ENCODING_EXT_ISO_8859_5, "ISO/IEC 8859-5 (Latin/Cyrillic)" }, + { DVB_ENCODING_EXT_ISO_8859_6, "ISO/IEC 8859-6 (Latin/Arabic)" }, + { DVB_ENCODING_EXT_ISO_8859_7, "ISO/IEC 8859-7 (Latin/Greek)" }, + { DVB_ENCODING_EXT_ISO_8859_8, "ISO/IEC 8859-8 (Latin/Hebrew)" }, + { DVB_ENCODING_EXT_ISO_8859_9, "ISO/IEC 8859-9 (West European & Turkish)" }, + { DVB_ENCODING_EXT_ISO_8859_10, "ISO/IEC 8859-10 (North European)" }, + { DVB_ENCODING_EXT_ISO_8859_11, "ISO/IEC 8859-11 (Thai)" }, + { DVB_ENCODING_EXT_ISO_8859_13, "ISO/IEC 8859-13 (Baltic)" }, + { DVB_ENCODING_EXT_ISO_8859_14, "ISO/IEC 8859-14 (Celtic)" }, + { DVB_ENCODING_EXT_ISO_8859_15, "ISO/IEC 8859-15 (West European)" }, + + { 0, NULL } +}; + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ |