source: trunk/globals.h@ 1710

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

Readd irdeto guessing - now selectable with -DIRDETO_GUESSING, thanks to landlord

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