source: trunk/globals.h@ 1715

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

Dont store provider id in cache because provider id was not checked for caching

File size: 26.5 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 grp;
316 //int level;
317};
318
319struct s_emm
320{
321 uchar emm[CS_EMMSTORESIZE];
322 uchar type;
323 int count;
324};
325
326struct s_module
327{
328 //int fd;
329 int multi;
330 int type;
331 int watchdog;
332 char desc[16];
333 char *logtxt;
334 //int s_port;
335 in_addr_t s_ip;
336 void (*s_handler)();
337 int (*recv)();
338 void (*send_dcw)();
339 void (*cleanup)();
340 int c_multi;
341 int (*c_recv_chk)();
342 int (*c_init)();
343 int (*c_send_ecm)();
344 int (*c_init_log)();
345 int (*c_recv_log)();
346 int c_port;
347 PTAB *ptab;
348};
349
350struct s_irdeto_quess
351{
352 int b47;
353 ushort caid;
354 ushort sid;
355 struct s_irdeto_quess *next;
356};
357
358struct s_client
359{
360 pid_t pid;
361 in_addr_t ip;
362 in_port_t port;
363 time_t login;
364 time_t last;
365 time_t lastswitch;
366 time_t lastemm;
367 time_t lastecm;
368 time_t expirationdate;
369 int c35_suppresscmd08;
370 int ncd_keepalive;
371 int disabled;
372 ulong grp;
373 int crypted;
374 int dup;
375 int au;
376 int autoau;
377 int monlvl;
378 int dbglvl;
379 CAIDTAB ctab;
380 TUNTAB ttab;
381 ulong sidtabok; // positiv services
382 ulong sidtabno; // negative services
383 int typ;
384 int ctyp;
385 int stat;
386 int ufd;
387 int last_srvid;
388 int last_caid;
389 int tosleep;
390 char usr[32];
391 int udp_fd;
392 int fd_m2c;
393 struct sockaddr_in udp_sa;
394 int log;
395 int logcounter;
396 int cwfound; // count found ECMs per client
397 int cwcache; // count ECMs from cache1/2 per client
398 int cwnot; // count not found ECMs per client
399 int cwtun; // count betatunneled ECMs per client
400 int cwignored; // count ignored ECMs per client
401 int cwtout; // count timeouted ECMs per client
402 int cwlastresptime; //last Responsetime (ms)
403 int emmok; // count EMM ok
404 int emmnok; // count EMM nok
405 int wihidden; // hidden in webinterface status
406 uchar ucrc[4]; // needed by monitor and used by camd35
407 ulong pcrc; // pwd crc
408 AES_KEY aeskey; // needed by monitor and used by camd33, camd35
409 ushort ncd_msgid;
410 uchar ncd_skey[16];
411 void *cc;
412 int port_idx; // index in server ptab
413 int ncd_server; // newcamd server?
414#ifdef CS_ANTICASC
415 ushort ac_idx;
416 ushort ac_limit;
417 uchar ac_penalty;
418#endif
419 FTAB fchid;
420 FTAB ftab; // user [caid] and ident filter
421 CLASSTAB cltab;
422};
423
424struct s_reader
425{
426 int smargopatch; //FIXME workaround for Smargo until native mode works
427 int pid;
428 int cs_idx;
429 int enable;
430 int fd;
431 ulong grp;
432 int fallback;
433 int typ;
434 int card_system;
435 char label[32];
436 char device[128];
437 int handle; //device handle
438 char pcsc_name[128];
439 int pcsc_has_card;
440 int detect;
441 int mhz; //actual clock rate of reader in 10khz steps
442 int cardmhz; //standard clock speed your card should have in 10khz steps; normally 357 but for Irdeto cards 600
443 int r_port;
444 char r_usr[64];
445 char r_pwd[64];
446 int r_crypted;
447 int l_port;
448 int log_port;
449 CAIDTAB ctab;
450 ulong boxid;
451 uchar nagra_boxkey[16]; //n3 boxkey 8byte or tiger idea key 16byte
452 int has_rsa;
453 uchar aes_key[16];
454 uchar rsa_mod[120]; //rsa modulus for nagra cards.
455 ulong sidtabok; // positiv services
456 ulong sidtabno; // negative services
457 uchar hexserial[8];
458 int nprov;
459 uchar prid[CS_MAXPROV][8];
460 uchar availkeys[CS_MAXPROV][16]; // viaccess; misused in seca, if availkeys[PROV][0]=0 then expired, 1 then valid.
461 uchar sa[CS_MAXPROV][4]; // viaccess & seca
462 ushort acs; // irdeto
463 ushort caid[16];
464 uchar b_nano[256];
465 char * emmfile;
466 char pincode[5];
467 int ucpk_valid;
468 int logemm;
469 int cachemm;
470 int rewritemm;
471 int card_status;
472 int deprecated; //if 0 ATR obeyed, if 1 default speed (9600) is chosen; for devices that cannot switch baudrate
473 struct s_module ph;
474 uchar ncd_key[16];
475 uchar ncd_skey[16];
476 int ncd_disable_server_filt;
477 ushort ncd_msgid;
478 int ncd_proto;
479 char cc_version[7]; // cccam version
480 char cc_build[5]; // cccam build number
481 int cc_maxhop; // cccam max distance
482 void *cc; // ptr to cccam internal data struct
483 uchar tcp_connected;
484 int tcp_ito; // inactivity timeout
485 int tcp_rto; // reconnect timeout
486 time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect )
487 time_t last_s; // send
488 uchar show_cls; // number of classes subscription showed on kill -31
489 int maxqlen; // max queue length
490 int qlen; // current queue length
491 FTAB fchid;
492 FTAB ftab;
493 CLASSTAB cltab;
494 uchar gbox_pwd[4];
495 uchar gbox_timecode[7];
496 int gbox_online;
497 uchar gbox_vers;
498 uchar gbox_prem;
499 int gbox_fd;
500 int loadbalanced;
501 struct timeb gbox_lasthello; // incoming time stamp
502#ifdef CS_RDR_INIT_HIST
503 uchar init_history[4096];
504 int init_history_pos;
505#endif
506 int msg_idx;
507#ifdef WEBIF
508 int emmwritten; //count written EMM
509 int emmskipped; //count skipped EMM
510 int emmerror; //count error EMM
511 int emmblocked; //count blocked EMM
512#endif
513#ifdef HAVE_PCSC
514 SCARDCONTEXT hContext;
515 SCARDHANDLE hCard;
516 DWORD dwActiveProtocol;
517#endif
518#if defined(LIBUSB)
519 unsigned char g_read_buffer[4096];
520 unsigned int g_read_buffer_size;
521 pthread_mutex_t g_read_mutex;
522 pthread_mutex_t g_usb_mutex;
523 struct usb_device *smartreader_usb_dev;
524 pthread_t rt;
525 unsigned char modem_status;
526 SR_CONFIG sr_config;
527#endif
528};
529
530#ifdef CS_ANTICASC
531
532struct s_acasc_shm {
533 ushort ac_count : 15;
534 ushort ac_deny : 1;
535};
536
537struct s_acasc {
538 ushort stat[10];
539 uchar idx; // current active index in stat[]
540};
541
542struct s_cpmap
543{
544 ushort caid;
545 ulong provid;
546 ushort sid;
547 ushort chid;
548 ushort dwtime;
549 struct s_cpmap *next;
550};
551#endif
552
553struct s_auth
554{
555 char usr[33];
556 char pwd[33];
557 int uniq;
558 int au;
559 int autoau;
560 int monlvl;
561 ulong grp;
562 int tosleep;
563 CAIDTAB ctab;
564 ulong sidtabok; // positiv services
565 ulong sidtabno; // negative services
566 FTAB fchid;
567 FTAB ftab; // user [caid] and ident filter
568 CLASSTAB cltab;
569 TUNTAB ttab;
570#ifdef CS_ANTICASC
571 int ac_idx;
572 int ac_users; // 0 - unlimited
573 uchar ac_penalty; // 0 - log, >0 - fake dw
574#endif
575 in_addr_t dynip;
576 uchar dyndns[64];
577 time_t expirationdate;
578 int c35_suppresscmd08;
579 int ncd_keepalive;
580 int disabled;
581 struct s_auth *next;
582};
583
584struct s_srvid
585{
586 int srvid;
587 int ncaid;
588 int caid[10];
589 char prov[33];
590 char name[33];
591 char type[33];
592 char desc[33];
593 struct s_srvid *next;
594};
595
596struct s_ip
597{
598 in_addr_t ip[2];
599 struct s_ip *next;
600};
601
602struct s_config
603{
604 int nice;
605 int debuglvl;
606 ulong netprio;
607 ulong ctimeout;
608 ulong ftimeout;
609 ulong cmaxidle;
610 int ulparent;
611 ulong delay;
612 int bindwait;
613 int resolvedelay;
614 int tosleep;
615 in_addr_t srvip;
616 char *pidfile;
617 char *usrfile;
618 char *cwlogdir;
619 char *logfile;
620 int disablelog;
621 int usrfileflag;
622 struct s_auth *account;
623 struct s_srvid *srvid;
624 struct s_sidtab *sidtab;
625 int mon_port;
626 in_addr_t mon_srvip;
627 struct s_ip *mon_allowed;
628 int mon_aulow;
629 int mon_hideclient_to;
630 int mon_level;
631#ifdef WEBIF
632 int http_port;
633 char http_user[65];
634 char http_pwd[65];
635 char http_css[128];
636 char http_tpl[128];
637 char http_script[128];
638 int http_refresh;
639 int http_hide_idle_clients;
640 struct s_ip *http_allowed;
641#endif
642 int c33_port;
643 in_addr_t c33_srvip;
644 uchar c33_key[16];
645 int c33_crypted;
646 int c33_passive;
647 struct s_ip *c33_plain;
648 int c35_port;
649 in_addr_t c35_srvip;
650 int c35_suppresscmd08;
651 PTAB c35_tcp_ptab;
652 in_addr_t c35_tcp_srvip;
653 PTAB ncd_ptab;
654 in_addr_t ncd_srvip;
655 uchar ncd_key[16];
656 int ncd_keepalive;
657 struct s_ip *ncd_allowed;
658 PTAB cc_ptab;
659 int rad_port;
660 in_addr_t rad_srvip;
661 int cc_port;
662 int cc_reshare;
663 in_addr_t cc_srvip;
664 uchar cc_version[7];
665 uchar cc_build[5];
666 struct s_ip *rad_allowed;
667 char rad_usr[32];
668 char ser_device[512];
669 ulong srtimeout; // SerialReaderTimeount in millisec
670 int max_log_size;
671 int waitforcards;
672 int preferlocalcards;
673#ifdef CS_WITH_GBOX
674 uchar gbox_pwd[8];
675 uchar ignorefile[128];
676 uchar cardfile[128];
677 uchar gbxShareOnl[128];
678 int maxdist;
679 int num_locals;
680 unsigned long locals[CS_MAXLOCALS];
681#endif
682#ifdef IRDETO_GUESSING
683 struct s_irdeto_quess *itab[0xff];
684#endif
685#ifdef HAVE_DVBAPI
686 int dvbapi_enabled;
687 int dvbapi_au;
688 char dvbapi_usr[33];
689 char dvbapi_boxtype[20];
690 char dvbapi_priority[64];
691 char dvbapi_ignore[64];
692#endif
693#ifdef CS_ANTICASC
694 char ac_enabled;
695 int ac_users; // num of users for account (0 - default)
696 int ac_stime; // time to collect AC statistics (3 min - default)
697 int ac_samples; // qty of samples
698 int ac_penalty; // 0 - write to log
699 int ac_fakedelay; // 100-1000 ms
700 int ac_denysamples;
701 char ac_logfile[128];
702 struct s_cpmap *cpmap;
703#endif
704 // struct s_reader reader[];
705};
706
707typedef struct ecm_request_t
708{
709
710 uchar ecm[256];
711 uchar cw[16];
712 uchar ecmd5[CS_ECMSTORESIZE];
713// uchar l;
714 short l;
715 ushort caid;
716 ushort ocaid;
717 ushort srvid;
718 ushort chid;
719 ushort pid;
720 ushort idx;
721 ulong prid;
722 int reader[CS_MAXREADER];
723 int cidx; // client index
724 int cpti; // client pending table index
725 int stage; // processing stage in server module
726 int level; // send-level in client module
727 int rc;
728 uchar rcEx;
729 struct timeb tps; // incoming time stamp
730 uchar locals_done;
731 ushort gbxCWFrom;
732 ushort gbxFrom;
733 ushort gbxTo;
734
735 uchar gbxForward[16];
736 int gbxRidx;
737} GCC_PACK ECM_REQUEST;
738
739typedef struct emm_packet_t
740{
741 uchar emm[258];
742 uchar l;
743 uchar caid[2];
744 uchar provid[4];
745 uchar hexserial[8];
746 uchar type;
747 int cidx;
748} GCC_PACK EMM_PACKET;
749
750// oscam-simples
751extern char *remote_txt(void);
752extern char *trim(char *);
753extern char *strtolower(char *);
754extern int gethexval(char);
755extern int cs_atob(uchar *, char *, int);
756extern ulong cs_atoi(char *, int, int);
757extern int byte_atob(char *);
758extern long word_atob(char *);
759extern int key_atob(char *, uchar *);
760extern int key_atob14(char *, uchar *);
761extern int key_atob_l(char *, uchar *, int);
762extern char *key_btoa(char *, uchar *);
763extern char *cs_hexdump(int, uchar *, int);
764extern in_addr_t cs_inet_order(in_addr_t);
765extern char *cs_inet_ntoa(in_addr_t);
766extern in_addr_t cs_inet_addr(char *txt);
767extern ulong b2i(int, uchar *);
768extern ullong b2ll(int, uchar *);
769extern uchar *i2b(int, ulong);
770extern ulong a2i(char *, int);
771extern int boundary(int, int);
772extern void cs_ftime(struct timeb *);
773extern void cs_sleepms(unsigned int);
774extern int bytes_available(int);
775extern void cs_setpriority(int);
776extern struct s_auth *find_user(char *);
777#ifdef WEBIF
778extern int x2i(int i);
779extern void urldecode(char *s);
780extern char to_hex(char code);
781extern char *urlencode(char *str);
782extern char *char_to_hex(const unsigned char* p_array, unsigned int p_array_len, char hex2ascii[256][2]);
783extern void create_rand_str(char *dst, int size);
784#endif
785extern void long2bitchar(long value, char *result);
786extern int file_exists(const char * filename);
787extern void clear_sip(struct s_ip **sip);
788extern void clear_ptab(struct s_ptab *ptab);
789extern void clear_ftab(struct s_ftab *ftab);
790void clear_caidtab(struct s_caidtab *ctab);
791void clear_tuntab(struct s_tuntab *ttab);
792extern int safe_overwrite_with_bak(char *destfile, char *tmpfile, char *bakfile, int forceBakOverWrite);
793extern void fprintf_conf(FILE *f, int varnameWidth, const char *varname, const char *fmtstring, ...);
794extern void cs_strncpy(char * destination, const char * source, size_t num);
795
796// oscam variables
797extern int pfd, rfd, fd_c2m, fd_m2c, cs_idx, *c_start, cs_ptyp, cs_dblevel, cs_hw;
798extern int *logidx, *loghistidx, *log_fd;
799extern int is_server, *mcl;
800extern uchar mbuf[1024];
801extern ushort len4caid[256];
802extern pid_t master_pid;
803extern struct s_ecm *ecmcache;
804extern struct s_client *client;
805extern struct s_reader *reader;
806
807extern struct card_struct *Cards;
808extern struct idstore_struct *idstore;
809extern unsigned long *IgnoreList;
810
811extern struct s_config *cfg;
812extern char cs_confdir[], *loghist;
813extern EMM_PACKET epg;
814extern struct s_module ph[CS_MAX_MOD];
815extern ECM_REQUEST *ecmtask;
816#ifdef CS_ANTICASC
817extern struct s_acasc_shm *acasc;
818extern FILE *fpa;
819extern int use_ac_log;
820#endif
821
822
823// oscam
824extern char *cs_platform(char *);
825extern int recv_from_udpipe(uchar *);
826extern char* username(int);
827extern int idx_from_pid(pid_t);
828extern int chk_bcaid(ECM_REQUEST *, CAIDTAB *);
829extern void cs_exit(int sig);
830extern int cs_fork(in_addr_t, in_port_t);
831extern void wait4master(void);
832extern int cs_auth_client(struct s_auth *, char*);
833extern void cs_disconnect_client(void);
834extern int check_ecmcache(ECM_REQUEST *, ulong);
835extern void store_logentry(char *);
836extern int write_to_pipe(int, int, uchar *, int);
837extern int read_from_pipe(int, uchar **, int);
838extern int write_ecm_request(int, ECM_REQUEST *);
839extern int write_ecm_answer(int, ECM_REQUEST *);
840extern void log_emm_request(int);
841extern ulong chk_provid(uchar *, ushort);
842extern void guess_cardsystem(ECM_REQUEST *);
843#ifdef IRDETO_GUESSING
844extern void guess_irdeto(ECM_REQUEST *);
845#endif
846extern void get_cw(ECM_REQUEST *);
847extern void do_emm(EMM_PACKET *);
848extern ECM_REQUEST *get_ecmtask(void);
849extern void request_cw(ECM_REQUEST *, int, int);
850extern int send_dcw(ECM_REQUEST *);
851extern int process_input(uchar *, int, int);
852extern int chk_srvid(ECM_REQUEST *, int);
853extern int chk_sfilter(ECM_REQUEST *, PTAB*);
854extern int chk_ufilters(ECM_REQUEST *);
855extern int chk_rfilter(ECM_REQUEST *, struct s_reader *);
856extern int chk_rsfilter(ECM_REQUEST *, int);
857extern int chk_avail_reader(ECM_REQUEST *, struct s_reader *);
858extern int matching_reader(ECM_REQUEST *, struct s_reader *);
859extern void set_signal_handler(int , int , void (*)(int));
860extern void cs_log_config(void);
861extern void cs_reinit_clients(void);
862extern void cs_resolve(void);
863extern void chk_dcw(int fd);
864
865#ifdef CS_ANTICASC
866//extern void start_anticascader(void);
867extern void init_ac(void);
868extern void ac_init_stat();
869extern int ac_init_log(char*);
870extern void ac_do_stat(void);
871extern void ac_init_client(struct s_auth *);
872extern void ac_chk(ECM_REQUEST*, int);
873#endif
874
875// oscam-nano
876extern int chk_class(ECM_REQUEST *, CLASSTAB*, const char*, const char*);
877
878// oscam-config
879extern int init_config(void);
880extern int init_userdb(void);
881extern int init_readerdb(void);
882extern int init_sidtab(void);
883extern int init_srvid(void);
884extern int search_boxkey(ushort, char *);
885extern void init_len4caid(void);
886#ifdef IRDETO_GUESSING
887extern int init_irdeto_guess_tab(void);
888#endif
889extern void chk_caidtab(char *caidasc, CAIDTAB *ctab);
890extern void chk_tuntab(char *tunasc, TUNTAB *ttab);
891extern void chk_services(char *labels, ulong *sidok, ulong *sidno);
892extern void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName);
893extern void chk_cltab(char *classasc, CLASSTAB *clstab);
894extern void chk_iprange(char *value, struct s_ip **base);
895extern void chk_port_tab(char *portasc, PTAB *ptab);
896#ifdef CS_ANTICASC
897extern void chk_t_ac(char *token, char *value);
898#endif
899extern void chk_t_camd33(char *token, char *value);
900extern void chk_t_camd35(char *token, char *value);
901extern void chk_t_camd35_tcp(char *token, char *value);
902extern void chk_t_newcamd(char *token, char *value);
903extern void chk_t_radegast(char *token, char *value);
904extern void chk_t_serial(char *token, char *value);
905extern void chk_t_gbox(char *token, char *value);
906extern void chk_t_cccam(char *token, char *value);
907extern void chk_t_global(char *token, char *value);
908extern void chk_t_monitor(char *token, char *value);
909
910#ifdef HAVE_DVBAPI
911extern void chk_t_dvbapi(char *token, char *value);
912#endif
913
914#ifdef WEBIF
915extern void chk_t_webif(char *token, char *value);
916#endif
917
918extern void chk_account(char *token, char *value, struct s_auth *account);
919extern void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab);
920extern int write_services();
921extern int write_userdb();
922extern int write_config();
923extern char *mk_t_caidtab(CAIDTAB *ctab);
924extern char *mk_t_tuntab(TUNTAB *ttab);
925extern char *mk_t_group(ulong *grp);
926extern char *mk_t_ftab(FTAB *ftab);
927
928// oscam-reader
929extern int ridx, logfd;
930extern int reader_cmd2icc(uchar *, int);
931extern int card_write(uchar *, uchar *);
932extern void cs_ri_brk(int);
933extern void cs_ri_log(char *,...);
934extern void start_cardreader(void);
935extern void reader_card_info(void);
936extern int network_tcp_connection_open();
937extern void network_tcp_connection_close(int);
938
939// oscam-log
940extern int cs_init_log(char *);
941extern void cs_write_log(char *);
942extern void cs_log(char *,...);
943extern void cs_debug(char *,...);
944extern void cs_debug_nolf(char *,...);
945extern void cs_debug_mask(unsigned short, char *,...);
946extern void cs_ddump(uchar *, int, char *, ...);
947extern void cs_ddump_mask(unsigned short, uchar *, int, char *, ...);
948extern void cs_close_log(void);
949extern int cs_init_statistics(char *);
950extern void cs_statistics(int);
951extern void cs_dump(uchar *, int, char *, ...);
952
953// oscam-aes
954extern void aes_set_key(char *);
955extern void aes_encrypt_idx(int, uchar *, int);
956extern void aes_decrypt(uchar *, int);
957#define aes_encrypt(b, n) aes_encrypt_idx(cs_idx, b, n)
958
959// reader-common
960extern int reader_device_init(char *);
961extern int reader_checkhealth(void);
962extern void reader_post_process(void);
963extern int reader_ecm(ECM_REQUEST *);
964extern int reader_emm(EMM_PACKET *);
965
966#ifdef HAVE_PCSC
967// reader-pcsc
968extern int pcsc_reader_do_api(struct s_reader *pcsc_reader, uchar *buf, uchar *cta_res, ushort *cta_lr,int l);
969extern int pcsc_activate_card(struct s_reader *pcsc_reader, uchar *atr, ushort *atr_size);
970extern int pcsc_check_card_inserted(struct s_reader *pcsc_reader);
971extern int pcsc_reader_init(struct s_reader *pcsc_reader, char *device);
972#endif
973
974// protocol modules
975extern int monitor_send_idx(int, char *);
976extern void module_monitor(struct s_module *);
977extern void module_camd35(struct s_module *);
978extern void module_camd35_tcp(struct s_module *);
979extern void module_camd33(struct s_module *);
980extern void module_newcamd(struct s_module *);
981extern void module_radegast(struct s_module *);
982extern void module_oscam_ser(struct s_module *);
983extern void module_gbox(struct s_module *);
984extern void module_cccam(struct s_module *);
985#ifdef HAVE_DVBAPI
986extern void module_dvbapi(struct s_module *);
987#endif
988extern struct timeval *chk_pending(struct timeb tp_ctimeout);
989
990// module-monitor
991extern char *monitor_get_proto(int idx);
992extern char *monitor_get_srvname(int srvid, int caid);
993extern int cs_idx2ridx(int idx);
994
995#ifdef WEBIF
996// oscam-http
997extern void http_srv();
998#endif
999
1000#endif // CS_GLOBALS
Note: See TracBrowser for help on using the repository browser.