From: Jaroslav Kysela Date: Thu, 21 Dec 2017 08:15:55 +0000 (+0100) Subject: en50221: capmt - filter out not used CAIDs, fixes #4799 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aa36c1448f0faa838f000c18f7ecc82273752e69;p=thirdparty%2Ftvheadend.git en50221: capmt - filter out not used CAIDs, fixes #4799 --- diff --git a/src/descrambler/dvbcam.c b/src/descrambler/dvbcam.c index 77e3437c2..b886703e9 100644 --- a/src/descrambler/dvbcam.c +++ b/src/descrambler/dvbcam.c @@ -40,7 +40,7 @@ typedef struct dvbcam_active_cam { TAILQ_ENTRY(dvbcam_active_cam) global_link; uint16_t caids[CAIDS_PER_CA_SLOT]; - int num_caids; + int caids_count; linuxdvb_ca_t *ca; uint8_t slot; int active_programs; @@ -165,12 +165,12 @@ dvbcam_is_ddci(struct service *t) */ void dvbcam_register_cam(linuxdvb_ca_t * lca, uint16_t * caids, - int num_caids) + int caids_count) { dvbcam_active_cam_t *ac, *ac_first; int registered = 0; - tvhtrace(LS_DVBCAM, "register cam %p num_caids %u", lca->lca_name, num_caids); + tvhtrace(LS_DVBCAM, "register cam %p caids_count %u", lca->lca_name, caids_count); pthread_mutex_lock(&dvbcam_mutex); @@ -186,10 +186,10 @@ dvbcam_register_cam(linuxdvb_ca_t * lca, uint16_t * caids, ac->ca = lca; } - num_caids = MIN(CAIDS_PER_CA_SLOT, num_caids); + caids_count = MIN(CAIDS_PER_CA_SLOT, caids_count); - memcpy(ac->caids, caids, num_caids * sizeof(uint16_t)); - ac->num_caids = num_caids; + memcpy(ac->caids, caids, caids_count * sizeof(uint16_t)); + ac->caids_count = caids_count; ac_first = TAILQ_FIRST(&dvbcam_active_cams); if (!registered) @@ -261,7 +261,7 @@ dvbcam_ca_lookup(dvbcam_active_cam_t *ac, mpegts_input_t *input, uint16_t caid) if (lfe == NULL || lcat->lcat_adapter != lfe->lfe_adapter) return 0; - for (i = 0; i < ac->num_caids; i++) + for (i = 0; i < ac->caids_count; i++) if (ac->caids[i] == caid) return 1; @@ -325,6 +325,7 @@ dvbcam_pmt_data(mpegts_service_t *s, const uint8_t *ptr, int len) r = en50221_capmt_build(s, bcmd, s->s_dvb_service_id, + ac->caids, ac->caids_count, as->last_pmt, as->last_pmt_len, &capmt, &capmt_len); if (r >= 0) { @@ -355,6 +356,7 @@ dvbcam_service_destroy(th_descrambler_t *td) s = (mpegts_service_t *)td->td_service; r = en50221_capmt_build(s, EN50221_CAPMT_BUILD_DELETE, s->s_dvb_service_id, + ac->caids, ac->caids_count, as->last_pmt, as->last_pmt_len, &capmt, &capmt_len); if (r >= 0) { diff --git a/src/input/mpegts/en50221/en50221_capmt.c b/src/input/mpegts/en50221/en50221_capmt.c index c9a732153..f84702f2a 100644 --- a/src/input/mpegts/en50221/en50221_capmt.c +++ b/src/input/mpegts/en50221/en50221_capmt.c @@ -83,11 +83,19 @@ static int en50221_capmt_check_pid } static int en50221_capmt_check_caid - (mpegts_service_t *s, uint16_t pid, uint16_t caid) + (mpegts_service_t *s, uint16_t pid, uint16_t caid, + const uint16_t *caids, int caids_count) { elementary_stream_t *st; caid_t *c; + for (; caids_count > 0; caids++, caids_count--) + if (caid == *caids) + break; + + if (caids_count == 0) + return 0; + TAILQ_FOREACH(st, &s->s_filt_components, es_link) { if (st->es_type != SCT_CA) continue; LIST_FOREACH(c, &st->es_caids, link) { @@ -104,6 +112,7 @@ static int en50221_capmt_check_caid int en50221_capmt_build (mpegts_service_t *s, int bcmd, uint16_t svcid, + const uint16_t *caids, int caids_count, const uint8_t *pmt, size_t pmtlen, uint8_t **capmt, size_t *capmtlen) { @@ -149,7 +158,7 @@ int en50221_capmt_build if (dtag == DVB_DESC_CA && dlen >= 4) { caid = extract_2byte(p + 2); pid = extract_pid(p + 4); - if (en50221_capmt_check_caid(s, pid, caid)) { + if (en50221_capmt_check_caid(s, pid, caid, caids, caids_count)) { if (first) { *x++ = cmd_id; first = 0; @@ -183,7 +192,7 @@ int en50221_capmt_build if (dtag == DVB_DESC_CA && dlen >= 4) { caid = extract_2byte(p + 2); pid = extract_pid(p + 4); - if (en50221_capmt_check_caid(s, pid, caid)) { + if (en50221_capmt_check_caid(s, pid, caid, caids, caids_count)) { if (first) { *x++ = cmd_id; first = 0; diff --git a/src/input/mpegts/en50221/en50221_capmt.h b/src/input/mpegts/en50221/en50221_capmt.h index 146579934..20860c6ce 100644 --- a/src/input/mpegts/en50221/en50221_capmt.h +++ b/src/input/mpegts/en50221/en50221_capmt.h @@ -30,8 +30,8 @@ struct mpegts_service; int en50221_capmt_build (struct mpegts_service *s, - int bcmd, uint16_t svcid, const uint8_t *pmt, size_t pmtlen, - uint8_t **capmt, size_t *capmtlen); + int bcmd, uint16_t svcid, const uint16_t *caids, int caids_count, + const uint8_t *pmt, size_t pmtlen, uint8_t **capmt, size_t *capmtlen); int en50221_capmt_build_query(const uint8_t *capmt, size_t capmtlen, uint8_t **dst, size_t *dstlen);