tsdecrypt reads and decrypts CSA encrypted incoming mpeg transport stream over UDP/RTP using code words obtained from OSCAM or similar CAM server. tsdecrypt communicates with CAM server using cs378x (camd35 over tcp) protocol or newcamd protocol. https://georgi.unixsol.org/programs/tsdecrypt/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

data.c 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Data functions
  3. * Copyright (C) 2011 Unix Solutions Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License (COPYING file) for more details.
  13. *
  14. */
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "data.h"
  19. #include "csa.h"
  20. #include "camd.h"
  21. void data_init(struct ts *ts) {
  22. memset(ts, 0, sizeof(struct ts));
  23. // Stream
  24. ts->pat = ts_pat_alloc();
  25. ts->curpat = ts_pat_alloc();
  26. ts->genpat = ts_pat_alloc();
  27. ts->cat = ts_cat_alloc();
  28. ts->curcat = ts_cat_alloc();
  29. ts->pmt = ts_pmt_alloc();
  30. ts->curpmt = ts_pmt_alloc();
  31. ts->sdt = ts_sdt_alloc();
  32. ts->cursdt = ts_sdt_alloc();
  33. ts->emm = ts_privsec_alloc();
  34. ts->last_emm = ts_privsec_alloc();
  35. ts->tmp_emm = ts_privsec_alloc();
  36. ts->ecm = ts_privsec_alloc();
  37. ts->last_ecm = ts_privsec_alloc();
  38. ts->tmp_ecm = ts_privsec_alloc();
  39. pidmap_clear(&ts->pidmap);
  40. pidmap_clear(&ts->cc);
  41. pidmap_clear(&ts->pid_seen);
  42. // Key
  43. memset(&ts->key, 0, sizeof(ts->key));
  44. ts->key.csakey = csa_key_alloc();
  45. gettimeofday(&ts->key.ts_keyset, NULL);
  46. // CAMD
  47. memset(&ts->camd, 0, sizeof(ts->camd));
  48. ts->camd.server_fd = -1;
  49. ts->camd.server_port = 2233;
  50. ts->camd.key = &ts->key;
  51. ts->camd.user = "user";
  52. ts->camd.pass = "pass";
  53. strcpy(ts->camd.newcamd.hex_des_key, "0102030405060708091011121314");
  54. camd_proto_cs378x(&ts->camd.ops);
  55. // Config
  56. ts->syslog_port = 514;
  57. ts->ts_discont = 1;
  58. ts->ecm_cw_log = 1;
  59. ts->debug_level = 0;
  60. ts->req_CA_sys = CA_CONAX;
  61. ts->emm_send = 0;
  62. ts->pid_filter = 1;
  63. ts->emm_report_interval = 60;
  64. ts->emm_last_report = time(NULL);
  65. ts->ecm_report_interval = 60;
  66. ts->ecm_last_report = time(NULL);
  67. ts->cw_warn_sec = 60;
  68. ts->cw_last_warn= time(NULL);
  69. ts->cw_last_warn= ts->cw_last_warn + ts->cw_warn_sec;
  70. ts->key.ts = time(NULL);
  71. ts->input.fd = 0; // STDIN
  72. ts->input.type = FILE_IO;
  73. ts->output.fd = 1; // STDOUT
  74. ts->output.type = FILE_IO;
  75. ts->output.ttl = 1;
  76. ts->output.tos = -1;
  77. ts->decode_buf = cbuf_init((7 * csa_get_batch_size() * 188) * 16, "decode"); // ~658Kb
  78. ts->write_buf = cbuf_init((7 * csa_get_batch_size() * 188) * 8, "write"); // ~324Kb
  79. ts->input_buffer= list_new("input");
  80. pthread_attr_init(&ts->thread_attr);
  81. size_t stack_size;
  82. pthread_attr_getstacksize(&ts->thread_attr, &stack_size);
  83. if (stack_size > THREAD_STACK_SIZE)
  84. pthread_attr_setstacksize(&ts->thread_attr, THREAD_STACK_SIZE);
  85. }
  86. void data_free(struct ts *ts) {
  87. ts_pat_free(&ts->pat);
  88. ts_pat_free(&ts->curpat);
  89. ts_pat_free(&ts->genpat);
  90. ts_cat_free(&ts->cat);
  91. ts_cat_free(&ts->curcat);
  92. ts_pmt_free(&ts->pmt);
  93. ts_pmt_free(&ts->curpmt);
  94. ts_sdt_free(&ts->sdt);
  95. ts_sdt_free(&ts->cursdt);
  96. ts_privsec_free(&ts->emm);
  97. ts_privsec_free(&ts->last_emm);
  98. ts_privsec_free(&ts->tmp_emm);
  99. ts_privsec_free(&ts->ecm);
  100. ts_privsec_free(&ts->last_ecm);
  101. ts_privsec_free(&ts->tmp_ecm);
  102. csa_key_free(&ts->key.csakey);
  103. cbuf_free(&ts->decode_buf);
  104. cbuf_free(&ts->write_buf);
  105. FREE(ts->input.fname);
  106. FREE(ts->output.fname);
  107. list_free(&ts->input_buffer, free, NULL);
  108. // glibc's crypt function allocates static buffer on first crypt() call.
  109. // Since newcamd uses crypt(), the result is saved in c->newcamd.crypt_passwd
  110. // and in order to avoid leaking 43 bytes of memory on exit which makes valgrind
  111. // unhappy it is a good idea to free the memory (ONCE!).
  112. FREE(ts->camd.newcamd.crypt_passwd);
  113. pthread_attr_destroy(&ts->thread_attr);
  114. }