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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef DATA_H
  2. #define DATA_H
  3. #include <pthread.h>
  4. #include <openssl/aes.h>
  5. #include <openssl/md5.h>
  6. #include <dvbcsa/dvbcsa.h>
  7. #include "libfuncs/libfuncs.h"
  8. #include "libts/tsfuncs.h"
  9. #include "cbuf.h"
  10. // 7 * 188
  11. #define FRAME_SIZE 1316
  12. struct key {
  13. uint8_t cw[16];
  14. int is_valid_cw;
  15. struct dvbcsa_key_s *csakey[2];
  16. struct dvbcsa_bs_key_s *bs_csakey[2];
  17. };
  18. // 4 auth header, 20 header size, 256 max data size, 16 potential padding
  19. #define CAMD35_HDR_LEN (20)
  20. #define CAMD35_BUF_LEN (4 + CAMD35_HDR_LEN + 256 + 16)
  21. struct camd35 {
  22. uint8_t buf[CAMD35_BUF_LEN];
  23. int server_fd;
  24. struct in_addr server_addr;
  25. unsigned int server_port;
  26. char user[64];
  27. char pass[64];
  28. AES_KEY aes_encrypt_key;
  29. AES_KEY aes_decrypt_key;
  30. uint32_t auth_token;
  31. struct key *key;
  32. pthread_t thread;
  33. QUEUE *queue;
  34. };
  35. enum io_type {
  36. FILE_IO,
  37. NET_IO,
  38. WTF_IO
  39. };
  40. struct io {
  41. int fd;
  42. enum io_type type;
  43. char *fname;
  44. struct in_addr addr;
  45. unsigned int port;
  46. // Used only for output
  47. int ttl;
  48. struct in_addr intf;
  49. };
  50. struct ts {
  51. // Stream handling
  52. struct ts_pat *pat, *curpat;
  53. struct ts_cat *cat, *curcat;
  54. struct ts_pmt *pmt, *curpmt;
  55. struct ts_privsec *emm, *last_emm;
  56. struct ts_privsec *ecm, *last_ecm;
  57. uint16_t pmt_pid;
  58. uint16_t service_id;
  59. uint16_t emm_caid, emm_pid;
  60. uint16_t ecm_caid, ecm_pid;
  61. uint16_t ecm_counter;
  62. pidmap_t pidmap;
  63. // CAMD handling
  64. struct key key;
  65. struct camd35 camd35;
  66. // Config
  67. enum CA_system req_CA_sys;
  68. int emm_send;
  69. int pid_filter;
  70. struct io input;
  71. struct io output;
  72. int debug_level;
  73. int camd_stop;
  74. int is_cw_error;
  75. int threaded;
  76. int decode_stop;
  77. pthread_t decode_thread;
  78. CBUF *decode_buf;
  79. int write_stop;
  80. pthread_t write_thread;
  81. CBUF *write_buf;
  82. };
  83. enum msg_type { EMM_MSG, ECM_MSG };
  84. struct camd_msg {
  85. enum msg_type type;
  86. uint16_t idx;
  87. uint16_t ca_id;
  88. uint16_t service_id;
  89. uint8_t data_len;
  90. uint8_t data[255];
  91. struct ts *ts;
  92. };
  93. void data_init(struct ts *ts);
  94. void data_free(struct ts *ts);
  95. #endif