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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. AES_KEY aes_encrypt_key;
  50. AES_KEY aes_decrypt_key;
  51. uint32_t auth_token;
  52. struct key *key;
  53. pthread_t thread;
  54. QUEUE *queue;
  55. };
  56. enum io_type {
  57. FILE_IO,
  58. NET_IO,
  59. WTF_IO
  60. };
  61. struct io {
  62. int fd;
  63. enum io_type type;
  64. char *fname;
  65. struct in_addr addr;
  66. unsigned int port;
  67. // Used only for output
  68. int ttl;
  69. struct in_addr intf;
  70. };
  71. struct ts {
  72. // Stream handling
  73. struct ts_pat *pat, *curpat;
  74. struct ts_cat *cat, *curcat;
  75. struct ts_pmt *pmt, *curpmt;
  76. struct ts_privsec *emm, *last_emm;
  77. struct ts_privsec *ecm, *last_ecm;
  78. struct ts_privsec *tmp_emm;
  79. struct ts_privsec *tmp_ecm;
  80. uint16_t pmt_pid;
  81. uint16_t service_id;
  82. uint16_t emm_caid, emm_pid;
  83. uint16_t ecm_caid, ecm_pid;
  84. uint16_t forced_caid;
  85. uint16_t forced_emm_pid;
  86. uint16_t forced_ecm_pid;
  87. uint16_t ecm_counter;
  88. pidmap_t pidmap;
  89. pidmap_t cc; // Continuity counters
  90. pidmap_t pid_seen;
  91. // Stats
  92. unsigned int emm_seen_count;
  93. unsigned int emm_processed_count;
  94. unsigned int emm_report_interval;
  95. time_t emm_last_report;
  96. unsigned int ecm_seen_count;
  97. unsigned int ecm_processed_count;
  98. unsigned int ecm_duplicate_count;
  99. unsigned int ecm_report_interval;
  100. time_t ecm_last_report;
  101. unsigned int cw_warn_sec;
  102. time_t cw_last_warn;
  103. // CAMD handling
  104. struct key key;
  105. struct camd35 camd35;
  106. // Config
  107. char ident[128];
  108. char syslog_host[128];
  109. int syslog_port;
  110. int syslog_active;
  111. int daemonize;
  112. char pidfile[PATH_MAX];
  113. enum CA_system req_CA_sys;
  114. int emm_send;
  115. int emm_only;
  116. int pid_filter;
  117. uint8_t irdeto_ecm;
  118. int ecm_cw_log;
  119. int rtp_input;
  120. struct io input;
  121. struct io output;
  122. int debug_level;
  123. int ts_discont;
  124. int camd_stop;
  125. int is_cw_error;
  126. int threaded;
  127. int packet_delay;
  128. int decode_stop;
  129. pthread_t decode_thread;
  130. CBUF *decode_buf;
  131. int write_stop;
  132. pthread_t write_thread;
  133. CBUF *write_buf;
  134. };
  135. enum msg_type { EMM_MSG, ECM_MSG };
  136. struct camd_msg {
  137. enum msg_type type;
  138. uint16_t idx;
  139. uint16_t ca_id;
  140. uint16_t service_id;
  141. uint8_t data_len;
  142. uint8_t data[255];
  143. struct ts *ts;
  144. };
  145. void data_init(struct ts *ts);
  146. void data_free(struct ts *ts);
  147. #endif