source: trunk/globals.h@ 1788

Last change on this file since 1788 was 1788, checked in by landlord, 10 years ago

Some small 'clean ups'.

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