1 #ifndef DISABLE_DVBAPI
2 #ifndef DVBAPI_H
3 #define DVBAPI_H
4 
5 #include "adapter.h"
6 #include "pmt.h"
7 #include "stream.h"
8 
9 #define DVBAPI_PROTOCOL_VERSION 2
10 
11 #define DVBAPI_FILTER_DATA 0xFFFF0000
12 #define DVBAPI_CLIENT_INFO 0xFFFF0001
13 #define DVBAPI_SERVER_INFO 0xFFFF0002
14 #define DVBAPI_DMX_SET_FILTER 0x403c6f2b
15 #define DVBAPI_CA_SET_PID 0x40086f87
16 #define DVBAPI_CA_SET_DESCR 0x40106f86
17 #define DVBAPI_DMX_STOP 0x00006f2a
18 #define CA_SET_DESCR_X 0x866f10
19 #define CA_SET_DESCR_AES 0x40106f87
20 #define CA_SET_DESCR_AES_X 0x876f10
21 #define CA_SET_PID_X 0x876f08
22 #define DMX_STOP_X 0x2a6f00
23 #define DMX_SET_FILTER_X 0x2b6f3c
24 #define DVBAPI_ECM_INFO 0xFFFF0003
25 #define CA_SET_DESCR_MODE 0x400c6f88
26 
27 #define AOT_CA_PMT 0x9F803282
28 
29 #define CAPMT_LIST_MORE                                                        \
30     0x00 // append a 'MORE' CAPMT object the list and start receiving the next
31          // object
32 #define CAPMT_LIST_FIRST                                                       \
33     0x01 // clear the list when a 'FIRST' CAPMT object is received, and start
34          // receiving the next object
35 #define CAPMT_LIST_LAST                                                        \
36     0x02 // append a 'LAST' CAPMT object to the list and start working with the
37          // list
38 #define CAPMT_LIST_ONLY                                                        \
39     0x03 // clear the list when an 'ONLY' CAPMT object is received, and start
40          // working with the object
41 #define CAPMT_LIST_ADD                                                         \
42     0x04 // append an 'ADD' CAPMT object to the current list and start working
43          // with the updated list
44 #define CAPMT_LIST_UPDATE                                                      \
45     0x05 // replace an entry in the list with an 'UPDATE' CAPMT object, and
46          // start working with the updated list
47 
48 #define MAX_KEYS 255
49 #define MAX_PMT_DATA 1880
50 #define MAX_KEY_FILTERS 20
51 typedef struct struct_key {
52     char enabled;
53     SMutex mutex;
54     int pmt_id;
55     int algo;
56     unsigned char cw[2][16];
57     uint32_t cw_time[2];
58     int key_len;
59     int sid;
60     int pmt_pid;
61     int64_t last_ecm, last_dmx_stop;
62     uint8_t hops;
63     uint16_t caid, info_pid;
64     uint32_t prid;
65     int ecmtime;
66     int demux_index, adapter_index;
67     int id;
68     int adapter;
69     int ver;
70     int ecms;
71     int program_id; // pmt sid
72     unsigned char cardsystem[64], reader[64], from[64], protocol[64];
73     int parity;
74     int blen;
75     int tsid, onid;
76     int filter_id[MAX_KEY_FILTERS], filter[MAX_KEY_FILTERS],
77         demux[MAX_KEY_FILTERS], pid[MAX_KEY_FILTERS],
78         ecm_parity[MAX_KEY_FILTERS];
79     int64_t last_parity_change;
80 } SKey;
81 
82 void init_dvbapi();
83 int have_dvbapi();
84 int dvbapi_enabled();
85 int send_ecm(int filter_id, unsigned char *b, int len, void *opaque);
86 int batch_size();
87 int decrypt_stream(adapter *ad, void *arg);
88 int keys_add(int i, int adapter, int pmt_id);
89 int keys_del(int i);
90 int dvbapi_process_pmt(unsigned char *b, adapter *ad);
91 void dvbapi_pid_add(adapter *a, int pid, SPid *cp, int existing);
92 void dvbapi_pid_del(adapter *a, int pid, SPid *cp);
93 void dvbapi_delete_keys_for_adapter(int aid);
94 void register_dvbapi();
95 void unregister_dvbapi();
96 void send_client_info(sockets *s);
97 int set_algo(SKey *k, int algo, int mode);
98 
99 #endif
100 #endif
101