source: trunk/globals.h@ 1838

Last change on this file since 1838 was 1838, checked in by alno, 10 years ago

new parameter "clientdyndns=0|1" avoids running the clientresolve thread. If you have already have defined hostname for your clients the parameter must be 1, otherwise no auth is possible for this clients

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