]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
en50221: capmt - filter out not used CAIDs, fixes #4799
authorJaroslav Kysela <perex@perex.cz>
Thu, 21 Dec 2017 08:15:55 +0000 (09:15 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 21 Dec 2017 08:15:55 +0000 (09:15 +0100)
src/descrambler/dvbcam.c
src/input/mpegts/en50221/en50221_capmt.c
src/input/mpegts/en50221/en50221_capmt.h

index 77e3437c2ab60de474351da1e98369144f9ae762..b886703e950fc7b15a68acb83add7094ddd313b7 100644 (file)
@@ -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) {
index c9a732153dbb25019159cc827c347a42a7e47b93..f84702f2a8fb1f2af006b4da67a248ee8b7353ab 100644 (file)
@@ -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;
index 146579934dd3b32c6536ecfdfa8ad80e1240d565..20860c6ce51fbce58cdb5e0af6a8fdcfe772b926 100644 (file)
@@ -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);