source: trunk/globals.h@ 1826

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

Merge from UMP r1898

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 tosleep;
613 in_addr_t srvip;
614 char *pidfile;
615 char *usrfile;
616 char *cwlogdir;
617 char *logfile;
618 int disablelog;
619 int disableuserfile;
620 int usrfileflag;
621 struct s_auth *account;
622 struct s_srvid *srvid;
623 struct s_sidtab *sidtab;
624 int mon_port;
625 in_addr_t mon_srvip;
626 struct s_ip *mon_allowed;
627 int mon_aulow;
628 int mon_hideclient_to;
629 int mon_level;
630 int mon_appendchaninfo;
631#ifdef WEBIF
632 int http_port;
633 char http_user[65];
634 char http_pwd[65];
635 char http_css[128];
636 char http_tpl[128];
637 char http_script[128];
638 int http_refresh;
639 int http_hide_idle_clients;
640 struct s_ip *http_allowed;
641 int http_readonly;
642 in_addr_t http_dynip;
643 uchar http_dyndns[64];
644#endif
645 int c33_port;
646 in_addr_t c33_srvip;
647 uchar c33_key[16];
648 int c33_crypted;
649 int c33_passive;
650 struct s_ip *c33_plain;
651 int c35_port;
652 in_addr_t c35_srvip;
653 int c35_suppresscmd08;
654 PTAB c35_tcp_ptab;
655 in_addr_t c35_tcp_srvip;
656 PTAB ncd_ptab;
657 in_addr_t ncd_srvip;
658 uchar ncd_key[16];
659 int ncd_keepalive;
660 struct s_ip *ncd_allowed;
661 PTAB cc_ptab;
662 int rad_port;
663 in_addr_t rad_srvip;
664 int cc_port;
665 int cc_reshare;
666 in_addr_t cc_srvip;
667 uchar cc_version[7];
668 uchar cc_build[5];
669 struct s_ip *rad_allowed;
670 char rad_usr[32];
671 char ser_device[512];
672 ulong srtimeout; // SerialReaderTimeount in millisec
673 int max_log_size;
674 int waitforcards;
675 int preferlocalcards;
676
677#ifdef CS_WITH_GBOX
678 uchar gbox_pwd[8];
679 uchar ignorefile[128];
680 uchar cardfile[128];
681 uchar gbxShareOnl[128];
682 int maxdist;
683 int num_locals;
684 unsigned long locals[CS_MAXLOCALS];
685#endif
686
687#ifdef IRDETO_GUESSING
688 struct s_irdeto_quess *itab[0xff];
689#endif
690
691#ifdef HAVE_DVBAPI
692 int dvbapi_enabled;
693 int dvbapi_au;
694 char dvbapi_usr[33];
695 char dvbapi_boxtype[20];
696 char dvbapi_priority[64];
697 char dvbapi_ignore[64];
698#endif
699
700#ifdef CS_ANTICASC
701 char ac_enabled;
702 int ac_users; // num of users for account (0 - default)
703 int ac_stime; // time to collect AC statistics (3 min - default)
704 int ac_samples; // qty of samples
705 int ac_penalty; // 0 - write to log
706 int ac_fakedelay; // 100-1000 ms
707 int ac_denysamples;
708 char ac_logfile[128];
709 struct s_cpmap *cpmap;
710#endif
711 // struct s_reader reader[];
712};
713
714typedef struct ecm_request_t
715{
716
717 uchar ecm[256];
718 uchar cw[16];
719 uchar ecmd5[CS_ECMSTORESIZE];
720// uchar l;
721 short l;
722 ushort caid;
723 ushort ocaid;
724 ushort srvid;
725 ushort chid;
726 ushort pid;
727 ushort idx;
728 ulong prid;
729 int reader[CS_MAXREADER];
730 int cidx; // client index
731 int cpti; // client pending table index
732 int stage; // processing stage in server module
733 int level; // send-level in client module
734 int rc;
735 uchar rcEx;
736 struct timeb tps; // incoming time stamp
737 uchar locals_done;
738 int btun; // mark er as betatunneled
739
740#ifdef CS_WITH_GBOX
741 ushort gbxCWFrom;
742 ushort gbxFrom;
743 ushort gbxTo;
744 uchar gbxForward[16];
745 int gbxRidx;
746#endif
747
748} GCC_PACK ECM_REQUEST;
749
750typedef struct emm_packet_t
751{
752 uchar emm[258];
753 uchar l;
754 uchar caid[2];
755 uchar provid[4];
756 uchar hexserial[8]; //contains hexserial or SA of EMM
757 uchar type;
758 int cidx;
759} GCC_PACK EMM_PACKET;
760
761//EMM types:
762#define UNKNOWN 0
763#define UNIQUE 1
764#define SHARED 2
765#define GLOBAL 3
766
767// oscam-simples
768extern char *remote_txt(void);
769extern char *trim(char *);
770extern char *strtolower(char *);
771extern int gethexval(char);
772extern int cs_atob(uchar *, char *, int);
773extern ulong cs_atoi(char *, int, int);
774extern int byte_atob(char *);
775extern long word_atob(char *);
776extern int key_atob(char *, uchar *);
777extern int key_atob14(char *, uchar *);
778extern int key_atob_l(char *, uchar *, int);
779extern char *key_btoa(char *, uchar *);
780extern char *cs_hexdump(int, uchar *, int);
781extern in_addr_t cs_inet_order(in_addr_t);
782extern char *cs_inet_ntoa(in_addr_t);
783extern in_addr_t cs_inet_addr(char *txt);
784extern ulong b2i(int, uchar *);
785extern ullong b2ll(int, uchar *);
786extern uchar *i2b(int, ulong);
787extern ulong a2i(char *, int);
788extern int boundary(int, int);
789extern void cs_ftime(struct timeb *);
790extern void cs_sleepms(unsigned int);
791extern void cs_sleepus(unsigned int);
792extern int bytes_available(int);
793extern void cs_setpriority(int);
794extern struct s_auth *find_user(char *);
795#ifdef WEBIF
796extern int x2i(int i);
797extern void urldecode(char *s);
798extern char to_hex(char code);
799extern char *urlencode(char *str);
800extern char *char_to_hex(const unsigned char* p_array, unsigned int p_array_len, char hex2ascii[256][2]);
801extern void create_rand_str(char *dst, int size);
802#endif
803extern void long2bitchar(long value, char *result);
804extern int file_exists(const char * filename);
805extern void clear_sip(struct s_ip **sip);
806extern void clear_ptab(struct s_ptab *ptab);
807extern void clear_ftab(struct s_ftab *ftab);
808void clear_caidtab(struct s_caidtab *ctab);
809void clear_tuntab(struct s_tuntab *ttab);
810extern int safe_overwrite_with_bak(char *destfile, char *tmpfile, char *bakfile, int forceBakOverWrite);
811extern void fprintf_conf(FILE *f, int varnameWidth, const char *varname, const char *fmtstring, ...);
812extern void cs_strncpy(char * destination, const char * source, size_t num);
813
814// oscam variables
815extern int pfd, rfd, fd_c2m, fd_m2c, cs_idx, *c_start, cs_ptyp, cs_dblevel, cs_hw;
816extern int *logidx, *loghistidx, *log_fd;
817extern int is_server, *mcl;
818extern uchar mbuf[1024];
819extern ushort len4caid[256];
820extern pid_t master_pid;
821extern struct s_ecm *ecmcache;
822extern struct s_client *client;
823extern struct s_reader *reader;
824
825extern struct card_struct *Cards;
826extern struct idstore_struct *idstore;
827extern unsigned long *IgnoreList;
828
829extern struct s_config *cfg;
830extern char cs_confdir[], *loghist;
831extern struct s_module ph[CS_MAX_MOD];
832extern ECM_REQUEST *ecmtask;
833#ifdef CS_ANTICASC
834extern struct s_acasc_shm *acasc;
835extern FILE *fpa;
836extern int use_ac_log;
837#endif
838
839
840// oscam
841extern char *cs_platform(char *);
842extern int recv_from_udpipe(uchar *);
843extern char* username(int);
844extern int idx_from_pid(pid_t);
845extern int chk_bcaid(ECM_REQUEST *, CAIDTAB *);
846extern void cs_exit(int sig);
847extern int cs_fork(in_addr_t, in_port_t);
848extern void wait4master(void);
849extern int cs_auth_client(struct s_auth *, char*);
850extern void cs_disconnect_client(void);
851extern int check_ecmcache(ECM_REQUEST *, ulong);
852extern void store_logentry(char *);
853extern int write_to_pipe(int, int, uchar *, int);
854extern int read_from_pipe(int, uchar **, int);
855extern int write_ecm_request(int, ECM_REQUEST *);
856extern int write_ecm_answer(int, ECM_REQUEST *);
857extern void log_emm_request(int);
858extern ulong chk_provid(uchar *, ushort);
859extern void guess_cardsystem(ECM_REQUEST *);
860#ifdef IRDETO_GUESSING
861extern void guess_irdeto(ECM_REQUEST *);
862#endif
863extern void get_cw(ECM_REQUEST *);
864extern void do_emm(EMM_PACKET *);
865extern ECM_REQUEST *get_ecmtask(void);
866extern void request_cw(ECM_REQUEST *, int, int);
867extern int send_dcw(ECM_REQUEST *);
868extern int process_input(uchar *, int, int);
869extern int chk_srvid(ECM_REQUEST *, int);
870extern int chk_sfilter(ECM_REQUEST *, PTAB*);
871extern int chk_ufilters(ECM_REQUEST *);
872extern int chk_rfilter(ECM_REQUEST *, struct s_reader *);
873extern int chk_rsfilter(ECM_REQUEST *, int);
874extern int chk_avail_reader(ECM_REQUEST *, struct s_reader *);
875extern int matching_reader(ECM_REQUEST *, struct s_reader *);
876extern void set_signal_handler(int , int , void (*)(int));
877extern void cs_log_config(void);
878extern void cs_waitforcardinit(void);
879extern void cs_reinit_clients(void);
880extern void cs_resolve(void);
881extern void chk_dcw(int fd);
882
883#ifdef CS_ANTICASC
884//extern void start_anticascader(void);
885extern void init_ac(void);
886extern void ac_init_stat();
887extern int ac_init_log(char*);
888extern void ac_do_stat(void);
889extern void ac_init_client(struct s_auth *);
890extern void ac_chk(ECM_REQUEST*, int);
891#endif
892
893// oscam-nano
894extern int chk_class(ECM_REQUEST *, CLASSTAB*, const char*, const char*);
895
896// oscam-config
897extern int init_config(void);
898extern int init_userdb(void);
899extern int init_readerdb(void);
900extern int init_sidtab(void);
901extern int init_srvid(void);
902extern int search_boxkey(ushort, char *);
903extern void init_len4caid(void);
904#ifdef IRDETO_GUESSING
905extern int init_irdeto_guess_tab(void);
906#endif
907extern void chk_caidtab(char *caidasc, CAIDTAB *ctab);
908extern void chk_tuntab(char *tunasc, TUNTAB *ttab);
909extern void chk_services(char *labels, ulong *sidok, ulong *sidno);
910extern void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName);
911extern void chk_cltab(char *classasc, CLASSTAB *clstab);
912extern void chk_iprange(char *value, struct s_ip **base);
913extern void chk_port_tab(char *portasc, PTAB *ptab);
914#ifdef CS_ANTICASC
915extern void chk_t_ac(char *token, char *value);
916#endif
917extern void chk_t_camd33(char *token, char *value);
918extern void chk_t_camd35(char *token, char *value);
919extern void chk_t_camd35_tcp(char *token, char *value);
920extern void chk_t_newcamd(char *token, char *value);
921extern void chk_t_radegast(char *token, char *value);
922extern void chk_t_serial(char *token, char *value);
923#ifdef CS_WITH_GBOX
924extern void chk_t_gbox(char *token, char *value);
925#endif
926extern void chk_t_cccam(char *token, char *value);
927extern void chk_t_global(char *token, char *value);
928extern void chk_t_monitor(char *token, char *value);
929
930#ifdef HAVE_DVBAPI
931extern void chk_t_dvbapi(char *token, char *value);
932#endif
933
934#ifdef WEBIF
935extern void chk_t_webif(char *token, char *value);
936#endif
937
938extern void chk_account(char *token, char *value, struct s_auth *account);
939extern void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab);
940extern int write_services();
941extern int write_userdb();
942extern int write_config();
943extern char *mk_t_caidtab(CAIDTAB *ctab);
944extern char *mk_t_tuntab(TUNTAB *ttab);
945extern char *mk_t_group(ulong *grp);
946extern char *mk_t_ftab(FTAB *ftab);
947
948// oscam-reader
949extern int ridx, logfd;
950extern int reader_cmd2icc(uchar *, int);
951extern int card_write(uchar *, uchar *);
952extern void cs_ri_brk(int);
953extern void cs_ri_log(char *,...);
954extern void start_cardreader(void);
955extern void reader_card_info(void);
956extern int network_tcp_connection_open();
957extern void network_tcp_connection_close(int);
958
959// oscam-log
960extern int cs_init_log(char *);
961extern void cs_write_log(char *);
962extern void cs_log(char *,...);
963extern void cs_debug(char *,...);
964extern void cs_debug_nolf(char *,...);
965extern void cs_debug_mask(unsigned short, char *,...);
966extern void cs_ddump(uchar *, int, char *, ...);
967extern void cs_ddump_mask(unsigned short, uchar *, int, char *, ...);
968extern void cs_close_log(void);
969extern int cs_init_statistics(char *);
970extern void cs_statistics(int);
971extern void cs_dump(uchar *, int, char *, ...);
972
973// oscam-aes
974extern void aes_set_key(char *);
975extern void aes_encrypt_idx(int, uchar *, int);
976extern void aes_decrypt(uchar *, int);
977#define aes_encrypt(b, n) aes_encrypt_idx(cs_idx, b, n)
978
979// reader-common
980extern int reader_device_init(char *);
981extern int reader_checkhealth(void);
982extern void reader_post_process(void);
983extern int reader_ecm(ECM_REQUEST *);
984extern int reader_emm(EMM_PACKET *);
985int reader_get_emm_type(EMM_PACKET *ep, struct s_reader * reader);
986
987#ifdef HAVE_PCSC
988// reader-pcsc
989extern int pcsc_reader_do_api(struct s_reader *pcsc_reader, uchar *buf, uchar *cta_res, ushort *cta_lr,int l);
990extern int pcsc_activate_card(struct s_reader *pcsc_reader, uchar *atr, ushort *atr_size);
991extern int pcsc_check_card_inserted(struct s_reader *pcsc_reader);
992extern int pcsc_reader_init(struct s_reader *pcsc_reader, char *device);
993#endif
994
995// protocol modules
996extern int monitor_send_idx(int, char *);
997extern void module_monitor(struct s_module *);
998extern void module_camd35(struct s_module *);
999extern void module_camd35_tcp(struct s_module *);
1000extern void module_camd33(struct s_module *);
1001extern void module_newcamd(struct s_module *);
1002extern void module_radegast(struct s_module *);
1003extern void module_oscam_ser(struct s_module *);
1004extern void module_cccam(struct s_module *);
1005extern struct timeval *chk_pending(struct timeb tp_ctimeout);
1006#ifdef CS_WITH_GBOX
1007extern void module_gbox(struct s_module *);
1008#endif
1009#ifdef HAVE_DVBAPI
1010extern void module_dvbapi(struct s_module *);
1011#endif
1012
1013
1014// module-monitor
1015extern char *monitor_get_proto(int idx);
1016extern char *monitor_get_srvname(int srvid, int caid);
1017extern int cs_idx2ridx(int idx);
1018
1019#ifdef WEBIF
1020// oscam-http
1021extern void http_srv();
1022#endif
1023
1024#endif // CS_GLOBALS
Note: See TracBrowser for help on using the repository browser.