Advertisement
Guest User

Untitled

a guest
Nov 9th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.92 KB | None | 0 0
  1. static int32_t dvbapi_get_descrambler_info(void)
  2. {
  3.     int32_t ret = 0;
  4.  
  5.     // In enigma2 all ca devices are listed under adapter0. In addition we only
  6.     // need to ask one ca device to get the total number of descramblers. In
  7.     // PC installations, there are no ca devices, so we use a predefined value.
  8.  
  9.     if(cfg.dvbapi_boxtype == BOXTYPE_PC || cfg.dvbapi_boxtype == BOXTYPE_PC_NODMX)
  10.     {
  11.         ca_descramblers_total = INDEX_MAX_NET;
  12.         return 1; // nothing else to do for PCs
  13.     }
  14.  
  15.     int32_t fd = 0, ca_offset = 0;
  16.     char device_path[128], device_path2[128];
  17.  
  18.     if(cfg.dvbapi_boxtype == BOXTYPE_DUCKBOX ||
  19.         cfg.dvbapi_boxtype == BOXTYPE_DBOX2 ||
  20.         cfg.dvbapi_boxtype == BOXTYPE_UFS910)
  21.     {
  22.         ca_offset = 1;
  23.     }
  24.  
  25.     // Ask device for exact number of ca descramblers
  26.     snprintf(device_path2, sizeof(device_path2), devices[selected_box].ca_device, ca_offset);
  27.     snprintf(device_path, sizeof(device_path), devices[selected_box].path, 0);
  28.  
  29.     if (!cs_strncat(device_path, device_path2, sizeof(device_path)))
  30.         return ret;
  31.  
  32.     DIR *dir = NULL;
  33.     struct dirent *ep = NULL;
  34.     ca_descramblers_total = 0;
  35.  
  36.     snprintf(device_path2, sizeof(device_path2), devices[selected_box].path, 0);
  37.  
  38.     if ((dir = opendir(device_path2)) != NULL)
  39.     {
  40.         while ((ep = readdir(dir)) != NULL)
  41.         {
  42.             if (strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0)
  43.             {
  44.                 // search for ca0, ca1...
  45.                 if (ep->d_name[0] == 'c' && ep->d_name[1] == 'a')
  46.                 {
  47.                     ca_descramblers_total += 1;
  48.                 }
  49.             }
  50.         }
  51.  
  52.         closedir(dir);
  53.     }
  54.  
  55.     if (ca_descramblers_total > 0)
  56.     {
  57.         cs_log("Detected %s device, total available descramblers: %d", device_path, ca_descramblers_total);
  58.         ret = 1;
  59.     }
  60.     else
  61.     {
  62.         // Use a safe default in case we fail to get the exact number
  63.         ca_descramblers_total = INDEX_MAX_LOCAL;
  64.         cs_log("Detected %s device, guesing safe count of total available descramblers: %d", device_path, ca_descramblers_total);
  65.         ret = 0;
  66.     }
  67.  
  68.     return ret;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement