| 1 |
/* |
| 2 |
* Copyright (c) 2020 - Mauro Carvalho Chehab |
| 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 |
*/ |
| 19 |
|
| 20 |
#include <libdvbv5/desc_registration_id.h> |
| 21 |
#include <libdvbv5/dvb-fe.h> |
| 22 |
|
| 23 |
#if __GNUC__ >= 9 |
| 24 |
#pragma GCC diagnostic ignored "-Waddress-of-packed-member" |
| 25 |
#endif |
| 26 |
|
| 27 |
int dvb_desc_registration_init(struct dvb_v5_fe_parms *parms, |
| 28 |
const uint8_t *buf, struct dvb_desc *desc) |
| 29 |
{ |
| 30 |
struct dvb_desc_registration *d = (struct dvb_desc_registration *) desc; |
| 31 |
size_t size = sizeof(d->format_identifier); |
| 32 |
|
| 33 |
if (desc->length < size) { |
| 34 |
dvb_logerr("dvb_desc_registration_init short read %d/%zd bytes", desc->length, size); |
| 35 |
return -1; |
| 36 |
} |
| 37 |
|
| 38 |
memcpy(&d->format_identifier, buf, size); |
| 39 |
|
| 40 |
if (desc->length <= size) |
| 41 |
return 0; |
| 42 |
|
| 43 |
d->additional_identification_info = malloc(desc->length - size); |
| 44 |
memcpy(desc->data, buf + size, desc->length - size); |
| 45 |
|
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
void dvb_desc_registration_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc) |
| 50 |
{ |
| 51 |
const struct dvb_desc_registration *d = (const struct dvb_desc_registration *) desc; |
| 52 |
int i = 0; |
| 53 |
|
| 54 |
dvb_loginfo("| format_identifier : %c%c%c%c", |
| 55 |
d->format_identifier[0], d->format_identifier[1], |
| 56 |
d->format_identifier[2], d->format_identifier[3]); |
| 57 |
|
| 58 |
if (!d->additional_identification_info) |
| 59 |
return; |
| 60 |
|
| 61 |
for (i = 0; i < d->length - 4; i++) { |
| 62 |
dvb_loginfo("| aditional_id_info[%d] : %02x", |
| 63 |
i, d->additional_identification_info[i]); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
void dvb_desc_registration_free(struct dvb_desc *desc) |
| 68 |
{ |
| 69 |
const struct dvb_desc_registration *d = (const void *) desc; |
| 70 |
|
| 71 |
free(d->additional_identification_info); |
| 72 |
} |