1 | #ifdef HAVE_DVBAPI
|
---|
2 |
|
---|
3 | #ifndef MODULEDVBAPI_H_
|
---|
4 | #define MODULEDVBAPI_H_
|
---|
5 |
|
---|
6 |
|
---|
7 | #include <sys/un.h>
|
---|
8 | #include <dirent.h>
|
---|
9 |
|
---|
10 | #define TYPE_ECM 1
|
---|
11 | #define TYPE_EMM 2
|
---|
12 |
|
---|
13 | //api
|
---|
14 | #define DVBAPI_3 0
|
---|
15 | #define DVBAPI_1 1
|
---|
16 | #define STAPI 2
|
---|
17 | #define COOLAPI 3
|
---|
18 |
|
---|
19 | #define PORT 9000
|
---|
20 |
|
---|
21 | #define TMPDIR "/tmp/"
|
---|
22 | #define STANDBY_FILE "/tmp/.pauseoscam"
|
---|
23 | #define ECMINFO_FILE "/tmp/ecm.info"
|
---|
24 |
|
---|
25 | #ifdef COOL
|
---|
26 | #define MAX_CA_DEVICES 4
|
---|
27 | #endif
|
---|
28 | #define MAX_DEMUX 16
|
---|
29 | #define MAX_CAID 50
|
---|
30 | #define ECM_PIDS 30
|
---|
31 | #define MAX_FILTER 24
|
---|
32 |
|
---|
33 | #ifndef FALSE
|
---|
34 | #define FALSE 0
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #ifndef TRUE
|
---|
38 | #define TRUE 1
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | #define BOX_COUNT 6
|
---|
42 |
|
---|
43 | struct box_devices
|
---|
44 | {
|
---|
45 | char *path;
|
---|
46 | char *ca_device;
|
---|
47 | char *demux_device;
|
---|
48 | char *cam_socket_path;
|
---|
49 | int8_t api;
|
---|
50 | };
|
---|
51 |
|
---|
52 | struct s_ecmpids
|
---|
53 | {
|
---|
54 | uint16_t CAID;
|
---|
55 | uint32_t PROVID;
|
---|
56 | uint16_t ECM_PID;
|
---|
57 | uint16_t EMM_PID;
|
---|
58 | int8_t irdeto_numchids;
|
---|
59 | int8_t irdeto_curchid;
|
---|
60 | int32_t irdeto_chids;
|
---|
61 | int32_t irdeto_cycle;
|
---|
62 | int8_t checked;
|
---|
63 | int8_t status;
|
---|
64 | unsigned char table;
|
---|
65 | int8_t index;
|
---|
66 | uint32_t streams;
|
---|
67 | };
|
---|
68 |
|
---|
69 | typedef struct filter_s
|
---|
70 | {
|
---|
71 | uint32_t fd; //FilterHandle
|
---|
72 | int32_t pidindex;
|
---|
73 | int32_t pid;
|
---|
74 | uint16_t caid;
|
---|
75 | uint16_t type;
|
---|
76 | int32_t count;
|
---|
77 | #ifdef WITH_STAPI
|
---|
78 | int32_t NumSlots;
|
---|
79 | uint32_t SlotHandle[10];
|
---|
80 | uint32_t BufferHandle[10];
|
---|
81 | #endif
|
---|
82 | } FILTERTYPE;
|
---|
83 |
|
---|
84 | struct s_emmpids
|
---|
85 | {
|
---|
86 | uint16_t CAID;
|
---|
87 | uint32_t PROVID;
|
---|
88 | uint16_t PID;
|
---|
89 | uint8_t type;
|
---|
90 | };
|
---|
91 |
|
---|
92 | #ifdef WITH_STAPI
|
---|
93 | struct STDEVICE
|
---|
94 | {
|
---|
95 | char name[20];
|
---|
96 | uint32_t SessionHandle;
|
---|
97 | uint32_t SignalHandle;
|
---|
98 | pthread_t thread;
|
---|
99 | struct filter_s demux_fd[MAX_DEMUX][MAX_FILTER];
|
---|
100 | };
|
---|
101 |
|
---|
102 | struct read_thread_param
|
---|
103 | {
|
---|
104 | int32_t id;
|
---|
105 | struct s_client *cli;
|
---|
106 | };
|
---|
107 |
|
---|
108 | #define BUFFLEN 1024
|
---|
109 | #define PROCDIR "/proc/stpti4_core/"
|
---|
110 | #define PTINUM 10
|
---|
111 | #define SLOTNUM 20
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | typedef struct demux_s
|
---|
115 | {
|
---|
116 | int8_t demux_index;
|
---|
117 | FILTERTYPE demux_fd[MAX_FILTER];
|
---|
118 | int32_t ca_mask;
|
---|
119 | int8_t adapter_index;
|
---|
120 | int32_t socket_fd;
|
---|
121 | int8_t ECMpidcount;
|
---|
122 | struct s_ecmpids ECMpids[ECM_PIDS];
|
---|
123 | int8_t EMMpidcount;
|
---|
124 | struct s_emmpids EMMpids[ECM_PIDS];
|
---|
125 | int8_t STREAMpidcount;
|
---|
126 | uint16_t STREAMpids[ECM_PIDS];
|
---|
127 | int16_t pidindex;
|
---|
128 | int16_t curindex;
|
---|
129 | int8_t tries;
|
---|
130 | int8_t max_status;
|
---|
131 | uint16_t program_number;
|
---|
132 | unsigned char lastcw[2][8];
|
---|
133 | int8_t emm_filter;
|
---|
134 | uchar hexserial[8];
|
---|
135 | struct s_reader *rdr;
|
---|
136 | char pmt_file[30];
|
---|
137 | int32_t pmt_time;
|
---|
138 | #ifdef WITH_STAPI
|
---|
139 | uint32_t DescramblerHandle[PTINUM];
|
---|
140 | int32_t desc_pidcount;
|
---|
141 | uint32_t slot_assc[PTINUM][SLOTNUM];
|
---|
142 | #endif
|
---|
143 | } DEMUXTYPE;
|
---|
144 |
|
---|
145 | #ifdef COOL
|
---|
146 | struct cool_dmx
|
---|
147 | {
|
---|
148 | int32_t opened;
|
---|
149 | int32_t filter_attached;
|
---|
150 | int32_t fd;
|
---|
151 | void * buffer1;
|
---|
152 | void * buffer2;
|
---|
153 | void * channel;
|
---|
154 | void * filter;
|
---|
155 | void * device;
|
---|
156 | int32_t pid;
|
---|
157 | pthread_mutex_t mutex;
|
---|
158 | int32_t demux_id;
|
---|
159 | int32_t demux_index;
|
---|
160 | int32_t filter_num;
|
---|
161 | };
|
---|
162 | typedef struct cool_dmx dmx_t;
|
---|
163 |
|
---|
164 | typedef struct
|
---|
165 | {
|
---|
166 | int32_t type;
|
---|
167 | uint32_t size;
|
---|
168 | int32_t unknown1;
|
---|
169 | int16_t unknown2;
|
---|
170 | int32_t unknown3;
|
---|
171 | int32_t unknown[4];
|
---|
172 | } buffer_open_arg_t;
|
---|
173 |
|
---|
174 | typedef struct
|
---|
175 | {
|
---|
176 | int32_t type;
|
---|
177 | int32_t unknown[2];
|
---|
178 | } channel_open_arg_t;
|
---|
179 |
|
---|
180 | typedef struct
|
---|
181 | {
|
---|
182 | uint32_t number;
|
---|
183 | int32_t unknown1;
|
---|
184 | int32_t unknown2;
|
---|
185 | int32_t unknown3;
|
---|
186 | int32_t unknown4;
|
---|
187 | int32_t unknown5;
|
---|
188 | int32_t unknown6;
|
---|
189 | int32_t unknown[6];
|
---|
190 | } device_open_arg_t;
|
---|
191 |
|
---|
192 | typedef struct
|
---|
193 | {
|
---|
194 | uint32_t length;
|
---|
195 | unsigned char filter[12];
|
---|
196 | unsigned char mask[12];
|
---|
197 | int32_t unknown[16];
|
---|
198 | } filter_set_t;
|
---|
199 |
|
---|
200 | typedef struct
|
---|
201 | {
|
---|
202 | int32_t unk;
|
---|
203 | int32_t type;
|
---|
204 | int32_t unknown[4];
|
---|
205 | uint32_t len;
|
---|
206 | } dmx_callback_data_t;
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | struct s_dvbapi_priority
|
---|
210 | {
|
---|
211 | char type; // p or i
|
---|
212 | uint16_t caid;
|
---|
213 | uint32_t provid;
|
---|
214 | uint16_t srvid;
|
---|
215 | uint16_t chid;
|
---|
216 | uint16_t ecmpid;
|
---|
217 | uint16_t mapcaid;
|
---|
218 | uint32_t mapprovid;
|
---|
219 | int16_t delay;
|
---|
220 | int8_t force;
|
---|
221 | #ifdef WITH_STAPI
|
---|
222 | char devname[30];
|
---|
223 | char pmtfile[30];
|
---|
224 | int8_t disablefilter;
|
---|
225 | #endif
|
---|
226 | struct s_dvbapi_priority *next;
|
---|
227 | };
|
---|
228 |
|
---|
229 |
|
---|
230 | #define DMX_FILTER_SIZE 16
|
---|
231 |
|
---|
232 |
|
---|
233 | //dvbapi 1
|
---|
234 | typedef struct dmxFilter
|
---|
235 | {
|
---|
236 | uint8_t filter[DMX_FILTER_SIZE];
|
---|
237 | uint8_t mask[DMX_FILTER_SIZE];
|
---|
238 | } dmxFilter_t;
|
---|
239 |
|
---|
240 | struct dmxSctFilterParams
|
---|
241 | {
|
---|
242 | uint16_t pid;
|
---|
243 | dmxFilter_t filter;
|
---|
244 | uint32_t timeout;
|
---|
245 | uint32_t flags;
|
---|
246 | #define DMX_CHECK_CRC 1
|
---|
247 | #define DMX_ONESHOT 2
|
---|
248 | #define DMX_IMMEDIATE_START 4
|
---|
249 | #define DMX_BUCKET 0x1000 /* added in 2005.05.18 */
|
---|
250 | #define DMX_KERNEL_CLIENT 0x8000
|
---|
251 | };
|
---|
252 |
|
---|
253 | #define DMX_START1 _IOW('o',41,int)
|
---|
254 | #define DMX_STOP1 _IOW('o',42,int)
|
---|
255 | #define DMX_SET_FILTER1 _IOW('o',43,struct dmxSctFilterParams *)
|
---|
256 | //------------------------------------------------------------------
|
---|
257 |
|
---|
258 |
|
---|
259 | //dbox2+ufs
|
---|
260 | typedef struct dmx_filter
|
---|
261 | {
|
---|
262 | uint8_t filter[DMX_FILTER_SIZE];
|
---|
263 | uint8_t mask[DMX_FILTER_SIZE];
|
---|
264 | uint8_t mode[DMX_FILTER_SIZE];
|
---|
265 | } dmx_filter_t;
|
---|
266 |
|
---|
267 |
|
---|
268 | struct dmx_sct_filter_params
|
---|
269 | {
|
---|
270 | uint16_t pid;
|
---|
271 | dmx_filter_t filter;
|
---|
272 | uint32_t timeout;
|
---|
273 | uint32_t flags;
|
---|
274 | #define DMX_CHECK_CRC 1
|
---|
275 | #define DMX_ONESHOT 2
|
---|
276 | #define DMX_IMMEDIATE_START 4
|
---|
277 | #define DMX_KERNEL_CLIENT 0x8000
|
---|
278 | };
|
---|
279 |
|
---|
280 | typedef struct ca_descr {
|
---|
281 | uint32_t index;
|
---|
282 | uint32_t parity; /* 0 == even, 1 == odd */
|
---|
283 | unsigned char cw[8];
|
---|
284 | } ca_descr_t;
|
---|
285 |
|
---|
286 | typedef struct ca_pid {
|
---|
287 | uint32_t pid;
|
---|
288 | int32_t index; /* -1 == disable*/
|
---|
289 | } ca_pid_t;
|
---|
290 |
|
---|
291 | #define DMX_START _IO('o', 41)
|
---|
292 | #define DMX_STOP _IO('o', 42)
|
---|
293 | #define DMX_SET_FILTER _IOW('o', 43, struct dmx_sct_filter_params)
|
---|
294 |
|
---|
295 | #define CA_SET_DESCR _IOW('o', 134, ca_descr_t)
|
---|
296 | #define CA_SET_PID _IOW('o', 135, ca_pid_t)
|
---|
297 | // --------------------------------------------------------------------
|
---|
298 |
|
---|
299 | #ifdef AZBOX
|
---|
300 | #include "openxcas/openxcas_api.h"
|
---|
301 | #include "openxcas/openxcas_message.h"
|
---|
302 |
|
---|
303 | int32_t openxcas_provid, openxcas_seq, openxcas_filter_idx, openxcas_stream_id, openxcas_cipher_idx, openxcas_busy;
|
---|
304 | unsigned char openxcas_cw[16];
|
---|
305 | uint16_t openxcas_sid, openxcas_caid, openxcas_ecm_pid, openxcas_video_pid, openxcas_audio_pid, openxcas_data_pid;
|
---|
306 |
|
---|
307 | void azbox_openxcas_ecm_callback(int32_t stream_id, uint32_t sequence, int32_t cipher_index, uint32_t caid, unsigned char *ecm_data, int32_t l, uint16_t pid);
|
---|
308 | void azbox_openxcas_ex_callback(int32_t stream_id, uint32_t seq, int32_t idx, uint32_t pid, unsigned char *ecm_data, int32_t l);
|
---|
309 | void azbox_send_dcw(struct s_client *client, ECM_REQUEST *er);
|
---|
310 | void * azbox_main(void * cli);
|
---|
311 | #endif
|
---|
312 |
|
---|
313 | #ifdef COOL
|
---|
314 | int32_t cnxt_cbuf_init(void *);
|
---|
315 | int32_t cnxt_cbuf_open(void **handle, buffer_open_arg_t * arg, void *, void *);
|
---|
316 | int32_t cnxt_cbuf_get_used(void *buffer, uint32_t * bytes_used);
|
---|
317 | int32_t cnxt_cbuf_attach(void *handle, int32_t type, void * channel);
|
---|
318 | int32_t cnxt_cbuf_detach(void *handle, int32_t type, void * channel);
|
---|
319 | int32_t cnxt_cbuf_close(void * handle);
|
---|
320 | int32_t cnxt_cbuf_read_data(void * handle, void *buffer, uint32_t size, uint32_t * ret_size);
|
---|
321 | int32_t cnxt_cbuf_flush(void * handle, int);
|
---|
322 |
|
---|
323 | void cnxt_kal_initialize(void);
|
---|
324 | void cnxt_kal_terminate(void);
|
---|
325 | void cnxt_drv_init(void);
|
---|
326 | void cnxt_drv_term(void);
|
---|
327 |
|
---|
328 | int32_t cnxt_dmx_init(void *);
|
---|
329 | int32_t cnxt_dmx_open(void **device, device_open_arg_t *arg, void *, void *);
|
---|
330 | int32_t cnxt_dmx_close(void * handle);
|
---|
331 | int32_t cnxt_dmx_channel_open(void * device, void **channel, channel_open_arg_t * arg, void * callback, void *);
|
---|
332 | int32_t cnxt_dmx_channel_close(void * channel);
|
---|
333 | int32_t cnxt_dmx_open_filter(void * handle, void *flt);
|
---|
334 | int32_t cnxt_dmx_set_filter(void * handle, filter_set_t * arg, void *);
|
---|
335 | int32_t cnxt_dmx_close_filter(void * filter);
|
---|
336 | int32_t cnxt_dmx_channel_attach(void * channel, int32_t param1, int32_t param2, void * buffer);
|
---|
337 | int32_t cnxt_dmx_channel_detach(void * channel, int32_t param1, int32_t param2, void * buffer);
|
---|
338 | int32_t cnxt_dmx_channel_attach_filter(void * channel, void * filter);
|
---|
339 | int32_t cnxt_dmx_channel_detach_filter(void * channel, void * filter);
|
---|
340 | int32_t cnxt_dmx_set_channel_buffer(void * channel, int32_t param1, void * buffer);
|
---|
341 | int32_t cnxt_dmx_set_channel_pid(void * channel, uint32_t pid);
|
---|
342 | int32_t cnxt_dmx_get_channel_from_pid(void * device, uint16_t pid, void * channel);
|
---|
343 | int32_t cnxt_dmx_set_channel_key(void * channel, int32_t param1, uint32_t parity, unsigned char *cw, uint32_t len);
|
---|
344 | int32_t cnxt_dmx_channel_ctrl(void * channel, int32_t param1, int32_t param2);
|
---|
345 |
|
---|
346 | int32_t cnxt_smc_init(void *);
|
---|
347 |
|
---|
348 |
|
---|
349 | void coolapi_open();
|
---|
350 | void coolapi_open_all();
|
---|
351 | void coolapi_close_all();
|
---|
352 | int32_t coolapi_set_filter (int32_t fd, int32_t num, int32_t pid, unsigned char * flt, unsigned char * mask);
|
---|
353 | int32_t coolapi_remove_filter (int32_t fd, int32_t num);
|
---|
354 | int32_t coolapi_open_device (int32_t demux_index, int32_t demux_id);
|
---|
355 | int32_t coolapi_close_device(int32_t fd);
|
---|
356 | int32_t coolapi_read(int32_t fd, unsigned char * buffer, uint32_t len);
|
---|
357 | int32_t coolapi_write_cw(int32_t mask, uint16_t *STREAMpids, int32_t count, ca_descr_t * ca_descr);
|
---|
358 | int32_t coolapi_set_pid (int32_t demux_id, int32_t num, int32_t index, int32_t pid);
|
---|
359 | void coolapi_close_all();
|
---|
360 | #endif
|
---|
361 |
|
---|
362 | #ifdef WITH_STAPI
|
---|
363 | static int32_t stapi_open();
|
---|
364 | static int32_t stapi_set_filter(int32_t demux_id, uint16_t pid, uchar *filter, uchar *mask, int32_t num, char *pmtfile);
|
---|
365 | static int32_t stapi_remove_filter(int32_t demux_id, int32_t num, char *pmtfile);
|
---|
366 | static int32_t stapi_set_pid(int32_t demux_id, int32_t num, int32_t index, uint16_t pid, char *pmtfile);
|
---|
367 | static int32_t stapi_write_cw(int32_t demux_id, uchar *cw, uint16_t *, int32_t, char *pmtfile);
|
---|
368 | static int32_t stapi_do_set_filter(int32_t demux_id, FILTERTYPE *filter, uint16_t *pids, int32_t pidcount, uchar *filt, uchar *mask, int32_t dev_id);
|
---|
369 | static int32_t stapi_do_remove_filter(int32_t demux_id, FILTERTYPE *filter, int32_t dev_id);
|
---|
370 | static void *stapi_read_thread(void *);
|
---|
371 |
|
---|
372 | uint32_t oscam_stapi_Capability(char *name);
|
---|
373 | char *oscam_stapi_LibVersion(void);
|
---|
374 | uint32_t oscam_stapi_Open(char *name, uint32_t *sessionhandle);
|
---|
375 | uint32_t oscam_stapi_SignalAllocate(uint32_t sessionhandle, uint32_t *signalhandle);
|
---|
376 | uint32_t oscam_stapi_FilterAllocate(uint32_t sessionhandle, uint32_t *filterhandle);
|
---|
377 | uint32_t oscam_stapi_SlotInit(uint32_t sessionhandle, uint32_t signalhandle, uint32_t *bufferhandle, uint32_t *slothandle, uint16_t pid);
|
---|
378 | uint32_t oscam_stapi_FilterSet(uint32_t filterhandle, uchar *filt, uchar *mask);
|
---|
379 | uint32_t oscam_stapi_FilterAssociate(uint32_t filterhandle, uint32_t slothandle);
|
---|
380 | uint32_t oscam_stapi_SlotDeallocate(uint32_t slothandle);
|
---|
381 | uint32_t oscam_stapi_BufferDeallocate(uint32_t bufferhandle);
|
---|
382 | uint32_t oscam_stapi_FilterDeallocate(uint32_t filterhandle);
|
---|
383 | uint32_t oscam_stapi_Close(uint32_t sessionhandle);
|
---|
384 | uint32_t oscam_stapi_CheckVersion();
|
---|
385 | uint32_t oscam_stapi_DescramblerAssociate(uint32_t deschandle, uint32_t slot);
|
---|
386 | uint32_t oscam_stapi_DescramblerDisassociate(uint32_t deschandle, uint32_t slot);
|
---|
387 | uint32_t oscam_stapi_DescramblerAllocate(uint32_t sessionhandle, uint32_t *deschandle);
|
---|
388 | uint32_t oscam_stapi_DescramblerDeallocate(uint32_t deschandle);
|
---|
389 | uint32_t oscam_stapi_DescramblerSet(uint32_t deschandle, int32_t parity, uchar *cw);
|
---|
390 | uint32_t oscam_stapi_SignalWaitBuffer(uint32_t signalhandle, uint32_t *qbuffer, int32_t timeout);
|
---|
391 | uint32_t oscam_stapi_BufferReadSection(uint32_t bufferhandle, uint32_t *filterlist, int32_t maxfilter, uint32_t *filtercount, int32_t *crc, uchar *buf, int32_t bufsize, uint32_t *size);
|
---|
392 | uint32_t oscam_stapi_SignalAbort(uint32_t signalhandle);
|
---|
393 | uint32_t oscam_stapi_PidQuery(char *name, uint16_t pid);
|
---|
394 | uint32_t oscam_stapi_BufferFlush(uint32_t bufferhandle);
|
---|
395 | uint32_t oscam_stapi_SlotClearPid(uint32_t slot);
|
---|
396 | #endif
|
---|
397 |
|
---|
398 | void dvbapi_stop_descrambling(int);
|
---|
399 | void dvbapi_process_input(int32_t demux_id, int32_t filter_num, uchar *buffer, int32_t len);
|
---|
400 | int32_t dvbapi_open_device(int32_t, int32_t, int);
|
---|
401 | int32_t dvbapi_stop_filternum(int32_t demux_index, int32_t num);
|
---|
402 | int32_t dvbapi_stop_filter(int32_t demux_index, int32_t type);
|
---|
403 | struct s_dvbapi_priority *dvbapi_check_prio_match(int32_t demux_id, int32_t pidindex, char type);
|
---|
404 | void dvbapi_send_dcw(struct s_client *client, ECM_REQUEST *er);
|
---|
405 | void dvbapi_write_cw(int32_t demux_id, uchar *cw, int32_t index);
|
---|
406 |
|
---|
407 | #undef cs_log
|
---|
408 | #define cs_log(txt, x...) cs_log_int(0, 1, NULL, 0, "dvbapi: "txt, ##x)
|
---|
409 | #ifdef WITH_DEBUG
|
---|
410 | #undef cs_debug_mask
|
---|
411 | #define cs_debug_mask(x,txt,y...) cs_log_int(x, 1, NULL, 0, "dvbapi: "txt, ##y)
|
---|
412 | #endif
|
---|
413 |
|
---|
414 | #endif // MODULEDVBAPI_H_
|
---|
415 | #endif // WITH_DVBAPI
|
---|