| 1 |
/* |
| 2 |
* Copyright (c) 2013 - Andre Roth <[email protected]> |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser General Public License as published by |
| 6 |
* the Free Software Foundation version 2.1 of the License. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program; if not, write to the Free Software |
| 15 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 |
* Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| 17 |
* |
| 18 |
* Described at ETSI EN 300 468 V1.11.1 (2010-04) |
| 19 |
*/ |
| 20 |
|
| 21 |
#include <libdvbv5/desc_ca.h> |
| 22 |
#include <libdvbv5/dvb-fe.h> |
| 23 |
|
| 24 |
#if __GNUC__ >= 9 |
| 25 |
#pragma GCC diagnostic ignored "-Waddress-of-packed-member" |
| 26 |
#endif |
| 27 |
|
| 28 |
int dvb_desc_ca_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc) |
| 29 |
{ |
| 30 |
struct dvb_desc_ca *d = (struct dvb_desc_ca *) desc; |
| 31 |
const uint8_t *p = buf; |
| 32 |
size_t len, dlen = desc->length; |
| 33 |
size_t start; |
| 34 |
|
| 35 |
start = offsetof(struct dvb_desc_ca, ca_id); |
| 36 |
len = sizeof(d->ca_id) + sizeof(d->bitfield1); |
| 37 |
|
| 38 |
if (dlen < len) { |
| 39 |
dvb_logwarn("CA descriptor is too short wrong: expected %zu, received %zu", |
| 40 |
len, dlen); |
| 41 |
return -1; |
| 42 |
} |
| 43 |
memcpy(((uint8_t *) d) + start, buf, len); |
| 44 |
p += len; |
| 45 |
bswap16(d->ca_id); |
| 46 |
bswap16(d->bitfield1); |
| 47 |
|
| 48 |
len = dlen - len; |
| 49 |
if (len) { |
| 50 |
d->privdata = malloc(len); |
| 51 |
if (!d->privdata) |
| 52 |
return -1; |
| 53 |
d->privdata_len = len; |
| 54 |
memcpy(d->privdata, p, len); |
| 55 |
} else { |
| 56 |
d->privdata = NULL; |
| 57 |
d->privdata_len = 0; |
| 58 |
} |
| 59 |
return 0; |
| 60 |
} |
| 61 |
|
| 62 |
void dvb_desc_ca_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc) |
| 63 |
{ |
| 64 |
const struct dvb_desc_ca *d = (const struct dvb_desc_ca *) desc; |
| 65 |
dvb_loginfo("| ca_id 0x%04x", d->ca_id); |
| 66 |
dvb_loginfo("| ca_pid 0x%04x", d->ca_pid); |
| 67 |
dvb_loginfo("| privdata length %d", d->privdata_len); |
| 68 |
if (d->privdata) |
| 69 |
dvb_hexdump(parms, "| privdata ", d->privdata, d->privdata_len); |
| 70 |
} |
| 71 |
|
| 72 |
void dvb_desc_ca_free(struct dvb_desc *desc) |
| 73 |
{ |
| 74 |
struct dvb_desc_ca *d = (struct dvb_desc_ca *) desc; |
| 75 |
if (d->privdata) |
| 76 |
free(d->privdata); |
| 77 |
} |
| 78 |
|