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.2KB

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