source: trunk/globals.h@ 1696

Last change on this file since 1696 was 1696, checked in by merek, 11 years ago

emm counting works only with webif, so we use this only for webif build

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