1 | #include <stdlib.h>
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <assert.h>
|
---|
4 | #include <fcntl.h>
|
---|
5 | #include <sys/ioctl.h>
|
---|
6 | #include <sys/poll.h>
|
---|
7 | #include <ctype.h>
|
---|
8 | #include <sys/types.h>
|
---|
9 | #include <sys/stat.h>
|
---|
10 | #include <sys/shm.h>
|
---|
11 | #include <sys/wait.h>
|
---|
12 | #include <unistd.h>
|
---|
13 | #include <sys/mman.h>
|
---|
14 | #include <stdarg.h>
|
---|
15 | #include <time.h>
|
---|
16 | #include <sys/timeb.h>
|
---|
17 | #include <limits.h>
|
---|
18 |
|
---|
19 | #include <sys/socket.h>
|
---|
20 | #include <netinet/in.h>
|
---|
21 | #include <arpa/inet.h>
|
---|
22 | #include <netdb.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <signal.h>
|
---|
25 | #include <errno.h>
|
---|
26 |
|
---|
27 | #include <pthread.h>
|
---|
28 |
|
---|
29 | #ifndef CS_GLOBALS
|
---|
30 | #define CS_GLOBALS
|
---|
31 | #define CS_VERSION "0.99.3svn"
|
---|
32 |
|
---|
33 | #if defined(__GNUC__)
|
---|
34 | # define GCC_PACK __attribute__((packed))
|
---|
35 | #else
|
---|
36 | # define GCC_PACK
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #include "oscam-config.h"
|
---|
40 | #ifndef USE_CMAKE
|
---|
41 | # include "oscam-ostype.h"
|
---|
42 | #endif
|
---|
43 | #include "oscam-types.h"
|
---|
44 | #include "cscrypt/cscrypt.h"
|
---|
45 |
|
---|
46 | #ifndef CS_CONFDIR
|
---|
47 | #define CS_CONFDIR "/usr/local/etc"
|
---|
48 | #endif
|
---|
49 | #ifndef CS_MMAPFILE
|
---|
50 | #define CS_MMAPFILE "/tmp/mcps.mem"
|
---|
51 | #endif
|
---|
52 | #ifndef CS_LOGFILE
|
---|
53 | #define CS_LOGFILE "/var/log/mcps.log"
|
---|
54 | #endif
|
---|
55 | #define CS_QLEN 128 // size of request queue
|
---|
56 | #define CS_MAXQLEN 128 // size of request queue for cardreader
|
---|
57 | #define CS_MAXCAIDTAB 32 // max. caid-defs/user
|
---|
58 | #define CS_MAXTUNTAB 4 // max. betatunnel mappings
|
---|
59 | #define CS_MAXPROV 32
|
---|
60 | #define CS_MAXPORTS 32 // max server ports
|
---|
61 | #define CS_MAXFILTERS 16
|
---|
62 |
|
---|
63 | #define CS_MAXCARDS 4096
|
---|
64 | #define CS_MAXIGNORE 1024
|
---|
65 | #define CS_MAXLOCALS 16
|
---|
66 | #define CS_ECMSTORESIZE 16 // use MD5()
|
---|
67 | #define CS_EMMSTORESIZE 270
|
---|
68 | #define CS_CLIENT_TIMEOUT 5000
|
---|
69 | #define CS_CLIENT_MAXIDLE 120
|
---|
70 | #define CS_BIND_TIMEOUT 120
|
---|
71 | #define CS_DELAY 0
|
---|
72 | #define CS_RESOLVE_DELAY 30
|
---|
73 | #define CS_MAXLOGHIST 30
|
---|
74 | #define CS_LOGHISTSIZE 160 // 32+128: username + logline
|
---|
75 |
|
---|
76 | #ifdef OLD_DEFS
|
---|
77 | #ifdef CS_EMBEDDED
|
---|
78 | #define CS_MAXPENDING 32
|
---|
79 | #define CS_ECMCACHESIZE 32
|
---|
80 | #define CS_EMMCACHESIZE 64
|
---|
81 | #define CS_MAXPID 32
|
---|
82 | #define CS_MAXREADER 8
|
---|
83 | #else
|
---|
84 | #define CS_MAXPENDING 128
|
---|
85 | #define CS_ECMCACHESIZE 128
|
---|
86 | #define CS_EMMCACHESIZE 256
|
---|
87 | #define CS_MAXPID 128
|
---|
88 | #define CS_MAXREADER 64
|
---|
89 | #endif
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | #ifdef CS_EMBEDDED
|
---|
93 | #define CS_MAXPID 32
|
---|
94 | #define CS_MAXREADER (CS_MAXPID>>1)
|
---|
95 | #define CS_MAXPENDING CS_MAXPID
|
---|
96 | #define CS_ECMCACHESIZE CS_MAXPID
|
---|
97 | #define CS_EMMCACHESIZE (CS_MAXPID<<1)
|
---|
98 | #else
|
---|
99 | #define CS_MAXPID 512
|
---|
100 | #define CS_MAXREADER (CS_MAXPID>>2)
|
---|
101 | #define CS_MAXPENDING (CS_MAXPID<<1)
|
---|
102 | #define CS_ECMCACHESIZE CS_MAXPID
|
---|
103 | #define CS_EMMCACHESIZE (CS_MAXPID<<1)
|
---|
104 | #define CS_RDR_INIT_HIST
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | #define D_DUMP 1 // Debug Dumps
|
---|
108 | #define D_MASTER 2 // Debug Master Process
|
---|
109 | #define D_READER 4 // Debug Reader/Proxy Process
|
---|
110 | #define D_CLIENT 8 // Debug Client Process
|
---|
111 | #define D_DEVICE 16 // Debug Reader I/O
|
---|
112 | #define D_WATCHDOG 32 // Debug Watchdog
|
---|
113 | #define D_ALL_DUMP 63
|
---|
114 |
|
---|
115 | #define R_MOUSE 0x1 // Reader smartcard mouse
|
---|
116 | #define R_INTERN 0x2 // Reader smartcard intern
|
---|
117 | #define R_SMART 0x5 // Smartreader+
|
---|
118 | #define R_CAMD35 0x10 // Reader cascading camd 3.5x
|
---|
119 | #define R_CAMD33 0x11 // Reader cascading camd 3.3x
|
---|
120 | #define R_NEWCAMD 0x12 // Reader cascading newcamd
|
---|
121 | #define R_RADEGAST 0x13 // Reader cascading radegast
|
---|
122 | #define R_CS378X 0x14 // Reader cascading camd 3.5x TCP
|
---|
123 | #define R_GBOX 0x20 // Reader cascading gbox
|
---|
124 | #define R_SERIAL 0x80 // Reader serial
|
---|
125 | #define R_IS_NETWORK 0x70
|
---|
126 | #define R_IS_CASCADING 0xF0
|
---|
127 |
|
---|
128 | #define CS_MAX_MOD 8
|
---|
129 | #define MOD_CONN_TCP 1
|
---|
130 | #define MOD_CONN_UDP 2
|
---|
131 | #define MOD_CONN_NET 3
|
---|
132 | #define MOD_CONN_SERIAL 4
|
---|
133 |
|
---|
134 | #ifdef CS_CORE
|
---|
135 | char *PIP_ID_TXT[] = { "ECM", "EMM", "LOG", "CIN", "HUP", NULL };
|
---|
136 | char *RDR_CD_TXT[] = { "cd", "dsr", "cts", "ring", "none",
|
---|
137 | #ifdef USE_GPIO
|
---|
138 | "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7",
|
---|
139 | #endif
|
---|
140 | NULL };
|
---|
141 | #else
|
---|
142 | extern char *PIP_ID_TXT[];
|
---|
143 | extern char *RDR_CD_TXT[];
|
---|
144 | #endif
|
---|
145 |
|
---|
146 | #define PIP_ID_ECM 0
|
---|
147 | #define PIP_ID_EMM 1
|
---|
148 | #define PIP_ID_LOG 2
|
---|
149 | #define PIP_ID_CIN 3 // CARD_INFO
|
---|
150 | #define PIP_ID_HUP 4
|
---|
151 | #define PIP_ID_MAX PIP_ID_HUP
|
---|
152 | #define PIP_ID_DCW 5
|
---|
153 |
|
---|
154 | #define PIP_ID_ERR (-1)
|
---|
155 | #define PIP_ID_DIR (-2)
|
---|
156 | #define PIP_ID_NUL (-3)
|
---|
157 |
|
---|
158 | #define cdiff *c_start
|
---|
159 |
|
---|
160 | #define NCD_AUTO 0
|
---|
161 | #define NCD_524 1
|
---|
162 | #define NCD_525 2
|
---|
163 |
|
---|
164 | #define CS_ANTICASC
|
---|
165 |
|
---|
166 | // moved from reader-common.h
|
---|
167 | #define CARD_INSERTED 1
|
---|
168 | #define CARD_NEED_INIT 2
|
---|
169 | #define CARD_FAILURE 4
|
---|
170 |
|
---|
171 | enum {E1_GLOBAL=0, E1_USER, E1_READER, E1_SERVER, E1_LSERVER};
|
---|
172 | enum {E2_GLOBAL=0, E2_GROUP, E2_CAID, E2_IDENT, E2_CLASS, E2_CHID, E2_QUEUE,
|
---|
173 | E2_EA_LEN, E2_F0_LEN, E2_OFFLINE, E2_SID};
|
---|
174 |
|
---|
175 | //typedef unsigned char uchar;
|
---|
176 | //typedef unsigned long ulong;
|
---|
177 |
|
---|
178 | typedef struct s_classtab
|
---|
179 | {
|
---|
180 | uchar an;
|
---|
181 | uchar bn;
|
---|
182 | uchar aclass[31];
|
---|
183 | uchar bclass[31];
|
---|
184 | } GCC_PACK CLASSTAB;
|
---|
185 |
|
---|
186 | typedef struct s_caidtab
|
---|
187 | {
|
---|
188 | ushort caid[CS_MAXCAIDTAB];
|
---|
189 | ushort mask[CS_MAXCAIDTAB];
|
---|
190 | ushort cmap[CS_MAXCAIDTAB];
|
---|
191 | } GCC_PACK CAIDTAB;
|
---|
192 |
|
---|
193 | typedef struct s_tuntab
|
---|
194 | {
|
---|
195 | ushort bt_caidfrom[CS_MAXTUNTAB];
|
---|
196 | ushort bt_caidto[CS_MAXTUNTAB];
|
---|
197 | ushort bt_srvid[CS_MAXTUNTAB];
|
---|
198 | } GCC_PACK TUNTAB;
|
---|
199 |
|
---|
200 | typedef struct s_sidtab
|
---|
201 | {
|
---|
202 | char label[33];
|
---|
203 | ushort num_caid;
|
---|
204 | ushort num_provid;
|
---|
205 | ushort num_srvid;
|
---|
206 | ushort *caid;
|
---|
207 | ulong *provid;
|
---|
208 | ushort *srvid;
|
---|
209 | struct s_sidtab *next;
|
---|
210 | } GCC_PACK SIDTAB;
|
---|
211 |
|
---|
212 |
|
---|
213 | typedef struct s_filter
|
---|
214 | {
|
---|
215 | ushort caid;
|
---|
216 | uchar nprids;
|
---|
217 | ulong prids[CS_MAXPROV];
|
---|
218 | } GCC_PACK FILTER;
|
---|
219 |
|
---|
220 | typedef struct s_ftab
|
---|
221 | {
|
---|
222 | int nfilts;
|
---|
223 | FILTER filts[CS_MAXFILTERS];
|
---|
224 | } GCC_PACK FTAB;
|
---|
225 |
|
---|
226 | typedef struct s_port
|
---|
227 | {
|
---|
228 | int fd;
|
---|
229 | int s_port;
|
---|
230 | FTAB ftab;
|
---|
231 | } GCC_PACK PORT;
|
---|
232 |
|
---|
233 | typedef struct s_ptab
|
---|
234 | {
|
---|
235 | int nports;
|
---|
236 | PORT ports[CS_MAXPORTS];
|
---|
237 | } GCC_PACK PTAB;
|
---|
238 |
|
---|
239 | struct s_ecm
|
---|
240 | {
|
---|
241 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
242 | uchar cw[16];
|
---|
243 | ushort caid;
|
---|
244 | ulong prid;
|
---|
245 | ulong grp;
|
---|
246 | // int level;
|
---|
247 | };
|
---|
248 |
|
---|
249 | struct s_emm
|
---|
250 | {
|
---|
251 | uchar emm[CS_EMMSTORESIZE];
|
---|
252 | uchar type;
|
---|
253 | int count;
|
---|
254 | };
|
---|
255 |
|
---|
256 | struct s_module
|
---|
257 | {
|
---|
258 | //int fd;
|
---|
259 | int multi;
|
---|
260 | int type;
|
---|
261 | int watchdog;
|
---|
262 | char desc[16];
|
---|
263 | char *logtxt;
|
---|
264 | //int s_port;
|
---|
265 | in_addr_t s_ip;
|
---|
266 | void (*s_handler)();
|
---|
267 | int (*recv)();
|
---|
268 | void (*send_dcw)();
|
---|
269 | int c_multi;
|
---|
270 | int (*c_recv_chk)();
|
---|
271 | int (*c_init)();
|
---|
272 | int (*c_send_ecm)();
|
---|
273 | int (*c_init_log)();
|
---|
274 | int (*c_recv_log)();
|
---|
275 | int c_port;
|
---|
276 | PTAB *ptab;
|
---|
277 | };
|
---|
278 |
|
---|
279 | struct s_irdeto_quess
|
---|
280 | {
|
---|
281 | int b47;
|
---|
282 | ushort caid;
|
---|
283 | ushort sid;
|
---|
284 | struct s_irdeto_quess *next;
|
---|
285 | };
|
---|
286 |
|
---|
287 | struct s_client
|
---|
288 | {
|
---|
289 | pid_t pid;
|
---|
290 | in_addr_t ip;
|
---|
291 | in_port_t port;
|
---|
292 | time_t login;
|
---|
293 | time_t last;
|
---|
294 | time_t lastswitch;
|
---|
295 | time_t lastemm;
|
---|
296 | time_t lastecm;
|
---|
297 | ulong grp;
|
---|
298 | int crypted;
|
---|
299 | int dup;
|
---|
300 | int au;
|
---|
301 | int monlvl;
|
---|
302 | int dbglvl;
|
---|
303 | CAIDTAB ctab;
|
---|
304 | TUNTAB ttab;
|
---|
305 | ulong sidtabok; // positiv services
|
---|
306 | ulong sidtabno; // negative services
|
---|
307 | int typ;
|
---|
308 | int ctyp;
|
---|
309 | int stat;
|
---|
310 | int ufd;
|
---|
311 | int last_srvid;
|
---|
312 | int last_caid;
|
---|
313 | int tosleep;
|
---|
314 | char usr[32];
|
---|
315 | int udp_fd;
|
---|
316 | int fd_m2c;
|
---|
317 | struct sockaddr_in udp_sa;
|
---|
318 | int log;
|
---|
319 | int logcounter;
|
---|
320 | int cwfound;
|
---|
321 | int cwcache;
|
---|
322 | int cwnot;
|
---|
323 | uchar ucrc[4]; // needed by monitor and used by camd35
|
---|
324 | ulong pcrc; // pwd crc
|
---|
325 | AES_KEY aeskey; // needed by monitor and used by camd33, camd35
|
---|
326 | ushort ncd_msgid;
|
---|
327 | uchar ncd_skey[16];
|
---|
328 | int port_idx; // index in server ptab
|
---|
329 | int ncd_server; // newcamd server?
|
---|
330 | #ifdef CS_ANTICASC
|
---|
331 | ushort ac_idx;
|
---|
332 | ushort ac_limit;
|
---|
333 | uchar ac_penalty;
|
---|
334 | #endif
|
---|
335 | FTAB fchid;
|
---|
336 | FTAB ftab; // user [caid] and ident filter
|
---|
337 | CLASSTAB cltab;
|
---|
338 | };
|
---|
339 |
|
---|
340 | struct s_reader
|
---|
341 | {
|
---|
342 | int cs_idx;
|
---|
343 | int fd;
|
---|
344 | ulong grp;
|
---|
345 | int fallback;
|
---|
346 | int typ;
|
---|
347 | int card_system;
|
---|
348 | char label[32];
|
---|
349 | char device[128];
|
---|
350 | int detect;
|
---|
351 | int mhz;
|
---|
352 | int custom_speed;
|
---|
353 | int r_port;
|
---|
354 | char r_usr[64];
|
---|
355 | char r_pwd[64];
|
---|
356 | int r_crypted;
|
---|
357 | int l_port;
|
---|
358 | int log_port;
|
---|
359 | CAIDTAB ctab;
|
---|
360 | ulong boxid;
|
---|
361 | uchar aes_key[16];
|
---|
362 | ulong sidtabok; // positiv services
|
---|
363 | ulong sidtabno; // negative services
|
---|
364 | uchar hexserial[8];
|
---|
365 | int nprov;
|
---|
366 | uchar prid[CS_MAXPROV][8];
|
---|
367 | uchar availkeys[CS_MAXPROV][16]; // viaccess; misused in seca, if availkeys[PROV][0]=0 then expired, 1 then valid.
|
---|
368 | uchar sa[CS_MAXPROV][4]; // viaccess & seca
|
---|
369 | ushort acs; // irdeto
|
---|
370 | ushort caid[16];
|
---|
371 | uchar b_nano[256];
|
---|
372 | char pincode[5];
|
---|
373 | int logemm;
|
---|
374 | int cachemm;
|
---|
375 | int rewritemm;
|
---|
376 | int online;
|
---|
377 | int card_status;
|
---|
378 | struct s_module ph;
|
---|
379 | uchar ncd_key[16];
|
---|
380 | uchar ncd_skey[16];
|
---|
381 | int ncd_disable_server_filt;
|
---|
382 | ushort ncd_msgid;
|
---|
383 | int ncd_proto;
|
---|
384 | uchar tcp_connected;
|
---|
385 | int tcp_ito; // inactivity timeout
|
---|
386 | int tcp_rto; // reconnect timeout
|
---|
387 | time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect )
|
---|
388 | time_t last_s; // send
|
---|
389 | uchar show_cls; // number of classes subscription showed on kill -31
|
---|
390 | int maxqlen; // max queue length
|
---|
391 | int qlen; // current queue length
|
---|
392 | FTAB fchid;
|
---|
393 | FTAB ftab;
|
---|
394 | CLASSTAB cltab;
|
---|
395 | uchar gbox_pwd[4];
|
---|
396 | uchar gbox_timecode[7];
|
---|
397 | int gbox_online;
|
---|
398 | uchar gbox_vers;
|
---|
399 | uchar gbox_prem;
|
---|
400 | int gbox_fd;
|
---|
401 | struct timeb gbox_lasthello; // incoming time stamp
|
---|
402 | #ifdef CS_RDR_INIT_HIST
|
---|
403 | uchar init_history[1024];
|
---|
404 | int init_history_pos;
|
---|
405 | #endif
|
---|
406 | };
|
---|
407 |
|
---|
408 | #ifdef CS_ANTICASC
|
---|
409 |
|
---|
410 | struct s_acasc_shm {
|
---|
411 | ushort count : 15;
|
---|
412 | ushort deny : 1;
|
---|
413 | };
|
---|
414 |
|
---|
415 | struct s_acasc {
|
---|
416 | ushort stat[10];
|
---|
417 | uchar idx; // current active index in stat[]
|
---|
418 | };
|
---|
419 |
|
---|
420 | struct s_cpmap
|
---|
421 | {
|
---|
422 | ushort caid;
|
---|
423 | ulong provid;
|
---|
424 | ushort sid;
|
---|
425 | ushort chid;
|
---|
426 | ushort dwtime;
|
---|
427 | struct s_cpmap *next;
|
---|
428 | };
|
---|
429 | #endif
|
---|
430 |
|
---|
431 | struct s_auth
|
---|
432 | {
|
---|
433 | char usr[33];
|
---|
434 | char pwd[33];
|
---|
435 | int uniq;
|
---|
436 | int au;
|
---|
437 | int monlvl;
|
---|
438 | ulong grp;
|
---|
439 | int tosleep;
|
---|
440 | CAIDTAB ctab;
|
---|
441 | ulong sidtabok; // positiv services
|
---|
442 | ulong sidtabno; // negative services
|
---|
443 | FTAB fchid;
|
---|
444 | FTAB ftab; // user [caid] and ident filter
|
---|
445 | CLASSTAB cltab;
|
---|
446 | TUNTAB ttab;
|
---|
447 | #ifdef CS_ANTICASC
|
---|
448 | int ac_idx;
|
---|
449 | int ac_users; // 0 - unlimited
|
---|
450 | uchar ac_penalty; // 0 - log, >0 - fake dw
|
---|
451 | #endif
|
---|
452 | in_addr_t dynip;
|
---|
453 | uchar dyndns[64];
|
---|
454 | struct s_auth *next;
|
---|
455 | };
|
---|
456 |
|
---|
457 | struct s_srvid
|
---|
458 | {
|
---|
459 | int srvid;
|
---|
460 | char name[33];
|
---|
461 | struct s_srvid *next;
|
---|
462 | };
|
---|
463 |
|
---|
464 | struct s_ip
|
---|
465 | {
|
---|
466 | in_addr_t ip[2];
|
---|
467 | struct s_ip *next;
|
---|
468 | };
|
---|
469 |
|
---|
470 | struct s_config
|
---|
471 | {
|
---|
472 | int nice;
|
---|
473 | ulong netprio;
|
---|
474 | ulong ctimeout;
|
---|
475 | ulong ftimeout;
|
---|
476 | int cmaxidle;
|
---|
477 | int ulparent;
|
---|
478 | ulong delay;
|
---|
479 | int bindwait;
|
---|
480 | int resolvedelay;
|
---|
481 | int tosleep;
|
---|
482 | in_addr_t srvip;
|
---|
483 | char pidfile[128];
|
---|
484 | char usrfile[128];
|
---|
485 | struct s_auth *account;
|
---|
486 | struct s_srvid *srvid;
|
---|
487 | struct s_sidtab *sidtab;
|
---|
488 | int mon_port;
|
---|
489 | in_addr_t mon_srvip;
|
---|
490 | struct s_ip *mon_allowed;
|
---|
491 | int mon_aulow;
|
---|
492 | int mon_hideclient_to;
|
---|
493 | int mon_level;
|
---|
494 | int c33_port;
|
---|
495 | in_addr_t c33_srvip;
|
---|
496 | uchar c33_key[16];
|
---|
497 | int c33_crypted;
|
---|
498 | int c33_passive;
|
---|
499 | struct s_ip *c33_plain;
|
---|
500 | int c35_port;
|
---|
501 | in_addr_t c35_srvip;
|
---|
502 | PTAB c35_tcp_ptab;
|
---|
503 | in_addr_t c35_tcp_srvip;
|
---|
504 | PTAB ncd_ptab;
|
---|
505 | in_addr_t ncd_srvip;
|
---|
506 | uchar ncd_key[16];
|
---|
507 | int rad_port;
|
---|
508 | in_addr_t rad_srvip;
|
---|
509 | struct s_ip *rad_allowed;
|
---|
510 | char rad_usr[32];
|
---|
511 | char ser_device[512];
|
---|
512 | int srtimeout; // SerialReaderTimeount in millisec
|
---|
513 | int max_log_size;
|
---|
514 | int show_ecm_dw;
|
---|
515 | int waitforcards;
|
---|
516 | int preferlocalcards;
|
---|
517 | uchar gbox_pwd[8];
|
---|
518 | uchar ignorefile[512];
|
---|
519 | uchar cardfile[512];
|
---|
520 | uchar gbxShareOnl[512];
|
---|
521 | int maxdist;
|
---|
522 | int num_locals;
|
---|
523 | unsigned long locals[CS_MAXLOCALS];
|
---|
524 | //struct s_irdeto_quess *itab[0xff];
|
---|
525 | #ifdef CS_ANTICASC
|
---|
526 | char ac_enabled;
|
---|
527 | int ac_users; // num of users for account (0 - default)
|
---|
528 | int ac_stime; // time to collect AC statistics (3 min - default)
|
---|
529 | int ac_samples; // qty of samples
|
---|
530 | int ac_penalty; // 0 - write to log
|
---|
531 | int ac_fakedelay; // 100-1000 ms
|
---|
532 | int ac_denysamples;
|
---|
533 | char ac_logfile[128];
|
---|
534 | struct s_cpmap *cpmap;
|
---|
535 | #endif
|
---|
536 | // struct s_reader reader[];
|
---|
537 | };
|
---|
538 |
|
---|
539 | typedef struct ecm_request_t
|
---|
540 | {
|
---|
541 |
|
---|
542 | uchar ecm[256];
|
---|
543 | uchar cw[16];
|
---|
544 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
545 | // uchar l;
|
---|
546 | short l;
|
---|
547 | ushort caid;
|
---|
548 | ushort ocaid;
|
---|
549 | ushort srvid;
|
---|
550 | ushort chid;
|
---|
551 | ushort pid;
|
---|
552 | ushort idx;
|
---|
553 | ulong prid;
|
---|
554 | int reader[CS_MAXREADER];
|
---|
555 | int cidx; // client index
|
---|
556 | int cpti; // client pending table index
|
---|
557 | int stage; // processing stage in server module
|
---|
558 | int level; // send-level in client module
|
---|
559 | int rc;
|
---|
560 | uchar rcEx;
|
---|
561 | struct timeb tps; // incoming time stamp
|
---|
562 | uchar locals_done;
|
---|
563 | ushort gbxCWFrom;
|
---|
564 | ushort gbxFrom;
|
---|
565 | ushort gbxTo;
|
---|
566 |
|
---|
567 | uchar gbxForward[16];
|
---|
568 | int gbxRidx;
|
---|
569 | } GCC_PACK ECM_REQUEST;
|
---|
570 |
|
---|
571 | typedef struct emm_packet_t
|
---|
572 | {
|
---|
573 | uchar emm[258];
|
---|
574 | uchar l;
|
---|
575 | uchar caid[2];
|
---|
576 | uchar provid[4];
|
---|
577 | uchar hexserial[8];
|
---|
578 | uchar type;
|
---|
579 | int cidx;
|
---|
580 | } GCC_PACK EMM_PACKET;
|
---|
581 |
|
---|
582 | // oscam-simples
|
---|
583 | extern char *remote_txt(void);
|
---|
584 | extern char *trim(char *);
|
---|
585 | extern char *strtolower(char *);
|
---|
586 | extern int gethexval(char);
|
---|
587 | extern int cs_atob(uchar *, char *, int);
|
---|
588 | extern ulong cs_atoi(char *, int, int);
|
---|
589 | extern int byte_atob(char *);
|
---|
590 | extern long word_atob(char *);
|
---|
591 | extern int key_atob(char *, uchar *);
|
---|
592 | extern int key_atob4(char *, uchar *);
|
---|
593 | extern char *key_btoa(char *, uchar *);
|
---|
594 | extern char *cs_hexdump(int, uchar *, int);
|
---|
595 | extern in_addr_t cs_inet_order(in_addr_t);
|
---|
596 | extern char *cs_inet_ntoa(in_addr_t);
|
---|
597 | extern in_addr_t cs_inet_addr(char *txt);
|
---|
598 | extern ulong b2i(int, uchar *);
|
---|
599 | extern ullong b2ll(int, uchar *);
|
---|
600 | extern uchar *i2b(int, ulong);
|
---|
601 | extern ulong a2i(char *, int);
|
---|
602 | extern int boundary(int, int);
|
---|
603 | extern void cs_ftime(struct timeb *);
|
---|
604 | extern void cs_sleepms(int);
|
---|
605 | extern int bytes_available(int);
|
---|
606 | extern void cs_setpriority(int);
|
---|
607 | extern struct s_auth *find_user(char *);
|
---|
608 |
|
---|
609 | // oscam variables
|
---|
610 | extern int pfd, rfd, fd_c2m, fd_m2c, cs_idx, *c_start, cs_ptyp, cs_dblevel, cs_hw;
|
---|
611 | extern int *logidx, *loghistidx, *log_fd;
|
---|
612 | extern int is_server, *mcl;
|
---|
613 | extern uchar mbuf[1024];
|
---|
614 | extern ushort len4caid[256];
|
---|
615 | extern pid_t master_pid;
|
---|
616 | extern struct s_ecm *ecmcache;
|
---|
617 | extern struct s_client *client;
|
---|
618 | extern struct s_reader *reader;
|
---|
619 |
|
---|
620 | extern struct card_struct *Cards;
|
---|
621 | extern struct idstore_struct *idstore;
|
---|
622 | extern unsigned long *IgnoreList;
|
---|
623 |
|
---|
624 | extern struct s_config *cfg;
|
---|
625 | extern char cs_confdir[], *loghist;
|
---|
626 | extern EMM_PACKET epg;
|
---|
627 | extern struct s_module ph[CS_MAX_MOD];
|
---|
628 | extern ECM_REQUEST *ecmtask;
|
---|
629 | extern char logfile[256];
|
---|
630 | #ifdef CS_ANTICASC
|
---|
631 | extern struct s_acasc_shm *acasc;
|
---|
632 | extern FILE *fpa;
|
---|
633 | extern int use_ac_log;
|
---|
634 | #endif
|
---|
635 |
|
---|
636 |
|
---|
637 | // oscam
|
---|
638 | extern char *cs_platform(char *);
|
---|
639 | extern int recv_from_udpipe(uchar *, int);
|
---|
640 | extern char* username(int);
|
---|
641 | extern int idx_from_pid(pid_t);
|
---|
642 | extern int chk_bcaid(ECM_REQUEST *, CAIDTAB *);
|
---|
643 | extern void cs_exit(int sig);
|
---|
644 | extern int cs_fork(in_addr_t, in_port_t);
|
---|
645 | extern void wait4master(void);
|
---|
646 | extern int cs_auth_client(struct s_auth *, char*);
|
---|
647 | extern void cs_disconnect_client(void);
|
---|
648 | extern int check_ecmcache(ECM_REQUEST *, ulong);
|
---|
649 | extern int write_to_pipe(int, int, uchar *, int);
|
---|
650 | extern int read_from_pipe(int, uchar **, int);
|
---|
651 | extern int write_ecm_request(int, ECM_REQUEST *);
|
---|
652 | extern int write_ecm_answer(int, ECM_REQUEST *);
|
---|
653 | extern void log_emm_request(int);
|
---|
654 | extern ulong chk_provid(uchar *, ushort);
|
---|
655 | extern void guess_cardsystem(ECM_REQUEST *);
|
---|
656 | extern void guess_irdeto(ECM_REQUEST *);
|
---|
657 | extern void get_cw(ECM_REQUEST *);
|
---|
658 | extern void do_emm(EMM_PACKET *);
|
---|
659 | extern ECM_REQUEST *get_ecmtask(void);
|
---|
660 | extern void request_cw(ECM_REQUEST *, int, int);
|
---|
661 | extern int send_dcw(ECM_REQUEST *);
|
---|
662 | extern int process_input(uchar *, int, int);
|
---|
663 | extern int chk_srvid(ECM_REQUEST *, int);
|
---|
664 | extern int chk_sfilter(ECM_REQUEST *, PTAB*);
|
---|
665 | extern int chk_ufilters(ECM_REQUEST *);
|
---|
666 | extern int chk_rfilter(ECM_REQUEST *, struct s_reader *);
|
---|
667 | extern int chk_rsfilter(ECM_REQUEST *, int);
|
---|
668 | extern int chk_avail_reader(ECM_REQUEST *, struct s_reader *);
|
---|
669 | extern void set_signal_handler(int , int , void (*)(int));
|
---|
670 | extern void cs_log_config(void);
|
---|
671 |
|
---|
672 | #ifdef CS_ANTICASC
|
---|
673 | //extern void start_anticascader(void);
|
---|
674 | extern void init_ac(void);
|
---|
675 | extern void ac_init_stat(int);
|
---|
676 | extern int ac_init_log(char*);
|
---|
677 | extern void ac_do_stat(void);
|
---|
678 | extern void ac_init_client(struct s_auth *);
|
---|
679 | extern void ac_chk(ECM_REQUEST*, int);
|
---|
680 | #endif
|
---|
681 |
|
---|
682 | // oscam-nano
|
---|
683 | extern int chk_class(ECM_REQUEST *, CLASSTAB*, const char*, const char*);
|
---|
684 |
|
---|
685 | // oscam-config
|
---|
686 | extern int init_config(void);
|
---|
687 | extern int init_userdb(void);
|
---|
688 | extern int init_readerdb(void);
|
---|
689 | extern int init_sidtab(void);
|
---|
690 | extern int init_srvid(void);
|
---|
691 | extern int search_boxkey(ushort, ulong, char *);
|
---|
692 | extern void init_len4caid(void);
|
---|
693 | extern int init_irdeto_guess_tab(void);
|
---|
694 |
|
---|
695 | // oscam-reader
|
---|
696 | extern int ridx, logfd;
|
---|
697 | extern void cs_ri_brk(int);
|
---|
698 | extern void cs_ri_log(char *,...);
|
---|
699 | extern void start_cardreader(void);
|
---|
700 | extern void reader_card_info(void);
|
---|
701 |
|
---|
702 | // oscam-log
|
---|
703 | extern int cs_init_log(char *);
|
---|
704 | extern void cs_log(char *,...);
|
---|
705 | extern void cs_debug(char *,...);
|
---|
706 | extern void cs_ddump(uchar *, int, char *, ...);
|
---|
707 | extern void cs_close_log(void);
|
---|
708 | extern int cs_init_statistics(char *);
|
---|
709 | extern void cs_statistics(int);
|
---|
710 | extern void cs_dump(uchar *, int, char *, ...);
|
---|
711 |
|
---|
712 | // oscam-aes
|
---|
713 | extern void aes_set_key(char *);
|
---|
714 | extern void aes_encrypt_idx(int, uchar *, int);
|
---|
715 | extern void aes_decrypt(uchar *, int);
|
---|
716 | #define aes_encrypt(b, n) aes_encrypt_idx(cs_idx, b, n)
|
---|
717 |
|
---|
718 | // reader-common
|
---|
719 | extern int reader_device_init(char *, int);
|
---|
720 | extern int reader_checkhealth(void);
|
---|
721 | extern int reader_ecm(ECM_REQUEST *);
|
---|
722 | extern int reader_emm(EMM_PACKET *);
|
---|
723 |
|
---|
724 | // reader-irdeto
|
---|
725 | extern int irdeto_card_init(uchar *, int);
|
---|
726 | extern int irdeto_do_ecm(ECM_REQUEST *);
|
---|
727 | extern int irdeto_do_emm(EMM_PACKET *);
|
---|
728 | extern int irdeto_card_info(void);
|
---|
729 |
|
---|
730 | // reader-viaccess
|
---|
731 | extern int viaccess_card_init(uchar *, int);
|
---|
732 | extern int viaccess_do_ecm(ECM_REQUEST *);
|
---|
733 | extern int viaccess_do_emm(EMM_PACKET *);
|
---|
734 | extern int viaccess_card_info(void);
|
---|
735 |
|
---|
736 | // reader-videoguard
|
---|
737 | extern int videoguard_card_init(uchar *, int);
|
---|
738 | extern int videoguard_do_ecm(ECM_REQUEST *);
|
---|
739 | extern int videoguard_do_emm(EMM_PACKET *);
|
---|
740 | extern int videoguard_card_info(void);
|
---|
741 |
|
---|
742 | // reader-cryptoworks
|
---|
743 | extern int cryptoworks_card_init(uchar *, int);
|
---|
744 | extern int cryptoworks_do_ecm(ECM_REQUEST *);
|
---|
745 | extern int cryptoworks_do_emm(EMM_PACKET *);
|
---|
746 | extern int cryptoworks_card_info(void);
|
---|
747 |
|
---|
748 | // reader-seca
|
---|
749 | extern int seca_card_init(uchar *, int);
|
---|
750 | extern int seca_do_ecm(ECM_REQUEST *);
|
---|
751 | extern int seca_do_emm(EMM_PACKET *);
|
---|
752 | extern int seca_card_info(void);
|
---|
753 |
|
---|
754 | // protocol modules
|
---|
755 | extern int monitor_send_idx(int, char *);
|
---|
756 | extern void module_monitor(struct s_module *);
|
---|
757 | extern void module_camd35(struct s_module *);
|
---|
758 | extern void module_camd35_tcp(struct s_module *);
|
---|
759 | extern void module_camd33(struct s_module *);
|
---|
760 | extern void module_newcamd(struct s_module *);
|
---|
761 | extern void module_radegast(struct s_module *);
|
---|
762 | extern void module_oscam_ser(struct s_module *);
|
---|
763 | extern void module_gbox(struct s_module *);
|
---|
764 | extern struct timeval *chk_pending(struct timeb tp_ctimeout);
|
---|
765 | #endif // CS_GLOBALS
|
---|