• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2011-2012 - Mauro Carvalho Chehab
3  * Copyright (c) 2012 - Andre Roth <neolynx@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation version 2.1 of the License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18  *
19  * Described at ETSI EN 300 468 V1.11.1 (2010-04)
20  */
21 
22 #include <libdvbv5/desc_cable_delivery.h>
23 #include <libdvbv5/dvb-fe.h>
24 
25 #if __GNUC__ >= 9
26 #pragma GCC diagnostic ignored "-Waddress-of-packed-member"
27 #endif
28 
dvb_desc_cable_delivery_init(struct dvb_v5_fe_parms * parms,const uint8_t * buf,struct dvb_desc * desc)29 int dvb_desc_cable_delivery_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc)
30 {
31 	struct dvb_desc_cable_delivery *cable = (struct dvb_desc_cable_delivery *) desc;
32 	size_t len, dlen = desc->length;
33 	size_t start;
34 
35 	start =  offsetof(struct dvb_desc_cable_delivery, frequency);
36 	len = sizeof(*cable) - start;
37 
38 	if (len != dlen) {
39 		dvb_logwarn("cable delivery descriptor size is wrong: expected %zu, received %zu",
40 			    len, dlen);
41 		return -1;
42 	}
43 
44 	/* copy only the data - length already initialize */
45 	memcpy(((uint8_t *) cable) + start, buf, dlen);
46 	bswap32(cable->frequency);
47 	bswap16(cable->bitfield1);
48 	bswap32(cable->bitfield2);
49 	cable->frequency   = dvb_bcd(cable->frequency) * 100;
50 	cable->symbol_rate = dvb_bcd(cable->symbol_rate) * 100;
51 	return 0;
52 }
53 
dvb_desc_cable_delivery_print(struct dvb_v5_fe_parms * parms,const struct dvb_desc * desc)54 void dvb_desc_cable_delivery_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc)
55 {
56 	const struct dvb_desc_cable_delivery *cable = (const struct dvb_desc_cable_delivery *) desc;
57 	dvb_loginfo("|           length            %d", cable->length);
58 	dvb_loginfo("|           frequency         %d", cable->frequency);
59 	dvb_loginfo("|           fec outer         %d", cable->fec_outer);
60 	dvb_loginfo("|           modulation        %d", cable->modulation);
61 	dvb_loginfo("|           symbol_rate       %d", cable->symbol_rate);
62 	dvb_loginfo("|           fec inner         %d", cable->fec_inner);
63 }
64 
65 const unsigned dvbc_fec_table[] = {
66 	[0]  = FEC_AUTO,	/* not defined */
67 	[1]  = FEC_1_2,
68 	[2]  = FEC_2_3,
69 	[3]  = FEC_3_4,
70 	[4]  = FEC_5_6,
71 	[5]  = FEC_7_8,
72 	[6]  = FEC_8_9,
73 	[7]  = FEC_3_5,
74 	[8]  = FEC_4_5,
75 	[9]  = FEC_9_10,
76 	[10 ...14] = FEC_AUTO,	/* Reserved for future usage */
77 	[15] = FEC_NONE,
78 };
79 
80 const unsigned dvbc_modulation_table[] = {
81 	[0] = QAM_AUTO,		/* Not defined */
82 	[1] = QAM_16,
83 	[2] = QAM_32,
84 	[3] = QAM_64,
85 	[4] = QAM_128,
86 	[5] = QAM_256,
87 	[6 ...255] = QAM_AUTO	/* Reserved for future usage */
88 };
89 
90