source: trunk/globals.h@ 1740

Last change on this file since 1740 was 1740, checked in by merek, 10 years ago

Revert last changes

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