summaryrefslogtreecommitdiffstats
path: root/lib/libucsi/dvb/int_section.h
diff options
context:
space:
mode:
authoretobi <git@e-tobi.net>2013-09-03 09:48:41 +0200
committeretobi <git@e-tobi.net>2013-09-03 09:48:41 +0200
commitab959d7b4194715870128e616b8e29d4a101e488 (patch)
tree61a746231d30817be73416a7d67763fd677a1042 /lib/libucsi/dvb/int_section.h
parent6b350466c4902c5b137e0efaf1d189128a7f18f5 (diff)
downloadlinux-dvb-apps-ab959d7b4194715870128e616b8e29d4a101e488.tar.gz
Imported Upstream version 1.1.1+rev1207upstream/1.1.1+rev1207
Diffstat (limited to 'lib/libucsi/dvb/int_section.h')
-rw-r--r--lib/libucsi/dvb/int_section.h245
1 files changed, 245 insertions, 0 deletions
diff --git a/lib/libucsi/dvb/int_section.h b/lib/libucsi/dvb/int_section.h
new file mode 100644
index 0000000..932c0e8
--- /dev/null
+++ b/lib/libucsi/dvb/int_section.h
@@ -0,0 +1,245 @@
+/*
+ * section and descriptor parser
+ *
+ * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
+ * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
+ * Copyright (C) 2005 Patrick Boettcher (pb@linuxtv.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+#ifndef _UCSI_DVB_INT_SECTION_H
+#define _UCSI_DVB_INT_SECTION_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libucsi/section.h>
+
+/**
+ * dvb_int_section structure - IP/MAC notification section.
+ */
+struct dvb_int_section {
+ struct section_ext head;
+
+ EBIT2(uint32_t platform_id :24; ,
+ uint32_t processing_order : 8; );
+ EBIT2(uint16_t reserved2 : 4; ,
+ uint16_t platform_descriptors_length :12; );
+ /* struct descriptor platform_descriptors[] */
+ /* struct dvb_int_target target_loop[] */
+} __ucsi_packed;
+
+/**
+ * An entry in the target_loop field of a dvb_int_section.
+ */
+struct dvb_int_target {
+ EBIT2(uint16_t reserved3 : 4; ,
+ uint16_t target_descriptors_length :12; );
+ /* struct descriptor target_descriptors[] */
+ /* struct dvb_int_operational_loop operational_loop */
+} __ucsi_packed;
+
+/**
+ * The operational_loop field in a dvb_int_target.
+ */
+struct dvb_int_operational_loop {
+ EBIT2(uint16_t reserved4 : 4; ,
+ uint16_t operational_descriptors_length :12; );
+ /* struct descriptor operational_descriptors[] */
+} __ucsi_packed;
+
+/**
+ * Process a dvb_int_section.
+ *
+ * @param section Generic section_ext pointer.
+ * @return dvb_int_section pointer, or NULL on error.
+ */
+extern struct dvb_int_section * dvb_int_section_codec(struct section_ext *section);
+
+/**
+ * Accessor for the action_type field of an INT.
+ *
+ * @param intp INT pointer.
+ * @return The action_type.
+ */
+static inline uint8_t dvb_int_section_action_type(struct dvb_int_section *intp)
+{
+ return intp->head.table_id_ext >> 8;
+}
+
+/**
+ * Accessor for the platform_id_hash field of an INT.
+ *
+ * @param intp INT pointer.
+ * @return The platform_id_hash.
+ */
+static inline uint8_t dvb_int_section_platform_id_hash(struct dvb_int_section *intp)
+{
+ return intp->head.table_id_ext & 0xff;
+}
+
+/**
+ * Iterator for platform_descriptors field in a dvb_int_section.
+ *
+ * @param intp dvb_int_section pointer.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define dvb_int_section_platform_descriptors_for_each(intp, pos) \
+ for ((pos) = dvb_int_section_platform_descriptors_first(intp); \
+ (pos); \
+ (pos) = dvb_int_section_platform_descriptors_next(intp, pos))
+
+/**
+ * Iterator for the target_loop field in a dvb_int_section.
+ *
+ * @param intp dvb_int_section pointer.
+ * @param pos Variable holding a pointer to the current dvb_int_target.
+ */
+#define dvb_int_section_target_loop_for_each(intp,pos) \
+ for ((pos) = dvb_int_section_target_loop_first(intp); \
+ (pos); \
+ (pos) = dvb_int_section_target_loop_next(intp, pos))
+
+/**
+ * Iterator for the target_descriptors field in a dvb_int_target.
+ *
+ * @param target dvb_int_target pointer.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define dvb_int_target_target_descriptors_for_each(target, pos) \
+ for ((pos) = dvb_int_target_target_descriptors_first(target); \
+ (pos); \
+ (pos) = dvb_int_target_target_descriptors_next(target, pos))
+
+/**
+ * Accessor for the operational_loop field of a dvb_int_target.
+ *
+ * @param target dvb_int_target pointer.
+ * @return Pointer to a dvb_int_operational_loop.
+ */
+static inline struct dvb_int_operational_loop *
+ dvb_int_target_operational_loop(struct dvb_int_target *target)
+{
+ return (struct dvb_int_operational_loop *)
+ ((uint8_t *) target + sizeof(struct dvb_int_target) + target->target_descriptors_length);
+}
+
+/**
+ * Iterator for the operational_descriptors field in a dvb_int_operational_loop.
+ *
+ * @param oploop dvb_int_operational_loop pointer.
+ * @param pos Variable holding a pointer to the current descriptor.
+ */
+#define dvb_int_operational_loop_operational_descriptors_for_each(oploop, pos) \
+ for ((pos) = dvb_int_operational_loop_operational_descriptors_first(oploop); \
+ (pos); \
+ (pos) = dvb_int_operational_loop_operational_descriptors_next(oploop, pos))
+
+
+
+
+
+/******************************** PRIVATE CODE ********************************/
+static inline struct descriptor *
+ dvb_int_section_platform_descriptors_first(struct dvb_int_section *in)
+{
+ if (in->platform_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) in + sizeof(struct dvb_int_section));
+}
+
+static inline struct descriptor *
+ dvb_int_section_platform_descriptors_next(struct dvb_int_section *in,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) in + sizeof(struct dvb_int_section),
+ in->platform_descriptors_length,
+ pos);
+}
+
+static inline struct dvb_int_target *
+ dvb_int_section_target_loop_first(struct dvb_int_section *in)
+{
+ if (sizeof(struct dvb_int_section) + in->platform_descriptors_length >= (uint32_t) section_ext_length((struct section_ext *) in))
+ return NULL;
+
+ return (struct dvb_int_target *)
+ ((uint8_t *) in + sizeof(struct dvb_int_section) + in->platform_descriptors_length);
+}
+
+static inline struct dvb_int_target *
+ dvb_int_section_target_loop_next(struct dvb_int_section *in,
+ struct dvb_int_target *pos)
+{
+ struct dvb_int_operational_loop *ol = dvb_int_target_operational_loop(pos);
+ struct dvb_int_target *next =
+ (struct dvb_int_target *) ( (uint8_t *) pos +
+ sizeof(struct dvb_int_target) + pos->target_descriptors_length +
+ sizeof(struct dvb_int_operational_loop) + ol->operational_descriptors_length);
+ struct dvb_int_target *end =
+ (struct dvb_int_target *) ((uint8_t *) in + section_ext_length((struct section_ext *) in) );
+
+ if (next >= end)
+ return 0;
+ return next;
+}
+
+static inline struct descriptor *
+ dvb_int_target_target_descriptors_first(struct dvb_int_target *tl)
+{
+ if (tl->target_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) tl + sizeof(struct dvb_int_target));
+}
+
+static inline struct descriptor *
+ dvb_int_target_target_descriptors_next(struct dvb_int_target *tl,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) tl + sizeof(struct dvb_int_target),
+ tl->target_descriptors_length,
+ pos);
+}
+
+static inline struct descriptor *
+ dvb_int_operational_loop_operational_descriptors_first(struct dvb_int_operational_loop *ol)
+{
+ if (ol->operational_descriptors_length == 0)
+ return NULL;
+
+ return (struct descriptor *)
+ ((uint8_t *) ol + sizeof(struct dvb_int_operational_loop));
+}
+
+static inline struct descriptor *
+ dvb_int_operational_loop_operational_descriptors_next(struct dvb_int_operational_loop *ol,
+ struct descriptor* pos)
+{
+ return next_descriptor((uint8_t*) ol + sizeof(struct dvb_int_operational_loop),
+ ol->operational_descriptors_length,
+ pos);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
{ "8/9", DVBFE_FEC_8_9 }, { "AUTO", DVBFE_FEC_AUTO }, { "NONE", DVBFE_FEC_NONE }, { NULL, 0 } }; static const struct dvbcfg_setting dvbcfg_dvbc_modulation_list[] = { { "QAM16", DVBFE_DVBC_MOD_QAM_16 }, { "QAM32", DVBFE_DVBC_MOD_QAM_32 }, { "QAM64", DVBFE_DVBC_MOD_QAM_64 }, { "QAM128", DVBFE_DVBC_MOD_QAM_128 }, { "QAM256", DVBFE_DVBC_MOD_QAM_256 }, { "AUTO", DVBFE_DVBC_MOD_AUTO }, { NULL, 0 } }; static const struct dvbcfg_setting dvbcfg_bandwidth_list[] = { { "6MHz", DVBFE_DVBT_BANDWIDTH_6_MHZ }, { "7MHz", DVBFE_DVBT_BANDWIDTH_7_MHZ }, { "8MHz", DVBFE_DVBT_BANDWIDTH_8_MHZ }, { "AUTO", DVBFE_DVBT_BANDWIDTH_AUTO }, { NULL, 0 } }; static const struct dvbcfg_setting dvbcfg_constellation_list[] = { { "QAM16", DVBFE_DVBT_CONST_QAM_16 }, { "QAM32", DVBFE_DVBT_CONST_QAM_32 }, { "QAM64", DVBFE_DVBT_CONST_QAM_64 }, { "QAM128", DVBFE_DVBT_CONST_QAM_128 }, { "QAM256", DVBFE_DVBT_CONST_QAM_256 }, { "QPSK", DVBFE_DVBT_CONST_QPSK }, { "AUTO", DVBFE_DVBT_CONST_AUTO }, { NULL, 0 } }; static const struct dvbcfg_setting dvbcfg_transmission_mode_list[] = { { "2k", DVBFE_DVBT_TRANSMISSION_MODE_2K }, { "8k", DVBFE_DVBT_TRANSMISSION_MODE_8K }, { "AUTO", DVBFE_DVBT_TRANSMISSION_MODE_AUTO }, { NULL, 0 } }; static const struct dvbcfg_setting dvbcfg_guard_interval_list[] = { { "1/32", DVBFE_DVBT_GUARD_INTERVAL_1_32 }, { "1/16", DVBFE_DVBT_GUARD_INTERVAL_1_16 }, { "1/8", DVBFE_DVBT_GUARD_INTERVAL_1_8 }, { "1/4", DVBFE_DVBT_GUARD_INTERVAL_1_4 }, { "AUTO", DVBFE_DVBT_GUARD_INTERVAL_AUTO }, { NULL, 0 } }; static const struct dvbcfg_setting dvbcfg_hierarchy_list[] = { { "1", DVBFE_DVBT_HIERARCHY_1 }, { "2", DVBFE_DVBT_HIERARCHY_2 }, { "4", DVBFE_DVBT_HIERARCHY_4 }, { "AUTO", DVBFE_DVBT_HIERARCHY_AUTO }, { "NONE", DVBFE_DVBT_HIERARCHY_NONE }, { NULL, 0 } }; static const struct dvbcfg_setting dvbcfg_atsc_modulation_list[] = { { "8VSB", DVBFE_ATSC_MOD_VSB_8 }, { "16VSB", DVBFE_ATSC_MOD_VSB_16 }, { "QAM64", DVBFE_ATSC_MOD_QAM_64 }, { "QAM256", DVBFE_ATSC_MOD_QAM_256 }, { NULL, 0 } }; int dvbcfg_scanfile_parse(FILE *file, dvbcfg_scancallback callback, void *private_data) { char *line_buf = NULL; size_t line_size = 0; int line_len = 0; int ret_val = 0; while ((line_len = getline(&line_buf, &line_size, file)) > 0) { char *line_tmp = line_buf; char *line_pos = line_buf; struct dvbcfg_scanfile tmp; /* remove newline and comments (started with hashes) */ while ((*line_tmp != '\0') && (*line_tmp != '\n') && (*line_tmp != '#')) line_tmp++; *line_tmp = '\0'; /* always use inversion auto */ tmp.fe_params.inversion = DVBFE_INVERSION_AUTO; /* parse frontend type */ switch(dvbcfg_parse_char(&line_pos, " ")) { case 'T': tmp.fe_type = DVBFE_TYPE_DVBT; break; case 'C': tmp.fe_type = DVBFE_TYPE_DVBC; break; case 'S': tmp.fe_type = DVBFE_TYPE_DVBS; break; case 'A': tmp.fe_type = DVBFE_TYPE_ATSC; break; default: continue; } /* parse frontend specific settings */ switch (tmp.fe_type) { case DVBFE_TYPE_ATSC: /* parse frequency */ tmp.fe_params.frequency = dvbcfg_parse_int(&line_pos, " "); if (!line_pos) continue; /* modulation */ tmp.fe_params.u.atsc.modulation = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_atsc_modulation_list); if (!line_pos) continue; break; case DVBFE_TYPE_DVBC: /* parse frequency */ tmp.fe_params.frequency = dvbcfg_parse_int(&line_pos, " "); if (!line_pos) continue; /* symbol rate */ tmp.fe_params.u.dvbc.symbol_rate = dvbcfg_parse_int(&line_pos, " "); if (!line_pos) continue; /* fec */ tmp.fe_params.u.dvbc.fec_inner = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_fec_list); if (!line_pos) continue; /* modulation */ tmp.fe_params.u.dvbc.modulation = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_dvbc_modulation_list); if (!line_pos) continue; break; case DVBFE_TYPE_DVBS: /* parse frequency */ tmp.fe_params.frequency = dvbcfg_parse_int(&line_pos, " "); if (!line_pos) continue; /* polarization */ tmp.polarization = tolower(dvbcfg_parse_char(&line_pos, " ")); if (!line_pos) continue; if ((tmp.polarization != 'h') && (tmp.polarization != 'v') && (tmp.polarization != 'l') && (tmp.polarization != 'r')) continue; /* symbol rate */ tmp.fe_params.u.dvbs.symbol_rate = dvbcfg_parse_int(&line_pos, " "); if (!line_pos) continue; /* fec */ tmp.fe_params.u.dvbc.fec_inner = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_fec_list); if (!line_pos) continue; break; case DVBFE_TYPE_DVBT: /* parse frequency */ tmp.fe_params.frequency = dvbcfg_parse_int(&line_pos, " "); if (!line_pos) continue; /* bandwidth */ tmp.fe_params.u.dvbt.bandwidth = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_bandwidth_list); if (!line_pos) continue; /* fec hp */ tmp.fe_params.u.dvbt.code_rate_HP = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_fec_list); if (!line_pos) continue; /* fec lp */ tmp.fe_params.u.dvbt.code_rate_LP = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_fec_list); if (!line_pos) continue; /* constellation */ tmp.fe_params.u.dvbt.constellation = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_constellation_list); if (!line_pos) continue; /* transmission mode */ tmp.fe_params.u.dvbt.transmission_mode = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_transmission_mode_list); if (!line_pos) continue; /* guard interval */ tmp.fe_params.u.dvbt.guard_interval = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_guard_interval_list); if (!line_pos) continue; /* hierarchy */ tmp.fe_params.u.dvbt.hierarchy_information = dvbcfg_parse_setting(&line_pos, " ", dvbcfg_hierarchy_list); if (!line_pos) continue; break; } /* invoke callback */ if ((ret_val = callback(&tmp, private_data)) != 0) { if (ret_val < 0) ret_val = 0; break; } } if (line_buf) free(line_buf); return ret_val; }