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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "data.h"
  22. #include "camd.h"
  23. void data_init(struct ts *ts) {
  24. memset(ts, 0, sizeof(struct ts));
  25. // Stream
  26. ts->pat = ts_pat_alloc();
  27. ts->curpat = ts_pat_alloc();
  28. ts->genpat = ts_pat_alloc();
  29. ts->cat = ts_cat_alloc();
  30. ts->curcat = ts_cat_alloc();
  31. ts->pmt = ts_pmt_alloc();
  32. ts->curpmt = ts_pmt_alloc();
  33. ts->sdt = ts_sdt_alloc();
  34. ts->cursdt = ts_sdt_alloc();
  35. ts->emm = ts_privsec_alloc();
  36. ts->last_emm = ts_privsec_alloc();
  37. ts->tmp_emm = ts_privsec_alloc();
  38. ts->ecm = ts_privsec_alloc();
  39. ts->last_ecm = ts_privsec_alloc();
  40. ts->tmp_ecm = ts_privsec_alloc();
  41. pidmap_clear(&ts->pidmap);
  42. pidmap_clear(&ts->cc);
  43. pidmap_clear(&ts->pid_seen);
  44. // Key
  45. memset(&ts->key, 0, sizeof(ts->key));
  46. ts->key.csakey[0] = dvbcsa_key_alloc();
  47. ts->key.csakey[1] = dvbcsa_key_alloc();
  48. ts->key.bs_csakey[0] = dvbcsa_bs_key_alloc();
  49. ts->key.bs_csakey[1] = dvbcsa_bs_key_alloc();
  50. gettimeofday(&ts->key.ts_keyset, NULL);
  51. // CAMD
  52. memset(&ts->camd, 0, sizeof(ts->camd));
  53. ts->camd.server_fd = -1;
  54. ts->camd.server_port = 2233;
  55. ts->camd.key = &ts->key;
  56. strcpy(ts->camd.user, "user");
  57. strcpy(ts->camd.pass, "pass");
  58. strcpy(ts->camd.newcamd.hex_des_key, "0102030405060708091011121314");
  59. camd_proto_cs378x(&ts->camd.ops);
  60. // Config
  61. ts->syslog_port = 514;
  62. ts->ts_discont = 1;
  63. ts->ecm_cw_log = 1;
  64. ts->debug_level = 0;
  65. ts->req_CA_sys = CA_CONAX;
  66. ts->emm_send = 0;
  67. ts->pid_filter = 1;
  68. ts->emm_report_interval = 60;
  69. ts->emm_last_report = time(NULL);
  70. ts->ecm_report_interval = 60;
  71. ts->ecm_last_report = time(NULL);
  72. ts->cw_warn_sec = 60;
  73. ts->cw_last_warn= time(NULL);
  74. ts->cw_last_warn= ts->cw_last_warn + ts->cw_warn_sec;
  75. ts->key.ts = time(NULL);
  76. ts->input.fd = 0; // STDIN
  77. ts->input.type = FILE_IO;
  78. ts->output.fd = 1; // STDOUT
  79. ts->output.type = FILE_IO;
  80. ts->output.ttl = 1;
  81. ts->output.tos = -1;
  82. ts->decode_buf = cbuf_init((7 * dvbcsa_bs_batch_size() * 188) * 16, "decode"); // ~658Kb
  83. ts->write_buf = cbuf_init((7 * dvbcsa_bs_batch_size() * 188) * 8, "write"); // ~324Kb
  84. }
  85. void data_free(struct ts *ts) {
  86. ts_pat_free(&ts->pat);
  87. ts_pat_free(&ts->curpat);
  88. ts_pat_free(&ts->genpat);
  89. ts_cat_free(&ts->cat);
  90. ts_cat_free(&ts->curcat);
  91. ts_pmt_free(&ts->pmt);
  92. ts_pmt_free(&ts->curpmt);
  93. ts_sdt_free(&ts->sdt);
  94. ts_sdt_free(&ts->cursdt);
  95. ts_privsec_free(&ts->emm);
  96. ts_privsec_free(&ts->last_emm);
  97. ts_privsec_free(&ts->tmp_emm);
  98. ts_privsec_free(&ts->ecm);
  99. ts_privsec_free(&ts->last_ecm);
  100. ts_privsec_free(&ts->tmp_ecm);
  101. dvbcsa_key_free(ts->key.csakey[0]);
  102. dvbcsa_key_free(ts->key.csakey[1]);
  103. dvbcsa_bs_key_free(ts->key.bs_csakey[0]);
  104. dvbcsa_bs_key_free(ts->key.bs_csakey[1]);
  105. cbuf_free(&ts->decode_buf);
  106. cbuf_free(&ts->write_buf);
  107. FREE(ts->input.fname);
  108. FREE(ts->output.fname);
  109. }