-
Notifications
You must be signed in to change notification settings - Fork 0
/
module-dvbapi.h
302 lines (266 loc) · 7.93 KB
/
module-dvbapi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#ifndef MODULE_DVBAPI_H_
#define MODULE_DVBAPI_H_
#ifdef HAVE_DVBAPI
#include <sys/un.h>
#define TYPE_ECM 1
#define TYPE_EMM 2
//api
#define DVBAPI_3 0
#define DVBAPI_1 1
#define STAPI 2
#define COOLAPI 3
#define TMPDIR "/tmp/"
#define STANDBY_FILE "/tmp/.pauseoscam"
#define ECMINFO_FILE "/tmp/ecm.info"
#define MAX_DEMUX 16
#define MAX_CAID 50
#define ECM_PIDS 30
#define MAX_FILTER 24
#define BOX_COUNT 6
#define BOXTYPE_DREAMBOX 1
#define BOXTYPE_DUCKBOX 2
#define BOXTYPE_UFS910 3
#define BOXTYPE_DBOX2 4
#define BOXTYPE_IPBOX 5
#define BOXTYPE_IPBOX_PMT 6
#define BOXTYPE_DM7000 7
#define BOXTYPE_QBOXHD 8
#define BOXTYPE_COOLSTREAM 9
#define BOXTYPE_NEUMO 10
#define BOXTYPE_PC 11
#define BOXTYPE_PC_NODMX 12
#define BOXTYPES 12
#define DMXMD5HASHSIZE 16 // use MD5()
#define REMOVED_STREAMPID_LASTINDEX 2
#define REMOVED_STREAMPID_INDEX 1
#define NO_STREAMPID_LISTED 0
#define FOUND_STREAMPID_INDEX 0
#define ADDED_STREAMPID_INDEX 1
#define CA_IS_IN_USE 1
#define CA_IS_CLEAR 0
#define DUMMY_FD 0xFFFF
//constants used int socket communication:
#define DVBAPI_PROTOCOL_VERSION 1
#define DVBAPI_CA_SET_PID 0x40086f87
#define DVBAPI_CA_SET_DESCR 0x40106f86
#define DVBAPI_DMX_SET_FILTER 0x403c6f2b
#define DVBAPI_DMX_STOP 0x00006f2a
#define DVBAPI_AOT_CA 0x9F803000
#define DVBAPI_AOT_CA_PMT 0x9F803200 //least significant byte is length (ignored)
#define DVBAPI_AOT_CA_STOP 0x9F803F04
#define DVBAPI_FILTER_DATA 0xFFFF0000
#define DVBAPI_CLIENT_INFO 0xFFFF0001
#define DVBAPI_SERVER_INFO 0xFFFF0002
struct box_devices
{
char *path;
char *ca_device;
char *demux_device;
char *cam_socket_path;
int8_t api;
};
struct s_ecmpids
{
uint16_t CAID;
uint32_t PROVID;
uint16_t ECM_PID;
uint32_t CHID;
uint16_t EMM_PID;
uint32_t VPID; // videopid
uint8_t irdeto_maxindex; // max irdeto indexes always fresh fetched from current ecm
uint8_t irdeto_curindex; // current irdeto index we want to handle
uint8_t irdeto_cycle; // temp var that holds the irdeto index we started with to detect if we cycled trough all indexes
int8_t checked;
int8_t status;
uint8_t tries;
unsigned char table;
int8_t index;
uint32_t streams;
};
typedef struct filter_s
{
uint32_t fd; //FilterHandle
int32_t pidindex;
int32_t pid;
uint16_t caid;
uint32_t provid;
uint16_t type;
int32_t count;
uchar ecmd5[CS_ECMSTORESIZE]; // last requested ecm md5
#ifdef WITH_STAPI
int32_t NumSlots;
uint32_t SlotHandle[10];
uint32_t BufferHandle[10];
#endif
} FILTERTYPE;
struct s_emmpids
{
uint16_t CAID;
uint32_t PROVID;
uint16_t PID;
uint8_t type;
};
#define PTINUM 10
#define SLOTNUM 20
typedef struct demux_s
{
int8_t demux_index;
FILTERTYPE demux_fd[MAX_FILTER];
int32_t ca_mask;
int8_t adapter_index;
int32_t socket_fd;
int8_t ECMpidcount;
struct timeb emmstart; // last time emm cat was started
struct s_ecmpids ECMpids[ECM_PIDS];
int8_t EMMpidcount;
struct s_emmpids EMMpids[ECM_PIDS];
uint16_t max_emm_filter;
int8_t STREAMpidcount;
uint16_t STREAMpids[ECM_PIDS];
int16_t pidindex;
int16_t curindex;
int8_t max_status;
uint16_t program_number;
uint16_t onid;
uint16_t tsid;
uint16_t pmtpid;
uint32_t enigma_namespace;
unsigned char lastcw[2][8];
int8_t emm_filter;
uchar hexserial[8];
struct s_reader *rdr;
char pmt_file[30];
time_t pmt_time;
uint8_t stopdescramble;
uint8_t old_ecmfiltercount; // previous ecm filtercount
uint8_t old_emmfiltercount; // previous emm filtercount
pthread_mutex_t answerlock; // requestmode 1 avoid race
#ifdef WITH_STAPI
uint32_t DescramblerHandle[PTINUM];
int32_t desc_pidcount;
uint32_t slot_assc[PTINUM][SLOTNUM];
#endif
} DEMUXTYPE;
typedef struct s_streampid
{
uint8_t cadevice; // holds ca device
uint16_t streampid; // holds pids
uint32_t activeindexers; // bitmask indexers if streampid enabled for index bit is set
}STREAMPIDTYPE;
struct s_dvbapi_priority
{
char type; // p or i
uint16_t caid;
uint32_t provid;
uint16_t srvid;
uint32_t chid;
uint16_t ecmpid;
uint16_t mapcaid;
uint32_t mapprovid;
uint16_t mapecmpid;
int16_t delay;
int8_t force;
int8_t pidx;
#ifdef WITH_STAPI
char devname[30];
char pmtfile[30];
int8_t disablefilter;
#endif
struct s_dvbapi_priority *next;
};
#define DMX_FILTER_SIZE 16
//dvbapi 1
typedef struct dmxFilter
{
uint8_t filter[DMX_FILTER_SIZE];
uint8_t mask[DMX_FILTER_SIZE];
} dmxFilter_t;
struct dmxSctFilterParams
{
uint16_t pid;
dmxFilter_t filter;
uint32_t timeout;
uint32_t flags;
#define DMX_CHECK_CRC 1
#define DMX_ONESHOT 2
#define DMX_IMMEDIATE_START 4
#define DMX_BUCKET 0x1000 /* added in 2005.05.18 */
#define DMX_KERNEL_CLIENT 0x8000
};
#define DMX_START1 _IOW('o',41,int)
#define DMX_STOP1 _IOW('o',42,int)
#define DMX_SET_FILTER1 _IOW('o',43,struct dmxSctFilterParams *)
//------------------------------------------------------------------
//dbox2+ufs
typedef struct dmx_filter
{
uint8_t filter[DMX_FILTER_SIZE];
uint8_t mask[DMX_FILTER_SIZE];
uint8_t mode[DMX_FILTER_SIZE];
} dmx_filter_t;
struct dmx_sct_filter_params
{
uint16_t pid;
dmx_filter_t filter;
uint32_t timeout;
uint32_t flags;
#define DMX_CHECK_CRC 1
#define DMX_ONESHOT 2
#define DMX_IMMEDIATE_START 4
#define DMX_KERNEL_CLIENT 0x8000
};
typedef struct ca_descr
{
uint32_t index;
uint32_t parity; /* 0 == even, 1 == odd */
unsigned char cw[8];
} ca_descr_t;
typedef struct ca_pid
{
uint32_t pid;
int32_t index; /* -1 == disable*/
} ca_pid_t;
#define DMX_START _IO('o', 41)
#define DMX_STOP _IO('o', 42)
#define DMX_SET_FILTER _IOW('o', 43, struct dmx_sct_filter_params)
#define CA_SET_DESCR _IOW('o', 134, ca_descr_t)
#define CA_SET_PID _IOW('o', 135, ca_pid_t)
// --------------------------------------------------------------------
void dvbapi_stop_descrambling(int);
void dvbapi_process_input(int32_t demux_id, int32_t filter_num, uchar *buffer, int32_t len);
int32_t dvbapi_open_device(int32_t, int32_t, int);
int32_t dvbapi_stop_filternum(int32_t demux_index, int32_t num);
int32_t dvbapi_stop_filter(int32_t demux_index, int32_t type);
struct s_dvbapi_priority *dvbapi_check_prio_match(int32_t demux_id, int32_t pidindex, char type);
void dvbapi_send_dcw(struct s_client *client, ECM_REQUEST *er);
void dvbapi_write_cw(int32_t demux_id, uchar *cw, int32_t idx);
int32_t dvbapi_parse_capmt(unsigned char *buffer, uint32_t length, int32_t connfd, char *pmtfile);
void request_cw(struct s_client *client, ECM_REQUEST *er, int32_t demux_id, uint8_t delayed_ecm_check);
void dvbapi_try_next_caid(int32_t demux_id, int8_t checked);
void dvbapi_read_priority(void);
int32_t dvbapi_set_section_filter(int32_t demux_index, ECM_REQUEST *er);
int32_t dvbapi_activate_section_filter(int32_t demux_index, int32_t num, int32_t fd, int32_t pid, uchar *filter, uchar *mask);
int32_t dvbapi_check_ecm_delayed_delivery(int32_t demux_index, ECM_REQUEST *er);
int32_t dvbapi_get_filternum(int32_t demux_index, ECM_REQUEST *er, int32_t type);
int32_t dvbapi_ca_setpid(int32_t demux_index, int32_t pid);
void dvbapi_set_pid(int32_t demux_id, int32_t num, int32_t idx, bool enable);
int8_t update_streampid_list(uint8_t cadevice, uint16_t pid, int32_t idx);
int8_t remove_streampid_from_list(uint8_t cadevice, uint16_t pid, int32_t idx);
void disable_unused_streampids(int16_t demux_id);
int8_t is_ca_used(uint8_t cadevice);
const char *dvbapi_get_client_name(void);
uint16_t dvbapi_get_client_proto_version(void);
void delayer(ECM_REQUEST *er);
void check_add_emmpid(int32_t demux_index, uchar *filter, int32_t l, int32_t emmtype);
#ifdef DVBAPI_LOG_PREFIX
#undef cs_log
#define cs_log(txt, x...) cs_log_int(0, 1, NULL, 0, "dvbapi: "txt, ##x)
#ifdef WITH_DEBUG
#undef cs_debug_mask
#define cs_debug_mask(x,txt,y...) cs_log_int(x, 1, NULL, 0, "dvbapi: "txt, ##y)
#endif
#endif
#else
static inline void dvbapi_read_priority(void) { }
#endif // WITH_DVBAPI
#endif // MODULE_DVBAPI_H_