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.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Data definitions
  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. #ifndef DATA_H
  19. #define DATA_H
  20. #include <pthread.h>
  21. #include <limits.h>
  22. #include <openssl/aes.h>
  23. #include <openssl/md5.h>
  24. #include <dvbcsa/dvbcsa.h>
  25. #include "libfuncs/libfuncs.h"
  26. #include "libtsfuncs/tsfuncs.h"
  27. // 7 * 188
  28. #define FRAME_SIZE 1316
  29. // How much seconds to assume the key is valid
  30. #define KEY_VALID_TIME 10
  31. struct key {
  32. uint8_t cw[16];
  33. int is_valid_cw;
  34. struct dvbcsa_key_s *csakey[2];
  35. struct dvbcsa_bs_key_s *bs_csakey[2];
  36. time_t ts; // At what time the key is set
  37. struct timeval ts_keyset; // At what time the key is set
  38. };
  39. // 4 auth header, 20 header size, 256 max data size, 16 potential padding
  40. #define CAMD35_HDR_LEN (20)
  41. #define CAMD35_BUF_LEN (4 + CAMD35_HDR_LEN + 256 + 16)
  42. struct camd35 {
  43. uint8_t buf[CAMD35_BUF_LEN];
  44. int server_fd;
  45. struct in_addr server_addr;
  46. unsigned int server_port;
  47. char user[64];
  48. char pass[64];
  49. int emm_count;
  50. int emm_count_report_interval;
  51. time_t emm_count_last_report;
  52. AES_KEY aes_encrypt_key;
  53. AES_KEY aes_decrypt_key;
  54. uint32_t auth_token;
  55. struct key *key;
  56. pthread_t thread;
  57. QUEUE *queue;
  58. };
  59. enum io_type {
  60. FILE_IO,
  61. NET_IO,
  62. WTF_IO
  63. };
  64. struct io {
  65. int fd;
  66. enum io_type type;
  67. char *fname;
  68. struct in_addr addr;
  69. unsigned int port;
  70. // Used only for output
  71. int ttl;
  72. struct in_addr intf;
  73. };
  74. struct ts {
  75. // Stream handling
  76. struct ts_pat *pat, *curpat;
  77. struct ts_cat *cat, *curcat;
  78. struct ts_pmt *pmt, *curpmt;
  79. struct ts_privsec *emm, *last_emm;
  80. struct ts_privsec *ecm, *last_ecm;
  81. struct ts_privsec *tmp_emm;
  82. struct ts_privsec *tmp_ecm;
  83. uint16_t pmt_pid;
  84. uint16_t service_id;
  85. uint16_t emm_caid, emm_pid;
  86. uint16_t ecm_caid, ecm_pid;
  87. uint16_t forced_emm_pid;
  88. uint16_t forced_ecm_pid;
  89. uint16_t ecm_counter;
  90. pidmap_t pidmap;
  91. pidmap_t cc; // Continuity counters
  92. pidmap_t pid_seen;
  93. // CAMD handling
  94. struct key key;
  95. struct camd35 camd35;
  96. // Config
  97. char ident[128];
  98. char syslog_host[128];
  99. int syslog_port;
  100. int syslog_active;
  101. int daemonize;
  102. char pidfile[PATH_MAX];
  103. enum CA_system req_CA_sys;
  104. int emm_send;
  105. int emm_only;
  106. int pid_filter;
  107. uint8_t irdeto_ecm;
  108. int rtp_input;
  109. struct io input;
  110. struct io output;
  111. int debug_level;
  112. int ts_discont;
  113. int camd_stop;
  114. int is_cw_error;
  115. int threaded;
  116. int packet_delay;
  117. int decode_stop;
  118. pthread_t decode_thread;
  119. CBUF *decode_buf;
  120. int write_stop;
  121. pthread_t write_thread;
  122. CBUF *write_buf;
  123. };
  124. enum msg_type { EMM_MSG, ECM_MSG };
  125. struct camd_msg {
  126. enum msg_type type;
  127. uint16_t idx;
  128. uint16_t ca_id;
  129. uint16_t service_id;
  130. uint8_t data_len;
  131. uint8_t data[255];
  132. struct ts *ts;
  133. };
  134. void data_init(struct ts *ts);
  135. void data_free(struct ts *ts);
  136. #endif