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

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