source: trunk/globals.h@ 1808

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

Remove smargopatch as native smartreader mode is now stable

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