]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
cccam: Fix nodeid byte display order Also change logic for generating a new random...
authorLuis Alves <ljalvs@gmail.com>
Tue, 16 May 2017 21:00:35 +0000 (22:00 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 19 May 2017 13:17:40 +0000 (15:17 +0200)
src/descrambler/cccam.c

index 07edf279f2dd4eb3f116adcf64b9cdcf760a81ac..8466e17b3b5e01b6e49cb390d24b375a99f32dcf 100644 (file)
@@ -1851,24 +1851,23 @@ caclient_cccam_nodeid_set(void *o, const void *v)
   cccam_t *cccam = o;
   const char *s = v ?: "";
   uint8_t key[8];
-  int u, l, i = 0;
-
-  if (!strlen(v)) {
-    uuid_random(cccam->cccam_nodeid, 8);
-    i = 1;
-  } else {
-    for(i = 0; i < ARRAY_SIZE(key); i++) {
-      while(*s != 0 && !isxdigit(*s)) s++;
-      u = *s ? nibble(*s++) : 0;
-      while(*s != 0 && !isxdigit(*s)) s++;
-      l = *s ? nibble(*s++) : 0;
-      key[7-i] = (u << 4) | l;
-    }
-    if (memcmp(cccam->cccam_nodeid, key, ARRAY_SIZE(key)) != 0) {
-      memcpy(cccam->cccam_nodeid, key, ARRAY_SIZE(key));
-      i = 1;
-    }
+  int i, u, l;
+  uint64_t node_id;
+
+  for(i = 0; i < ARRAY_SIZE(key); i++) {
+    while(*s != 0 && !isxdigit(*s)) s++;
+    u = *s ? nibble(*s++) : 0;
+    while(*s != 0 && !isxdigit(*s)) s++;
+    l = *s ? nibble(*s++) : 0;
+    key[i] = (u << 4) | l;
   }
+
+  node_id = be64toh(*((uint64_t*) key));
+  if (!node_id)
+    uuid_random(key, 8);
+
+  if ((i = memcmp(cccam->cccam_nodeid, key, ARRAY_SIZE(key))) != 0)
+    memcpy(cccam->cccam_nodeid, key, ARRAY_SIZE(key));
   return i;
 }
 
@@ -1880,14 +1879,14 @@ caclient_cccam_nodeid_get(void *o)
   static const char *ret = buf;
   snprintf(buf, sizeof(buf),
            "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
-           cccam->cccam_nodeid[0x7],
-           cccam->cccam_nodeid[0x6],
-           cccam->cccam_nodeid[0x5],
-           cccam->cccam_nodeid[0x4],
-           cccam->cccam_nodeid[0x3],
-           cccam->cccam_nodeid[0x2],
+           cccam->cccam_nodeid[0x0],
            cccam->cccam_nodeid[0x1],
-           cccam->cccam_nodeid[0x0]);
+           cccam->cccam_nodeid[0x2],
+           cccam->cccam_nodeid[0x3],
+           cccam->cccam_nodeid[0x4],
+           cccam->cccam_nodeid[0x5],
+           cccam->cccam_nodeid[0x6],
+           cccam->cccam_nodeid[0x7]);
   return &ret;
 }