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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. void data_init(struct ts *ts) {
  23. memset(ts, 0, sizeof(struct ts));
  24. // Stream
  25. ts->pat = ts_pat_alloc();
  26. ts->curpat = 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->emm = ts_privsec_alloc();
  32. ts->last_emm = ts_privsec_alloc();
  33. ts->tmp_emm = ts_privsec_alloc();
  34. ts->ecm = ts_privsec_alloc();
  35. ts->last_ecm = ts_privsec_alloc();
  36. ts->tmp_ecm = ts_privsec_alloc();
  37. pidmap_clear(&ts->pidmap);
  38. pidmap_clear(&ts->cc);
  39. pidmap_clear(&ts->pid_seen);
  40. // Key
  41. memset(&ts->key, 0, sizeof(ts->key));
  42. ts->key.csakey[0] = dvbcsa_key_alloc();
  43. ts->key.csakey[1] = dvbcsa_key_alloc();
  44. ts->key.bs_csakey[0] = dvbcsa_bs_key_alloc();
  45. ts->key.bs_csakey[1] = dvbcsa_bs_key_alloc();
  46. gettimeofday(&ts->key.ts_keyset, NULL);
  47. // CAMD
  48. memset(&ts->camd35, 0, sizeof(ts->camd35));
  49. ts->camd35.server_fd = -1;
  50. ts->camd35.server_port = 2233;
  51. ts->camd35.key = &ts->key;
  52. strcpy(ts->camd35.user, "user");
  53. strcpy(ts->camd35.pass, "pass");
  54. ts->camd35.emm_count_report_interval = 60;
  55. ts->camd35.emm_count_last_report = time(NULL);
  56. // Config
  57. ts->syslog_port = 514;
  58. ts->ts_discont = 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->packet_delay = 0;
  64. ts->input.fd = 0; // STDIN
  65. ts->input.type = FILE_IO;
  66. ts->output.fd = 1; // STDOUT
  67. ts->output.type = FILE_IO;
  68. ts->output.ttl = 1;
  69. ts->decode_buf = cbuf_init((7 * dvbcsa_bs_batch_size() * 188) * 2, "decode");
  70. ts->write_buf = cbuf_init((7 * dvbcsa_bs_batch_size() * 188) * 2, "write");
  71. }
  72. void data_free(struct ts *ts) {
  73. ts_pat_free(&ts->pat);
  74. ts_pat_free(&ts->curpat);
  75. ts_cat_free(&ts->cat);
  76. ts_cat_free(&ts->curcat);
  77. ts_pmt_free(&ts->pmt);
  78. ts_pmt_free(&ts->curpmt);
  79. ts_privsec_free(&ts->emm);
  80. ts_privsec_free(&ts->last_emm);
  81. ts_privsec_free(&ts->tmp_emm);
  82. ts_privsec_free(&ts->ecm);
  83. ts_privsec_free(&ts->last_ecm);
  84. ts_privsec_free(&ts->tmp_ecm);
  85. dvbcsa_key_free(ts->key.csakey[0]);
  86. dvbcsa_key_free(ts->key.csakey[1]);
  87. dvbcsa_bs_key_free(ts->key.bs_csakey[0]);
  88. dvbcsa_bs_key_free(ts->key.bs_csakey[1]);
  89. cbuf_free(&ts->decode_buf);
  90. cbuf_free(&ts->write_buf);
  91. FREE(ts->input.fname);
  92. FREE(ts->output.fname);
  93. }