]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Fix EN50211 size for large messages
authorFlole <flole@flole.de>
Mon, 31 May 2021 21:07:45 +0000 (23:07 +0200)
committerFlole <flole@flole.de>
Mon, 31 May 2021 21:07:45 +0000 (23:07 +0200)
src/input/mpegts/en50221/en50221.c
src/input/mpegts/en50221/en50221.h
src/input/mpegts/en50221/en50221_apps.c

index 5697600e1915e3c12dcaf6f236b6460a045ffc9d..0c4bee8f30f7b11ddbe68adc1ac5981c7b9345bb 100644 (file)
@@ -174,12 +174,12 @@ en50221_transport_pdu_write(en50221_transport_t *cit,
                             uint8_t tag, const uint8_t *data,
                             size_t datalen)
 {
-  uint8_t *buf = alloca(6 + datalen);
+  uint8_t *buf = alloca(8 + datalen);
   size_t hlen;
 
   buf[0] = tag;
   datalen++;
-  if (datalen < 0x80) {
+if (datalen < 0x80) {
     buf[1] = datalen & 0x7f;
     hlen = 2;
   } else if (datalen < 0x100) {
@@ -191,10 +191,19 @@ en50221_transport_pdu_write(en50221_transport_t *cit,
     buf[2] = datalen >> 8;
     buf[3] = datalen & 0xff;
     hlen = 4;
+  } else if (datalen < 0x1000000) {
+    buf[1] = 0x83;
+    buf[2] = datalen >> 16;
+    buf[3] = (datalen >> 8) & 0xff;
+    buf[4] = datalen & 0xff;
+    hlen = 5;
   } else {
-    tvherror(LS_EN50221, "%s: too much pdu data to write %zd",
-                         cit->cit_name, datalen);
-    return -EIO;
+    buf[1] = 0x84;
+    buf[2] = datalen >> 24;
+    buf[3] = (datalen >> 16) & 0xff;
+    buf[4] = (datalen >> 8) & 0xff;
+    buf[5] = datalen & 0xff;
+    hlen = 6;
   }
   buf[hlen++] = tcnum;
   if (datalen > 1)
@@ -768,7 +777,7 @@ int en50221_app_pdu_send
 {
   en50221_slot_t *slot = app->cia_slot;
   en50221_transport_t *cit = slot->cil_transport;
-  uint8_t *buf = alloca(datalen + 10), *p, tag;
+  uint8_t *buf = alloca(datalen + 12), *p, tag;
   size_t hlen, buflen, tlen;
   int r;
 
@@ -783,18 +792,27 @@ int en50221_app_pdu_send
     buf[7] = datalen & 0x7f;
     hlen = 8;
   } else if (datalen < 0x100) {
-    buf[7] = 0x82;
+    buf[7] = 0x81;
     buf[8] = datalen & 0xff;
     hlen = 9;
   } else if (datalen < 0x10000) {
-    buf[7] = 0x83;
+    buf[7] = 0x82;
     buf[8] = datalen >> 8;
     buf[9] = datalen & 0xff;
     hlen = 10;
+  } else if (datalen < 0x1000000) {
+    buf[7] = 0x83;
+    buf[8] = datalen >> 16;
+    buf[9] = (datalen >> 8) & 0xff;
+    buf[10] = datalen & 0xff;
+    hlen = 11;
   } else {
-    tvherror(LS_EN50221, "%s: too much apdu data to write %zd tag 0x%06x",
-                         app->cia_name, datalen, atag);
-    return -EIO;
+    buf[7] = 0x84;
+    buf[8] = datalen >> 24;
+    buf[9] = (datalen >> 16) & 0xff;
+    buf[10] = (datalen >> 8) & 0xff;
+    buf[11] = datalen & 0xff;
+    hlen = 12;
   }
   if (datalen > 0)
     memcpy(buf + hlen, data, datalen);
index 911e41e6211a7d984e957c9360adc70faae81c09..34c27ac2c3772648006405d809e1364eae75956a 100644 (file)
@@ -218,7 +218,7 @@ int en50221_extract_len
  * random public functions
  */
 int en50221_send_capmt
-  (en50221_slot_t *slot, const uint8_t *capmt, uint8_t capmtlen);
+  (en50221_slot_t *slot, const uint8_t *capmt, size_t capmtlen);
 int en50221_pcmcia_data_rate(en50221_slot_t *slot, uint8_t rate);
 int en50221_mmi_answer
   (en50221_slot_t *slot, const uint8_t *data, size_t datalen);
index 7509a03b7accdc770bf45f58efb0686d41095dce..180e81d9ed558a7cd49faa2caddb373823233b42 100644 (file)
@@ -222,7 +222,7 @@ en50221_app_ca_handle
 }
 
 int en50221_send_capmt
-  (en50221_slot_t *slot, const uint8_t *capmt, uint8_t capmtlen)
+  (en50221_slot_t *slot, const uint8_t *capmt, size_t capmtlen)
 {
   en50221_app_t *app;
   app = en50221_slot_find_application(slot, CICAM_RI_CONDITIONAL_ACCESS_SUPPORT, ~0);