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.

csa.h 4.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * CSA functions
  3. * Copyright (C) 2012 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 CSA_H
  19. #define CSA_H
  20. // The following *MUST* be the same as struct dvbcsa_bs_batch_s from libdvbcsa
  21. struct csa_batch {
  22. uint8_t *data; // Pointer to payload
  23. unsigned int len; // Payload bytes lenght
  24. };
  25. #if USE_LIBDVBCSA
  26. #include <dvbcsa/dvbcsa.h>
  27. #define use_dvbcsa 1
  28. #else
  29. #define use_dvbcsa 0
  30. #define dvbcsa_key_t void
  31. #define dvbcsa_bs_key_t void
  32. #define dvbcsa_bs_batch_s csa_batch
  33. static inline dvbcsa_key_t * dvbcsa_key_alloc(void) { return NULL; }
  34. static inline void dvbcsa_key_free(dvbcsa_key_t *key) { (void)key; }
  35. static inline void dvbcsa_key_set(const uint8_t *cw, dvbcsa_key_t *key) { (void)cw; (void)key; }
  36. static inline void dvbcsa_decrypt(const uint8_t *key, uint8_t *data, unsigned int len) { (void)key; (void)data; (void)len; }
  37. static inline unsigned int dvbcsa_bs_batch_size(void) { return 0; }
  38. static inline dvbcsa_bs_key_t * dvbcsa_bs_key_alloc(void) { return NULL; }
  39. static inline void dvbcsa_bs_key_free(dvbcsa_bs_key_t *key) { (void)key; }
  40. static inline void dvbcsa_bs_key_set(uint8_t *cw, dvbcsa_bs_key_t *key) { (void)cw; (void)key; }
  41. static inline void dvbcsa_bs_decrypt(const dvbcsa_bs_key_t *key, const struct dvbcsa_bs_batch_s *pcks, unsigned int maxlen) { (void)key; (void)pcks; (void)maxlen; }
  42. #endif
  43. #define ffdecsa_key_t void
  44. #if USE_FFDECSA
  45. #include "FFdecsa/FFdecsa.h"
  46. #define use_ffdecsa 1
  47. static inline int ffdecsa_get_internal_parallelism(void) { return get_internal_parallelism(); }
  48. static inline int ffdecsa_get_suggested_cluster_size(void) { return get_suggested_cluster_size(); }
  49. static inline ffdecsa_key_t * ffdecsa_key_alloc(void) { return get_key_struct(); }
  50. static inline void ffdecsa_key_free(ffdecsa_key_t *keys) { free_key_struct(keys); }
  51. static inline void ffdecsa_set_cw(ffdecsa_key_t *keys, const uint8_t *even, const uint8_t *odd) { set_control_words(keys, even, odd); }
  52. static inline void ffdecsa_set_even_cw(void *keys, const uint8_t *even) { set_even_control_word(keys, even); }
  53. static inline void ffdecsa_set_odd_cw(ffdecsa_key_t *keys, const uint8_t *odd) { return set_odd_control_word(keys, odd); }
  54. static inline int ffdecsa_decrypt_packets(ffdecsa_key_t *keys, uint8_t **cluster) { return decrypt_packets(keys, cluster); }
  55. #else
  56. #define use_ffdecsa 0
  57. static inline int ffdecsa_get_internal_parallelism(void) { return 0; }
  58. static inline int ffdecsa_get_suggested_cluster_size(void) { return 0; }
  59. static inline ffdecsa_key_t * ffdecsa_key_alloc(void) { return NULL; }
  60. static inline void ffdecsa_key_free(ffdecsa_key_t *keys) { (void)keys; }
  61. static inline void ffdecsa_set_cw(ffdecsa_key_t *keys, const uint8_t *even, const uint8_t *odd) { (void)keys; (void)even; (void)odd; }
  62. static inline void ffdecsa_set_even_cw(void *keys, const uint8_t *even) { (void)keys; (void)even; }
  63. static inline void ffdecsa_set_odd_cw(ffdecsa_key_t *keys, const uint8_t *odd) { (void)keys; (void)odd; }
  64. static inline int ffdecsa_decrypt_packets(ffdecsa_key_t *keys, uint8_t **cluster) { (void)keys; (void)cluster; return 0; }
  65. #endif
  66. #include "data.h"
  67. struct csakey {
  68. dvbcsa_key_t *s_csakey[2];
  69. dvbcsa_bs_key_t *bs_csakey[2];
  70. ffdecsa_key_t *ff_csakey;
  71. };
  72. csakey_t * csa_key_alloc (void);
  73. void csa_key_free (csakey_t **pcsakey);
  74. unsigned int csa_get_batch_size (void);
  75. void csa_set_even_cw (csakey_t *csakey, uint8_t *even_cw);
  76. void csa_set_odd_cw (csakey_t *csakey, uint8_t *odd_cw);
  77. void csa_decrypt_single_packet (csakey_t *csakey, uint8_t *ts_packet);
  78. void csa_decrypt_multiple_even (csakey_t *csakey, struct csa_batch *batch);
  79. void csa_decrypt_multiple_odd (csakey_t *csakey, struct csa_batch *batch);
  80. void csa_decrypt_multiple_ff (csakey_t *csakey, uint8_t **cluster);
  81. void csa_benchmark(void);
  82. #endif