source: trunk/globals.h@ 1708

Last change on this file since 1708 was 1708, checked in by merek, 11 years ago
  • Remove deprecated irdeto_guessing code
  • Show config warnings also for Anticascading, Gbox when using config directives without support in binary
File size: 26.3 KB
Line 
1#define _GNU_SOURCE //prevents "implicit" warning for asprintf
2#include <stdlib.h>
3#include <stdio.h>
4#include <assert.h>
5#include <fcntl.h>
6#include <sys/ioctl.h>
7#include <sys/poll.h>
8#include <ctype.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <sys/shm.h>
12#include <sys/wait.h>
13#include <unistd.h>
14#include <sys/mman.h>
15#include <stdarg.h>
16#include <time.h>
17#include <sys/timeb.h>
18#include <limits.h>
19
20#include <sys/socket.h>
21#include <netinet/in.h>
22#include <arpa/inet.h>
23#include <netdb.h>
24#include <string.h>
25#include <signal.h>
26#include <errno.h>
27
28#include <pthread.h>
29
30#ifndef CS_GLOBALS
31#define CS_GLOBALS
32#define CS_VERSION "0.99.4svn"
33
34#if defined(__GNUC__)
35# define GCC_PACK __attribute__((packed))
36#else
37# define GCC_PACK
38#endif
39
40#define call(arg) \
41 if (arg) { \
42 cs_debug_mask(D_TRACE, "ERROR, function call %s returns error.",#arg); \
43 return ERROR; \
44 }
45
46#include "oscam-config.h"
47#ifndef USE_CMAKE
48# include "oscam-ostype.h"
49#endif
50#include "oscam-types.h"
51#include "cscrypt/cscrypt.h"
52
53#ifdef HAVE_PCSC
54 #include <PCSC/pcsclite.h>
55 #ifdef OS_MACOSX
56 #include <PCSC/wintypes.h>
57 #else
58 #include <PCSC/reader.h>
59 #endif
60#endif
61
62#if defined(LIBUSB)
63#include <libusb-1.0/libusb.h>
64#include "csctapi/smartreader_types.h"
65#endif
66
67#ifndef CS_CONFDIR
68#define CS_CONFDIR "/usr/local/etc"
69#endif
70#ifndef CS_MMAPFILE
71#define CS_MMAPFILE "/tmp/oscam.mem"
72#endif
73#ifndef CS_LOGFILE
74#define CS_LOGFILE "/var/log/oscam.log"
75#endif
76#define CS_QLEN 128 // size of request queue
77#define CS_MAXQLEN 128 // size of request queue for cardreader
78#define CS_MAXCAIDTAB 32 // max. caid-defs/user
79#define CS_MAXTUNTAB 16 // max. betatunnel mappings
80#define CS_MAXPROV 32
81#define CS_MAXPORTS 32 // max server ports
82#define CS_MAXFILTERS 16
83
84#define CS_MAXCARDS 4096
85#define CS_MAXIGNORE 1024
86#define CS_MAXLOCALS 16
87#define CS_ECMSTORESIZE 16 // use MD5()
88#define CS_EMMSTORESIZE 270
89#define CS_CLIENT_TIMEOUT 5000
90#define CS_CLIENT_MAXIDLE 120
91#define CS_BIND_TIMEOUT 120
92#define CS_DELAY 0
93#define CS_RESOLVE_DELAY 30
94#define CS_MAXLOGHIST 30
95#define CS_LOGHISTSIZE 160 // 32+128: username + logline
96
97#ifdef OLD_DEFS
98#ifdef CS_EMBEDDED
99#define CS_MAXPENDING 32
100#define CS_ECMCACHESIZE 32
101#define CS_EMMCACHESIZE 64
102#define CS_MAXPID 32
103#define CS_MAXREADER 8
104#else
105#define CS_MAXPENDING 128
106#define CS_ECMCACHESIZE 128
107#define CS_EMMCACHESIZE 256
108#define CS_MAXPID 128
109#define CS_MAXREADER 64
110#endif
111#endif
112
113#ifdef CS_EMBEDDED
114#define CS_MAXPID 32
115#define CS_MAXREADER (CS_MAXPID>>1)
116#define CS_MAXPENDING CS_MAXPID
117#define CS_ECMCACHESIZE CS_MAXPID
118#define CS_EMMCACHESIZE (CS_MAXPID<<1)
119#else
120#define CS_MAXPID 512
121#define CS_MAXREADER (CS_MAXPID>>2)
122#define CS_MAXPENDING (CS_MAXPID<<1)
123#define CS_ECMCACHESIZE CS_MAXPID
124#define CS_EMMCACHESIZE (CS_MAXPID<<1)
125#endif
126
127#define CS_RDR_INIT_HIST
128#define D_TRACE 1 // Generate very detailed error/trace messages per routine
129#define D_ATR 2 // Debug ATR parsing, dump of ecm, emm, cw
130#define D_READER 4 // Debug Reader/Proxy Process
131#define D_CLIENT 8 // Debug Client Process
132#define D_IFD 16 // Debug IFD+protocol
133#define D_DEVICE 32 // Debug Reader I/O
134#define D_ALL_DUMP 63 // dumps all
135
136#define R_DB2COM1 0x1 // Reader Dbox2 @ com1
137#define R_DB2COM2 0x2 // Reader Dbox2 @ com1
138#define R_MOUSE 0x3 // Reader smartcard mouse
139/////////////////// phoenix readers which need baudrate setting and timings need to be guarded by OSCam: BEFORE R_MOUSE
140#define R_INTERNAL 0x4 // Reader smartcard intern
141/////////////////// internal readers (Dreambox, Coolstream, IPBox) are all R_INTERNAL, they are determined compile-time
142/////////////////// readers that do not reed baudrate setting and timings are guarded by reader itself (large buffer built in): AFTER R_SMART
143#define R_SMART 0x5 // Smartreader+
144#define R_PCSC 0x6 // PCSC
145/////////////////// proxy readers after R_CS378X
146#define R_CAMD35 0x10 // Reader cascading camd 3.5x
147#define R_CAMD33 0x11 // Reader cascading camd 3.3x
148#define R_NEWCAMD 0x12 // Reader cascading newcamd
149#define R_RADEGAST 0x13 // Reader cascading radegast
150#define R_CS378X 0x14 // Reader cascading camd 3.5x TCP
151/////////////////// peer to peer proxy readers after R_CCCAM
152#define R_GBOX 0x20 // Reader cascading gbox
153#define R_CCCAM 0x25 // Reader cascading cccam
154#define R_SERIAL 0x80 // Reader serial
155#define R_IS_NETWORK 0x70
156#define R_IS_CASCADING 0xF0
157
158
159#define CS_MAX_MOD 12
160#define MOD_CONN_TCP 1
161#define MOD_CONN_UDP 2
162#define MOD_CONN_NET 3
163#define MOD_CONN_SERIAL 4
164
165#ifdef CS_CORE
166char *PIP_ID_TXT[] = { "ECM", "EMM", "LOG", "CIN", "HUP", NULL };
167char *RDR_CD_TXT[] = { "cd", "dsr", "cts", "ring", "none",
168#ifdef USE_GPIO
169 "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", //felix: changed so that gpio can be used
170#endif
171 NULL };
172#else
173extern char *PIP_ID_TXT[];
174extern char *RDR_CD_TXT[];
175#endif
176
177#define PIP_ID_ECM 0
178#define PIP_ID_EMM 1
179#define PIP_ID_LOG 2
180#define PIP_ID_CIN 3 // CARD_INFO
181#define PIP_ID_HUP 4
182#define PIP_ID_MAX PIP_ID_HUP
183#define PIP_ID_DCW 5
184
185#define PIP_ID_ERR (-1)
186#define PIP_ID_DIR (-2)
187#define PIP_ID_NUL (-3)
188
189#define cdiff *c_start
190
191#define NCD_AUTO 0
192#define NCD_524 1
193#define NCD_525 2
194
195#define CS_ANTICASC
196
197// moved from reader-common.h
198#define NO_CARD 0
199#define CARD_NEED_INIT 1
200#define CARD_INSERTED 2
201#define CARD_FAILURE 3
202
203enum {E1_GLOBAL=0, E1_USER, E1_READER, E1_SERVER, E1_LSERVER};
204enum {E2_GLOBAL=0, E2_GROUP, E2_CAID, E2_IDENT, E2_CLASS, E2_CHID, E2_QUEUE,
205 E2_EA_LEN, E2_F0_LEN, E2_OFFLINE, E2_SID};
206
207//typedef unsigned char uchar;
208//typedef unsigned long ulong;
209
210typedef unsigned char uint8;
211typedef unsigned short uint16;
212typedef unsigned int uint32;
213typedef unsigned long long uint64;
214
215// constants
216#define CTA_RES_LEN 512
217
218typedef struct s_classtab
219{
220 uchar an;
221 uchar bn;
222 uchar aclass[31];
223 uchar bclass[31];
224} GCC_PACK CLASSTAB;
225
226typedef struct s_caidtab
227{
228 ushort caid[CS_MAXCAIDTAB];
229 ushort mask[CS_MAXCAIDTAB];
230 ushort cmap[CS_MAXCAIDTAB];
231} GCC_PACK CAIDTAB;
232
233typedef struct s_tuntab
234{
235 ushort bt_caidfrom[CS_MAXTUNTAB];
236 ushort bt_caidto[CS_MAXTUNTAB];
237 ushort bt_srvid[CS_MAXTUNTAB];
238} GCC_PACK TUNTAB;
239
240typedef struct s_sidtab
241{
242 char label[33];
243 ushort num_caid;
244 ushort num_provid;
245 ushort num_srvid;
246 ushort *caid;
247 ulong *provid;
248 ushort *srvid;
249 struct s_sidtab *next;
250} GCC_PACK SIDTAB;
251
252
253typedef struct s_filter
254{
255 ushort caid;
256 uchar nprids;
257 ulong prids[CS_MAXPROV];
258} GCC_PACK FILTER;
259
260typedef struct s_ftab
261{
262 int nfilts;
263 FILTER filts[CS_MAXFILTERS];
264} GCC_PACK FTAB;
265
266typedef struct s_port
267{
268 int fd;
269 int s_port;
270 FTAB ftab;
271} GCC_PACK PORT;
272
273typedef struct s_ptab
274{
275 int nports;
276 PORT ports[CS_MAXPORTS];
277} GCC_PACK PTAB;
278
279#if defined(LIBUSB)
280typedef struct {
281 int F;
282 float D;
283 int fs;
284 int N;
285 int T;
286 int inv;
287 int parity;
288 int irdeto;
289 int running;
290 libusb_device *usb_dev;
291 libusb_device_handle *usb_dev_handle;
292 enum smartreader_chip_type type;
293 int in_ep; // 0x01
294 int out_ep; // 0x82
295 int index;
296 /** usb read timeout */
297 int usb_read_timeout;
298 /** usb write timeout */
299 int usb_write_timeout;
300 unsigned int writebuffer_chunksize;
301 unsigned char bitbang_enabled;
302 int baudrate;
303 int interface; // 0 or 1
304 /** maximum packet size. Needed for filtering modem status bytes every n packets. */
305 unsigned int max_packet_size;
306} SR_CONFIG;
307#endif
308
309
310struct s_ecm
311{
312 uchar ecmd5[CS_ECMSTORESIZE];
313 uchar cw[16];
314 ushort caid;
315 ulong prid;
316 ulong grp;
317// int level;
318};
319
320struct s_emm
321{
322 uchar emm[CS_EMMSTORESIZE];
323 uchar type;
324 int count;
325};
326
327struct s_module
328{
329 //int fd;
330 int multi;
331 int type;
332 int watchdog;
333 char desc[16];
334 char *logtxt;
335 //int s_port;
336 in_addr_t s_ip;
337 void (*s_handler)();
338 int (*recv)();
339 void (*send_dcw)();
340 void (*cleanup)();
341 int c_multi;
342 int (*c_recv_chk)();
343 int (*c_init)();
344 int (*c_send_ecm)();
345 int (*c_init_log)();
346 int (*c_recv_log)();
347 int c_port;
348 PTAB *ptab;
349};
350
351struct s_irdeto_quess
352{
353 int b47;
354 ushort caid;
355 ushort sid;
356 struct s_irdeto_quess *next;
357};
358
359struct s_client
360{
361 pid_t pid;
362 in_addr_t ip;
363 in_port_t port;
364 time_t login;
365 time_t last;
366 time_t lastswitch;
367 time_t lastemm;
368 time_t lastecm;
369 time_t expirationdate;
370 int c35_suppresscmd08;
371 int ncd_keepalive;
372 int disabled;
373 ulong grp;
374 int crypted;
375 int dup;
376 int au;
377 int autoau;
378 int monlvl;
379 int dbglvl;
380 CAIDTAB ctab;
381 TUNTAB ttab;
382 ulong sidtabok; // positiv services
383 ulong sidtabno; // negative services
384 int typ;
385 int ctyp;
386 int stat;
387 int ufd;
388 int last_srvid;
389 int last_caid;
390 int tosleep;
391 char usr[32];
392 int udp_fd;
393 int fd_m2c;
394 struct sockaddr_in udp_sa;
395 int log;
396 int logcounter;
397 int cwfound; // count found ECMs per client
398 int cwcache; // count ECMs from cache1/2 per client
399 int cwnot; // count not found ECMs per client
400 int cwtun; // count betatunneled ECMs per client
401 int cwignored; // count ignored ECMs per client
402 int cwtout; // count timeouted ECMs per client
403 int cwlastresptime; //last Responsetime (ms)
404 int emmok; // count EMM ok
405 int emmnok; // count EMM nok
406 int wihidden; // hidden in webinterface status
407 uchar ucrc[4]; // needed by monitor and used by camd35
408 ulong pcrc; // pwd crc
409 AES_KEY aeskey; // needed by monitor and used by camd33, camd35
410 ushort ncd_msgid;
411 uchar ncd_skey[16];
412 void *cc;
413 int port_idx; // index in server ptab
414 int ncd_server; // newcamd server?
415#ifdef CS_ANTICASC
416 ushort ac_idx;
417 ushort ac_limit;
418 uchar ac_penalty;
419#endif
420 FTAB fchid;
421 FTAB ftab; // user [caid] and ident filter
422 CLASSTAB cltab;
423};
424
425struct s_reader
426{
427 int smargopatch; //FIXME workaround for Smargo until native mode works
428 int pid;
429 int cs_idx;
430 int enable;
431 int fd;
432 ulong grp;
433 int fallback;
434 int typ;
435 int card_system;
436 char label[32];
437 char device[128];
438 int handle; //device handle
439 char pcsc_name[128];
440 int pcsc_has_card;
441 int detect;
442 int mhz; //actual clock rate of reader in 10khz steps
443 int cardmhz; //standard clock speed your card should have in 10khz steps; normally 357 but for Irdeto cards 600
444 int r_port;
445 char r_usr[64];
446 char r_pwd[64];
447 int r_crypted;
448 int l_port;
449 int log_port;
450 CAIDTAB ctab;
451 ulong boxid;
452 uchar nagra_boxkey[16]; //n3 boxkey 8byte or tiger idea key 16byte
453 int has_rsa;
454 uchar aes_key[16];
455 uchar rsa_mod[120]; //rsa modulus for nagra cards.
456 ulong sidtabok; // positiv services
457 ulong sidtabno; // negative services
458 uchar hexserial[8];
459 int nprov;
460 uchar prid[CS_MAXPROV][8];
461 uchar availkeys[CS_MAXPROV][16]; // viaccess; misused in seca, if availkeys[PROV][0]=0 then expired, 1 then valid.
462 uchar sa[CS_MAXPROV][4]; // viaccess & seca
463 ushort acs; // irdeto
464 ushort caid[16];
465 uchar b_nano[256];
466 char * emmfile;
467 char pincode[5];
468 int ucpk_valid;
469 int logemm;
470 int cachemm;
471 int rewritemm;
472 int card_status;
473 int deprecated; //if 0 ATR obeyed, if 1 default speed (9600) is chosen; for devices that cannot switch baudrate
474 struct s_module ph;
475 uchar ncd_key[16];
476 uchar ncd_skey[16];
477 int ncd_disable_server_filt;
478 ushort ncd_msgid;
479 int ncd_proto;
480 char cc_version[7]; // cccam version
481 char cc_build[5]; // cccam build number
482 int cc_maxhop; // cccam max distance
483 void *cc; // ptr to cccam internal data struct
484 uchar tcp_connected;
485 int tcp_ito; // inactivity timeout
486 int tcp_rto; // reconnect timeout
487 time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect )
488 time_t last_s; // send
489 uchar show_cls; // number of classes subscription showed on kill -31
490 int maxqlen; // max queue length
491 int qlen; // current queue length
492 FTAB fchid;
493 FTAB ftab;
494 CLASSTAB cltab;
495 uchar gbox_pwd[4];
496 uchar gbox_timecode[7];
497 int gbox_online;
498 uchar gbox_vers;
499 uchar gbox_prem;
500 int gbox_fd;
501 int loadbalanced;
502 struct timeb gbox_lasthello; // incoming time stamp
503#ifdef CS_RDR_INIT_HIST
504 uchar init_history[4096];
505 int init_history_pos;
506#endif
507 int msg_idx;
508#ifdef WEBIF
509 int emmwritten; //count written EMM
510 int emmskipped; //count skipped EMM
511 int emmerror; //count error EMM
512 int emmblocked; //count blocked EMM
513#endif
514#ifdef HAVE_PCSC
515 SCARDCONTEXT hContext;
516 SCARDHANDLE hCard;
517 DWORD dwActiveProtocol;
518#endif
519#if defined(LIBUSB)
520 unsigned char g_read_buffer[4096];
521 unsigned int g_read_buffer_size;
522 pthread_mutex_t g_read_mutex;
523 pthread_mutex_t g_usb_mutex;
524 struct usb_device *smartreader_usb_dev;
525 pthread_t rt;
526 unsigned char modem_status;
527 SR_CONFIG sr_config;
528#endif
529};
530
531#ifdef CS_ANTICASC
532
533struct s_acasc_shm {
534 ushort ac_count : 15;
535 ushort ac_deny : 1;
536};
537
538struct s_acasc {
539 ushort stat[10];
540 uchar idx; // current active index in stat[]
541};
542
543struct s_cpmap
544{
545 ushort caid;
546 ulong provid;
547 ushort sid;
548 ushort chid;
549 ushort dwtime;
550 struct s_cpmap *next;
551};
552#endif
553
554struct s_auth
555{
556 char usr[33];
557 char pwd[33];
558 int uniq;
559 int au;
560 int autoau;
561 int monlvl;
562 ulong grp;
563 int tosleep;
564 CAIDTAB ctab;
565 ulong sidtabok; // positiv services
566 ulong sidtabno; // negative services
567 FTAB fchid;
568 FTAB ftab; // user [caid] and ident filter
569 CLASSTAB cltab;
570 TUNTAB ttab;
571#ifdef CS_ANTICASC
572 int ac_idx;
573 int ac_users; // 0 - unlimited
574 uchar ac_penalty; // 0 - log, >0 - fake dw
575#endif
576 in_addr_t dynip;
577 uchar dyndns[64];
578 time_t expirationdate;
579 int c35_suppresscmd08;
580 int ncd_keepalive;
581 int disabled;
582 struct s_auth *next;
583};
584
585struct s_srvid
586{
587 int srvid;
588 int ncaid;
589 int caid[10];
590 char prov[33];
591 char name[33];
592 char type[33];
593 char desc[33];
594 struct s_srvid *next;
595};
596
597struct s_ip
598{
599 in_addr_t ip[2];
600 struct s_ip *next;
601};
602
603struct s_config
604{
605 int nice;
606 int debuglvl;
607 ulong netprio;
608 ulong ctimeout;
609 ulong ftimeout;
610 ulong cmaxidle;
611 int ulparent;
612 ulong delay;
613 int bindwait;
614 int resolvedelay;
615 int tosleep;
616 in_addr_t srvip;
617 char *pidfile;
618 char *usrfile;
619 char *cwlogdir;
620 char *logfile;
621 int disablelog;
622 int usrfileflag;
623 struct s_auth *account;
624 struct s_srvid *srvid;
625 struct s_sidtab *sidtab;
626 int mon_port;
627 in_addr_t mon_srvip;
628 struct s_ip *mon_allowed;
629 int mon_aulow;
630 int mon_hideclient_to;
631 int mon_level;
632#ifdef WEBIF
633 int http_port;
634 char http_user[65];
635 char http_pwd[65];
636 char http_css[128];
637 char http_tpl[128];
638 char http_script[128];
639 int http_refresh;
640 int http_hide_idle_clients;
641 struct s_ip *http_allowed;
642#endif
643 int c33_port;
644 in_addr_t c33_srvip;
645 uchar c33_key[16];
646 int c33_crypted;
647 int c33_passive;
648 struct s_ip *c33_plain;
649 int c35_port;
650 in_addr_t c35_srvip;
651 int c35_suppresscmd08;
652 PTAB c35_tcp_ptab;
653 in_addr_t c35_tcp_srvip;
654 PTAB ncd_ptab;
655 in_addr_t ncd_srvip;
656 uchar ncd_key[16];
657 int ncd_keepalive;
658 struct s_ip *ncd_allowed;
659 PTAB cc_ptab;
660 int rad_port;
661 in_addr_t rad_srvip;
662 int cc_port;
663 int cc_reshare;
664 in_addr_t cc_srvip;
665 uchar cc_version[7];
666 uchar cc_build[5];
667 struct s_ip *rad_allowed;
668 char rad_usr[32];
669 char ser_device[512];
670 ulong srtimeout; // SerialReaderTimeount in millisec
671 int max_log_size;
672 int waitforcards;
673 int preferlocalcards;
674#ifdef CS_WITH_GBOX
675 uchar gbox_pwd[8];
676 uchar ignorefile[128];
677 uchar cardfile[128];
678 uchar gbxShareOnl[128];
679 int maxdist;
680 int num_locals;
681 unsigned long locals[CS_MAXLOCALS];
682#endif
683 //struct s_irdeto_quess *itab[0xff];
684#ifdef HAVE_DVBAPI
685 int dvbapi_enabled;
686 int dvbapi_au;
687 char dvbapi_usr[33];
688 char dvbapi_boxtype[20];
689 char dvbapi_priority[64];
690 char dvbapi_ignore[64];
691#endif
692#ifdef CS_ANTICASC
693 char ac_enabled;
694 int ac_users; // num of users for account (0 - default)
695 int ac_stime; // time to collect AC statistics (3 min - default)
696 int ac_samples; // qty of samples
697 int ac_penalty; // 0 - write to log
698 int ac_fakedelay; // 100-1000 ms
699 int ac_denysamples;
700 char ac_logfile[128];
701 struct s_cpmap *cpmap;
702#endif
703 // struct s_reader reader[];
704};
705
706typedef struct ecm_request_t
707{
708
709 uchar ecm[256];
710 uchar cw[16];
711 uchar ecmd5[CS_ECMSTORESIZE];
712// uchar l;
713 short l;
714 ushort caid;
715 ushort ocaid;
716 ushort srvid;
717 ushort chid;
718 ushort pid;
719 ushort idx;
720 ulong prid;
721 int reader[CS_MAXREADER];
722 int cidx; // client index
723 int cpti; // client pending table index
724 int stage; // processing stage in server module
725 int level; // send-level in client module
726 int rc;
727 uchar rcEx;
728 struct timeb tps; // incoming time stamp
729 uchar locals_done;
730 ushort gbxCWFrom;
731 ushort gbxFrom;
732 ushort gbxTo;
733
734 uchar gbxForward[16];
735 int gbxRidx;
736} GCC_PACK ECM_REQUEST;
737
738typedef struct emm_packet_t
739{
740 uchar emm[258];
741 uchar l;
742 uchar caid[2];
743 uchar provid[4];
744 uchar hexserial[8];
745 uchar type;
746 int cidx;
747} GCC_PACK EMM_PACKET;
748
749// oscam-simples
750extern char *remote_txt(void);
751extern char *trim(char *);
752extern char *strtolower(char *);
753extern int gethexval(char);
754extern int cs_atob(uchar *, char *, int);
755extern ulong cs_atoi(char *, int, int);
756extern int byte_atob(char *);
757extern long word_atob(char *);
758extern int key_atob(char *, uchar *);
759extern int key_atob14(char *, uchar *);
760extern int key_atob_l(char *, uchar *, int);
761extern char *key_btoa(char *, uchar *);
762extern char *cs_hexdump(int, uchar *, int);
763extern in_addr_t cs_inet_order(in_addr_t);
764extern char *cs_inet_ntoa(in_addr_t);
765extern in_addr_t cs_inet_addr(char *txt);
766extern ulong b2i(int, uchar *);
767extern ullong b2ll(int, uchar *);
768extern uchar *i2b(int, ulong);
769extern ulong a2i(char *, int);
770extern int boundary(int, int);
771extern void cs_ftime(struct timeb *);
772extern void cs_sleepms(unsigned int);
773extern int bytes_available(int);
774extern void cs_setpriority(int);
775extern struct s_auth *find_user(char *);
776#ifdef WEBIF
777extern int x2i(int i);
778extern void urldecode(char *s);
779extern char to_hex(char code);
780extern char *urlencode(char *str);
781extern char *char_to_hex(const unsigned char* p_array, unsigned int p_array_len, char hex2ascii[256][2]);
782extern void create_rand_str(char *dst, int size);
783#endif
784extern void long2bitchar(long value, char *result);
785extern int file_exists(const char * filename);
786extern void clear_sip(struct s_ip **sip);
787extern void clear_ptab(struct s_ptab *ptab);
788extern void clear_ftab(struct s_ftab *ftab);
789void clear_caidtab(struct s_caidtab *ctab);
790void clear_tuntab(struct s_tuntab *ttab);
791extern int safe_overwrite_with_bak(char *destfile, char *tmpfile, char *bakfile, int forceBakOverWrite);
792extern void fprintf_conf(FILE *f, int varnameWidth, const char *varname, const char *fmtstring, ...);
793extern void cs_strncpy(char * destination, const char * source, size_t num);
794
795// oscam variables
796extern int pfd, rfd, fd_c2m, fd_m2c, cs_idx, *c_start, cs_ptyp, cs_dblevel, cs_hw;
797extern int *logidx, *loghistidx, *log_fd;
798extern int is_server, *mcl;
799extern uchar mbuf[1024];
800extern ushort len4caid[256];
801extern pid_t master_pid;
802extern struct s_ecm *ecmcache;
803extern struct s_client *client;
804extern struct s_reader *reader;
805
806extern struct card_struct *Cards;
807extern struct idstore_struct *idstore;
808extern unsigned long *IgnoreList;
809
810extern struct s_config *cfg;
811extern char cs_confdir[], *loghist;
812extern EMM_PACKET epg;
813extern struct s_module ph[CS_MAX_MOD];
814extern ECM_REQUEST *ecmtask;
815#ifdef CS_ANTICASC
816extern struct s_acasc_shm *acasc;
817extern FILE *fpa;
818extern int use_ac_log;
819#endif
820
821
822// oscam
823extern char *cs_platform(char *);
824extern int recv_from_udpipe(uchar *);
825extern char* username(int);
826extern int idx_from_pid(pid_t);
827extern int chk_bcaid(ECM_REQUEST *, CAIDTAB *);
828extern void cs_exit(int sig);
829extern int cs_fork(in_addr_t, in_port_t);
830extern void wait4master(void);
831extern int cs_auth_client(struct s_auth *, char*);
832extern void cs_disconnect_client(void);
833extern int check_ecmcache(ECM_REQUEST *, ulong);
834extern void store_logentry(char *);
835extern int write_to_pipe(int, int, uchar *, int);
836extern int read_from_pipe(int, uchar **, int);
837extern int write_ecm_request(int, ECM_REQUEST *);
838extern int write_ecm_answer(int, ECM_REQUEST *);
839extern void log_emm_request(int);
840extern ulong chk_provid(uchar *, ushort);
841extern void guess_cardsystem(ECM_REQUEST *);
842extern void get_cw(ECM_REQUEST *);
843extern void do_emm(EMM_PACKET *);
844extern ECM_REQUEST *get_ecmtask(void);
845extern void request_cw(ECM_REQUEST *, int, int);
846extern int send_dcw(ECM_REQUEST *);
847extern int process_input(uchar *, int, int);
848extern int chk_srvid(ECM_REQUEST *, int);
849extern int chk_sfilter(ECM_REQUEST *, PTAB*);
850extern int chk_ufilters(ECM_REQUEST *);
851extern int chk_rfilter(ECM_REQUEST *, struct s_reader *);
852extern int chk_rsfilter(ECM_REQUEST *, int);
853extern int chk_avail_reader(ECM_REQUEST *, struct s_reader *);
854extern int matching_reader(ECM_REQUEST *, struct s_reader *);
855extern void set_signal_handler(int , int , void (*)(int));
856extern void cs_log_config(void);
857extern void cs_reinit_clients(void);
858extern void cs_resolve(void);
859extern void chk_dcw(int fd);
860
861#ifdef CS_ANTICASC
862//extern void start_anticascader(void);
863extern void init_ac(void);
864extern void ac_init_stat();
865extern int ac_init_log(char*);
866extern void ac_do_stat(void);
867extern void ac_init_client(struct s_auth *);
868extern void ac_chk(ECM_REQUEST*, int);
869#endif
870
871// oscam-nano
872extern int chk_class(ECM_REQUEST *, CLASSTAB*, const char*, const char*);
873
874// oscam-config
875extern int init_config(void);
876extern int init_userdb(void);
877extern int init_readerdb(void);
878extern int init_sidtab(void);
879extern int init_srvid(void);
880extern int search_boxkey(ushort, char *);
881extern void init_len4caid(void);
882extern void chk_caidtab(char *caidasc, CAIDTAB *ctab);
883extern void chk_tuntab(char *tunasc, TUNTAB *ttab);
884extern void chk_services(char *labels, ulong *sidok, ulong *sidno);
885extern void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName);
886extern void chk_cltab(char *classasc, CLASSTAB *clstab);
887extern void chk_iprange(char *value, struct s_ip **base);
888extern void chk_port_tab(char *portasc, PTAB *ptab);
889#ifdef CS_ANTICASC
890extern void chk_t_ac(char *token, char *value);
891#endif
892extern void chk_t_camd33(char *token, char *value);
893extern void chk_t_camd35(char *token, char *value);
894extern void chk_t_camd35_tcp(char *token, char *value);
895extern void chk_t_newcamd(char *token, char *value);
896extern void chk_t_radegast(char *token, char *value);
897extern void chk_t_serial(char *token, char *value);
898extern void chk_t_gbox(char *token, char *value);
899extern void chk_t_cccam(char *token, char *value);
900extern void chk_t_global(char *token, char *value);
901extern void chk_t_monitor(char *token, char *value);
902
903#ifdef HAVE_DVBAPI
904extern void chk_t_dvbapi(char *token, char *value);
905#endif
906
907#ifdef WEBIF
908extern void chk_t_webif(char *token, char *value);
909#endif
910
911extern void chk_account(char *token, char *value, struct s_auth *account);
912extern void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab);
913extern int write_services();
914extern int write_userdb();
915extern int write_config();
916extern char *mk_t_caidtab(CAIDTAB *ctab);
917extern char *mk_t_tuntab(TUNTAB *ttab);
918extern char *mk_t_group(ulong *grp);
919extern char *mk_t_ftab(FTAB *ftab);
920
921// oscam-reader
922extern int ridx, logfd;
923extern int reader_cmd2icc(uchar *, int);
924extern int card_write(uchar *, uchar *);
925extern void cs_ri_brk(int);
926extern void cs_ri_log(char *,...);
927extern void start_cardreader(void);
928extern void reader_card_info(void);
929extern int network_tcp_connection_open();
930extern void network_tcp_connection_close(int);
931
932// oscam-log
933extern int cs_init_log(char *);
934extern void cs_write_log(char *);
935extern void cs_log(char *,...);
936extern void cs_debug(char *,...);
937extern void cs_debug_nolf(char *,...);
938extern void cs_debug_mask(unsigned short, char *,...);
939extern void cs_ddump(uchar *, int, char *, ...);
940extern void cs_ddump_mask(unsigned short, uchar *, int, char *, ...);
941extern void cs_close_log(void);
942extern int cs_init_statistics(char *);
943extern void cs_statistics(int);
944extern void cs_dump(uchar *, int, char *, ...);
945
946// oscam-aes
947extern void aes_set_key(char *);
948extern void aes_encrypt_idx(int, uchar *, int);
949extern void aes_decrypt(uchar *, int);
950#define aes_encrypt(b, n) aes_encrypt_idx(cs_idx, b, n)
951
952// reader-common
953extern int reader_device_init(char *);
954extern int reader_checkhealth(void);
955extern void reader_post_process(void);
956extern int reader_ecm(ECM_REQUEST *);
957extern int reader_emm(EMM_PACKET *);
958
959#ifdef HAVE_PCSC
960// reader-pcsc
961extern int pcsc_reader_do_api(struct s_reader *pcsc_reader, uchar *buf, uchar *cta_res, ushort *cta_lr,int l);
962extern int pcsc_activate_card(struct s_reader *pcsc_reader, uchar *atr, ushort *atr_size);
963extern int pcsc_check_card_inserted(struct s_reader *pcsc_reader);
964extern int pcsc_reader_init(struct s_reader *pcsc_reader, char *device);
965#endif
966
967// protocol modules
968extern int monitor_send_idx(int, char *);
969extern void module_monitor(struct s_module *);
970extern void module_camd35(struct s_module *);
971extern void module_camd35_tcp(struct s_module *);
972extern void module_camd33(struct s_module *);
973extern void module_newcamd(struct s_module *);
974extern void module_radegast(struct s_module *);
975extern void module_oscam_ser(struct s_module *);
976extern void module_gbox(struct s_module *);
977extern void module_cccam(struct s_module *);
978#ifdef HAVE_DVBAPI
979extern void module_dvbapi(struct s_module *);
980#endif
981extern struct timeval *chk_pending(struct timeb tp_ctimeout);
982
983// module-monitor
984extern char *monitor_get_proto(int idx);
985extern char *monitor_get_srvname(int srvid, int caid);
986extern int cs_idx2ridx(int idx);
987
988#ifdef WEBIF
989// oscam-http
990extern void http_srv();
991#endif
992
993#endif // CS_GLOBALS
Note: See TracBrowser for help on using the repository browser.