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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 <openssl/aes.h>
  22. #include <openssl/md5.h>
  23. #include <dvbcsa/dvbcsa.h>
  24. #include "libfuncs/libfuncs.h"
  25. #include "libts/tsfuncs.h"
  26. // 7 * 188
  27. #define FRAME_SIZE 1316
  28. // How much seconds to assume the key is valid
  29. #define KEY_VALID_TIME 10
  30. struct key {
  31. uint8_t cw[16];
  32. int is_valid_cw;
  33. struct dvbcsa_key_s *csakey[2];
  34. struct dvbcsa_bs_key_s *bs_csakey[2];
  35. time_t ts; // At what time the key is set
  36. struct timeval ts_keyset; // At what time the key is set
  37. };
  38. // 4 auth header, 20 header size, 256 max data size, 16 potential padding
  39. #define CAMD35_HDR_LEN (20)
  40. #define CAMD35_BUF_LEN (4 + CAMD35_HDR_LEN + 256 + 16)
  41. struct camd35 {
  42. uint8_t buf[CAMD35_BUF_LEN];
  43. int server_fd;
  44. struct in_addr server_addr;
  45. unsigned int server_port;
  46. char user[64];
  47. char pass[64];
  48. int emm_count;
  49. int emm_count_report_interval;
  50. time_t emm_count_last_report;
  51. AES_KEY aes_encrypt_key;
  52. AES_KEY aes_decrypt_key;
  53. uint32_t auth_token;
  54. struct key *key;
  55. pthread_t thread;
  56. QUEUE *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 ecm_counter;
  87. pidmap_t pidmap;
  88. pidmap_t cc; // Continuity counters
  89. pidmap_t pid_seen;
  90. // CAMD handling
  91. struct key key;
  92. struct camd35 camd35;
  93. // Config
  94. char ident[128];
  95. char syslog_host[128];
  96. int syslog_port;
  97. int syslog_active;
  98. int daemonize;
  99. char pidfile[PATH_MAX];
  100. enum CA_system req_CA_sys;
  101. int emm_send;
  102. int emm_only;
  103. int pid_filter;
  104. uint8_t irdeto_ecm;
  105. int rtp_input;
  106. struct io input;
  107. struct io output;
  108. int debug_level;
  109. int ts_discont;
  110. int camd_stop;
  111. int is_cw_error;
  112. int threaded;
  113. int packet_delay;
  114. int decode_stop;
  115. pthread_t decode_thread;
  116. CBUF *decode_buf;
  117. int write_stop;
  118. pthread_t write_thread;
  119. CBUF *write_buf;
  120. };
  121. enum msg_type { EMM_MSG, ECM_MSG };
  122. struct camd_msg {
  123. enum msg_type type;
  124. uint16_t idx;
  125. uint16_t ca_id;
  126. uint16_t service_id;
  127. uint8_t data_len;
  128. uint8_t data[255];
  129. struct ts *ts;
  130. };
  131. void data_init(struct ts *ts);
  132. void data_free(struct ts *ts);
  133. #endif