source: trunk/globals.h@ 1718

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

And again ifdefs for gbox

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