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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 notify {
  32. pthread_t thread; /* Thread handle */
  33. QUEUE *notifications; /* Notification queue */
  34. char ident[512]; /* tsdecrypt ident (set by -i) */
  35. char program[512]; /* What program to exec */
  36. };
  37. struct key {
  38. uint8_t cw[16];
  39. int is_valid_cw;
  40. struct dvbcsa_key_s *csakey[2];
  41. struct dvbcsa_bs_key_s *bs_csakey[2];
  42. time_t ts; // At what time the key is set
  43. struct timeval ts_keyset; // At what time the key is set
  44. };
  45. // 4 auth header, 20 header size, 256 max data size, 16 potential padding
  46. #define CAMD35_HDR_LEN (20)
  47. #define CAMD35_BUF_LEN (4 + CAMD35_HDR_LEN + 256 + 16)
  48. struct camd35 {
  49. uint8_t buf[CAMD35_BUF_LEN];
  50. int server_fd;
  51. struct in_addr server_addr;
  52. unsigned int server_port;
  53. char user[64];
  54. char pass[64];
  55. AES_KEY aes_encrypt_key;
  56. AES_KEY aes_decrypt_key;
  57. uint32_t auth_token;
  58. struct key *key;
  59. pthread_t thread;
  60. QUEUE *req_queue;
  61. QUEUE *ecm_queue;
  62. QUEUE *emm_queue;
  63. };
  64. enum io_type {
  65. FILE_IO,
  66. NET_IO,
  67. WTF_IO
  68. };
  69. struct io {
  70. int fd;
  71. enum io_type type;
  72. char *fname;
  73. struct in_addr addr;
  74. unsigned int port;
  75. // Used only for output
  76. int ttl;
  77. struct in_addr intf;
  78. };
  79. struct ts {
  80. // Stream handling
  81. struct ts_pat *pat, *curpat;
  82. struct ts_cat *cat, *curcat;
  83. struct ts_pmt *pmt, *curpmt;
  84. struct ts_privsec *emm, *last_emm;
  85. struct ts_privsec *ecm, *last_ecm;
  86. struct ts_privsec *tmp_emm;
  87. struct ts_privsec *tmp_ecm;
  88. uint16_t pmt_pid;
  89. uint16_t service_id;
  90. uint16_t emm_caid, emm_pid;
  91. uint16_t ecm_caid, ecm_pid;
  92. uint16_t forced_caid;
  93. uint16_t forced_emm_pid;
  94. uint16_t forced_ecm_pid;
  95. uint16_t ecm_counter;
  96. pidmap_t pidmap;
  97. pidmap_t cc; // Continuity counters
  98. pidmap_t pid_seen;
  99. // Stats
  100. unsigned int emm_seen_count;
  101. unsigned int emm_processed_count;
  102. unsigned int emm_report_interval;
  103. time_t emm_last_report;
  104. unsigned int ecm_seen_count;
  105. unsigned int ecm_processed_count;
  106. unsigned int ecm_duplicate_count;
  107. unsigned int ecm_report_interval;
  108. time_t ecm_last_report;
  109. unsigned int cw_warn_sec;
  110. time_t cw_last_warn;
  111. // CAMD handling
  112. struct key key;
  113. struct camd35 camd35;
  114. // Config
  115. char ident[128];
  116. char syslog_host[128];
  117. int syslog_port;
  118. int syslog_active;
  119. int daemonize;
  120. char pidfile[PATH_MAX];
  121. enum CA_system req_CA_sys;
  122. int emm_send;
  123. int emm_only;
  124. int pid_filter;
  125. uint8_t irdeto_ecm;
  126. int ecm_cw_log;
  127. int rtp_input;
  128. struct io input;
  129. struct io output;
  130. int debug_level;
  131. int ts_discont;
  132. int camd_stop;
  133. int is_cw_error;
  134. int threaded;
  135. int packet_delay;
  136. int decode_stop;
  137. pthread_t decode_thread;
  138. CBUF *decode_buf;
  139. int write_stop;
  140. pthread_t write_thread;
  141. CBUF *write_buf;
  142. struct notify *notify;
  143. char notify_program[512];
  144. };
  145. enum msg_type { EMM_MSG, ECM_MSG };
  146. struct camd_msg {
  147. enum msg_type type;
  148. uint16_t idx;
  149. uint16_t ca_id;
  150. uint16_t service_id;
  151. uint8_t data_len;
  152. uint8_t data[255];
  153. struct ts *ts;
  154. };
  155. void data_init(struct ts *ts);
  156. void data_free(struct ts *ts);
  157. #endif