source: trunk/globals.h@ 1716

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

Many more ifdefs for GBOX and WebIf

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