source: trunk/globals.h@ 4019

Last change on this file since 4019 was 4019, checked in by dingo35, 10 years ago

ifd_smartreader.c: reverse 4015 seems to give problems on different platforms

File size: 43.5 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#include <pwd.h>
20
21#include <sys/socket.h>
22#include <netinet/in.h>
23#include <arpa/inet.h>
24#include <netdb.h>
25#include <string.h>
26#include <signal.h>
27#include <errno.h>
28
29#include <pthread.h>
30
31#include "module-obj-llist.h"
32#include "module-datastruct-llist.h"
33
34//for reader-nagra variables in s_reader:
35#include "cscrypt/idea.h"
36
37#ifndef CS_GLOBALS
38#define CS_GLOBALS
39#define CS_VERSION "1.00-unstable_svn"
40#ifndef CS_SVN_VERSION
41# define CS_SVN_VERSION "test"
42#endif
43
44#if defined(__GNUC__) && !defined(__arm__)
45# define GCC_PACK __attribute__((packed))
46#else
47# define GCC_PACK
48#endif
49
50#include "oscam-config.h"
51
52#ifdef UNUSED
53#elif defined(__GNUC__)
54# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
55#elif defined(__LCLINT__)
56# define UNUSED(x) /*@unused@*/ x
57#else
58# define UNUSED(x) x
59#endif
60
61#ifdef WITH_DEBUG
62# define call(arg) \
63 if (arg) { \
64 cs_debug_mask(D_TRACE, "ERROR, function call %s returns error.",#arg); \
65 return ERROR; \
66 }
67# define D_USE(x) x
68#else
69# define call(arg) arg
70# if defined(__GNUC__)
71# define D_USE(x) D_USE_ ## x __attribute__((unused))
72# elif defined(__LCLINT__)
73# define D_USE(x) /*@debug use only@*/ x
74# else
75# define D_USE(x) x
76# endif
77#endif
78
79#ifndef USE_CMAKE
80# include "oscam-ostype.h"
81#endif
82#include "oscam-types.h"
83#include "cscrypt/cscrypt.h"
84
85#ifdef HAVE_PCSC
86 #ifdef OS_CYGWIN32
87 #define __reserved
88 #define __nullnullterminated
89 #include <specstrings.h>
90 #include "cygwin/WinSCard.h"
91 #else
92 #include <PCSC/pcsclite.h>
93 #ifdef OS_MACOSX
94 #include <PCSC/wintypes.h>
95 #else
96 #include <PCSC/reader.h>
97 #endif
98 #endif
99#endif
100
101#if defined(LIBUSB)
102#include <libusb-1.0/libusb.h>
103#include "csctapi/smartreader_types.h"
104#endif
105
106#ifndef CS_CONFDIR
107#define CS_CONFDIR "/usr/local/etc"
108#endif
109#ifndef CS_MMAPFILE
110#define CS_MMAPFILE "/tmp/oscam.mem"
111#endif
112#ifndef CS_LOGFILE
113#define CS_LOGFILE "/var/log/oscam.log"
114#endif
115#define CS_QLEN 128 // size of request queue
116#define CS_MAXQLEN 128 // size of request queue for cardreader
117#define CS_MAXCAIDTAB 32 // max. caid-defs/user
118#define CS_MAXTUNTAB 16 // max. betatunnel mappings
119#define CS_MAXPROV 32
120#define CS_MAXPORTS 32 // max server ports
121#define CS_MAXFILTERS 16
122
123#define CS_MAXCARDS 4096
124#define CS_MAXIGNORE 1024
125#define CS_MAXLOCALS 16
126#define CS_ECMSTORESIZE 16 // use MD5()
127#define CS_EMMSTORESIZE 16 // use MD5()
128#define CS_CLIENT_TIMEOUT 5000
129#define CS_CLIENT_MAXIDLE 120
130#define CS_BIND_TIMEOUT 120
131#define CS_DELAY 0
132#define CS_RESOLVE_DELAY 30
133#define CS_MAXLOGHIST 30
134#define CS_LOGHISTSIZE 193 // 32+128+33: username + logline + channelname
135#define CS_MAXREADERCAID 16
136
137#ifndef PTHREAD_STACK_MIN
138#define PTHREAD_STACK_MIN 64000
139#endif
140
141#ifdef CS_EMBEDDED
142//#define CS_MAXPID 32
143//#define CS_MAXREADER (CS_MAXPID>>1)
144#define CS_MAXREADER 16
145//#define CS_MAXPENDING CS_MAXPID
146#define CS_MAXPENDING 16
147#define PTHREAD_STACK_SIZE PTHREAD_STACK_MIN+8000
148#else
149//#define CS_MAXPID 512
150//#define CS_MAXREADER (CS_MAXPID<<2)
151#define CS_MAXREADER 256
152//#define CS_MAXPENDING (CS_MAXPID<<1)
153#define CS_MAXPENDING 32
154#define PTHREAD_STACK_SIZE PTHREAD_STACK_MIN+10000
155#endif
156
157#define CS_EMMCACHESIZE 64 //nr of EMMs that each client will cache; cache is per client, so memory-expensive...
158
159#define D_TRACE 1 // Generate very detailed error/trace messages per routine
160#define D_ATR 2 // Debug ATR parsing, dump of ecm, cw
161#define D_READER 4 // Debug Reader/Proxy Process
162#define D_CLIENT 8 // Debug Client Process
163#define D_IFD 16 // Debug IFD+protocol
164#define D_DEVICE 32 // Debug Reader I/O
165#define D_EMM 64 // Dumps EMM
166#define D_FUT 128 // Reserved for future use
167#define D_ALL_DUMP 255 // dumps all
168
169#define R_DB2COM1 0x1 // Reader Dbox2 @ com1
170#define R_DB2COM2 0x2 // Reader Dbox2 @ com1
171#define R_SC8in1 0x3 // Reader smartcard mouse
172#define R_MP35 0x4 // AD-Teknik Multiprogrammer 3.5 and 3.6 (only usb tested)
173#define R_MOUSE 0x5 // Reader smartcard mouse
174/////////////////// phoenix readers which need baudrate setting and timings need to be guarded by OSCam: BEFORE R_MOUSE
175#define R_INTERNAL 0x6 // Reader smartcard intern
176/////////////////// internal readers (Dreambox, Coolstream, IPBox) are all R_INTERNAL, they are determined compile-time
177/////////////////// readers that do not reed baudrate setting and timings are guarded by reader itself (large buffer built in): AFTER R_SMART
178#define R_SMART 0x7 // Smartreader+
179#define R_PCSC 0x8 // PCSC
180/////////////////// proxy readers after R_CS378X
181#define R_CAMD35 0x20 // Reader cascading camd 3.5x
182#define R_CAMD33 0x21 // Reader cascading camd 3.3x
183#define R_NEWCAMD 0x22 // Reader cascading newcamd
184#define R_RADEGAST 0x23 // Reader cascading radegast
185#define R_CS378X 0x24 // Reader cascading camd 3.5x TCP
186#define R_CONSTCW 0x25 // Reader for Constant CW
187/////////////////// peer to peer proxy readers after R_CCCAM
188#ifdef CS_WITH_GBOX
189#define R_GBOX 0x30 // Reader cascading gbox
190#endif
191#define R_CCCAM 0x35 // Reader cascading cccam
192#define R_SERIAL 0x80 // Reader serial
193#define R_IS_NETWORK 0x60
194#define R_IS_CASCADING 0xE0
195
196
197#define CS_MAX_MOD 20
198#define MOD_CONN_TCP 1
199#define MOD_CONN_UDP 2
200#define MOD_CONN_NET 3
201#define MOD_CONN_SERIAL 4
202#define MOD_NO_CONN 8
203
204#define MOD_CARDSYSTEM 16
205#define MOD_ADDON 32
206
207
208#ifdef HAVE_DVBAPI
209#define BOXTYPE_DREAMBOX 1
210#define BOXTYPE_DUCKBOX 2
211#define BOXTYPE_UFS910 3
212#define BOXTYPE_DBOX2 4
213#define BOXTYPE_IPBOX 5
214#define BOXTYPE_IPBOX_PMT 6
215#define BOXTYPE_DM7000 7
216#define BOXTYPE_QBOXHD 8
217#define BOXTYPES 8
218extern const char *boxdesc[];
219#endif
220
221#ifdef CS_CORE
222char *PIP_ID_TXT[] = { "ECM", "EMM", "CIN", "KCL", "UDP", NULL };
223char *RDR_CD_TXT[] = { "cd", "dsr", "cts", "ring", "none",
224#ifdef USE_GPIO
225 "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", //felix: changed so that gpio can be used
226#endif
227 NULL };
228#else
229extern char *PIP_ID_TXT[];
230extern char *RDR_CD_TXT[];
231#endif
232
233#define PIP_ID_ECM 0
234#define PIP_ID_EMM 1
235#define PIP_ID_CIN 2 // CARD_INFO
236#define PIP_ID_KCL 3 // Schlocke: Kill all Clients (no param)
237#define PIP_ID_UDP 4
238#define PIP_ID_MAX PIP_ID_UDP
239
240
241#define PIP_ID_ERR (-1)
242#define PIP_ID_DIR (-2)
243#define PIP_ID_NUL (-3)
244
245#define cdiff *c_start
246
247#define NCD_AUTO 0
248#define NCD_524 1
249#define NCD_525 2
250
251// moved from reader-common.h
252#define NO_CARD 0
253#define CARD_NEED_INIT 1
254#define CARD_INSERTED 2
255#define CARD_FAILURE 3
256
257// moved from stats
258#define DEFAULT_REOPEN_SECONDS 900
259#define DEFAULT_MIN_ECM_COUNT 5
260#define DEFAULT_MAX_ECM_COUNT 500
261#define DEFAULT_NBEST 1
262#define DEFAULT_NFB 1
263
264enum {E1_GLOBAL=0, E1_USER, E1_READER, E1_SERVER, E1_LSERVER};
265enum {E2_GLOBAL=0, E2_GROUP, E2_CAID, E2_IDENT, E2_CLASS, E2_CHID, E2_QUEUE,
266 E2_EA_LEN, E2_F0_LEN, E2_OFFLINE, E2_SID};
267
268typedef unsigned char uint8;
269typedef unsigned short uint16;
270typedef unsigned int uint32;
271typedef unsigned long long uint64;
272
273int server_pid; //alno: PID of server - set while startup
274
275// constants
276#define CTA_RES_LEN 512
277
278#ifdef CS_LED
279#define LED1A 0
280#define LED1B 1
281#define LED2 2
282#define LED3 3
283#define LED_OFF 0
284#define LED_ON 1
285#define LED_BLINK_ON 2
286#define LED_BLINK_OFF 3
287#define LED_DEFAULT 10
288extern void cs_switch_led(int led, int action);
289#endif
290
291#ifdef QBOXHD_LED
292typedef struct {
293 unsigned short H; // range 0-359
294 unsigned char S; // range 0-99
295 unsigned char V; // range 0-99
296} qboxhd_led_color_struct;
297typedef struct {
298 unsigned char red; // first 5 bit used (&0x1F)
299 unsigned char green; // first 5 bit used (&0x1F)
300 unsigned char blue; // first 5 bit used (&0x1F)
301} qboxhdmini_led_color_struct;
302
303extern void qboxhd_led_blink(int color, int duration);
304
305#define QBOXHD_LED_DEVICE "/dev/sw0"
306#define QBOXHD_SET_LED_ALL_PANEL_COLOR _IO(0xBC, 13) // payload = 3byte [H][S][V]
307#define QBOXHD_LED_COLOR_RED 359 // only H value, S and V values are always == 99
308#define QBOXHD_LED_COLOR_GREEN 120
309#define QBOXHD_LED_COLOR_BLUE 230
310#define QBOXHD_LED_COLOR_YELLOW 55
311#define QBOXHD_LED_COLOR_MAGENTA 290
312
313#define QBOXHDMINI_LED_DEVICE "/dev/lpc_0"
314#define QBOXHDMINI_IOSET_RGB _IOWR('L', 6, qboxhdmini_led_color_struct)
315#define QBOXHDMINI_LED_COLOR_RED 0x1F0000 // 3 bytes RGB , 5 bit used for each color
316#define QBOXHDMINI_LED_COLOR_GREEN 0x001F00
317#define QBOXHDMINI_LED_COLOR_BLUE 0x00001F
318#define QBOXHDMINI_LED_COLOR_YELLOW 0x1F1F00
319#define QBOXHDMINI_LED_COLOR_MAGENTA 0x1F001F
320
321#define QBOXHD_LED_COLOR_OFF -1 // all colors H,S,V and/or R,G,B == 0,0,0
322
323#define QBOXHD_LED_BLINK_FAST 100 // blink milliseconds
324#define QBOXHD_LED_BLINK_MEDIUM 200
325#define QBOXHD_LED_BLINK_SLOW 400
326
327#endif //QBOXHD_LED
328
329#define MAX_ATR_LEN 33 // max. ATR length
330#define MAX_HIST 15 // max. number of historical characters
331
332#define MAX_SIDBITS 64 // max services
333#define SIDTABBITS uint64 // 64bit type for services, if a system does not support this type,
334 // please use a define and define it as uint32 / MAX_SIDBITS 32
335
336#define BAN_UNKNOWN 1 //failban mask for anonymous/ unknown contact
337#define BAN_DISABLED 2 //failban mask for disabled user
338#define BAN_SLEEPING 4 //failban mask for sleeping user
339
340
341//checking if (X) free(X) unneccessary since freeing a null pointer doesnt do anything
342#define NULLFREE(X) {if (X) {free(X); X = NULL; }}
343
344typedef struct s_classtab
345{
346 uchar an;
347 uchar bn;
348 uchar aclass[31];
349 uchar bclass[31];
350} GCC_PACK CLASSTAB;
351
352typedef struct s_caidtab
353{
354 ushort caid[CS_MAXCAIDTAB];
355 ushort mask[CS_MAXCAIDTAB];
356 ushort cmap[CS_MAXCAIDTAB];
357} GCC_PACK CAIDTAB;
358
359typedef struct s_tuntab
360{
361 ushort bt_caidfrom[CS_MAXTUNTAB];
362 ushort bt_caidto[CS_MAXTUNTAB];
363 ushort bt_srvid[CS_MAXTUNTAB];
364} GCC_PACK TUNTAB;
365
366typedef struct s_sidtab
367{
368 char label[33];
369 ushort num_caid;
370 ushort num_provid;
371 ushort num_srvid;
372 ushort *caid;
373 ulong *provid;
374 ushort *srvid;
375 struct s_sidtab *next;
376} GCC_PACK SIDTAB;
377
378
379typedef struct s_filter
380{
381 ushort caid;
382 uchar nprids;
383 ulong prids[CS_MAXPROV];
384} GCC_PACK FILTER;
385
386typedef struct s_ftab
387{
388 int nfilts;
389 FILTER filts[CS_MAXFILTERS];
390} GCC_PACK FTAB;
391
392typedef struct s_port
393{
394 int fd;
395 int s_port;
396 int ncd_key_is_set; //0 or 1
397 uchar ncd_key[16];
398 FTAB ftab;
399} GCC_PACK PORT;
400
401typedef struct s_ptab
402{
403 int nports;
404 PORT ports[CS_MAXPORTS];
405} GCC_PACK PTAB;
406
407#if defined(LIBUSB)
408typedef struct {
409 int F;
410 float D;
411 int fs;
412 int N;
413 int T;
414 int inv;
415 int parity;
416 int irdeto;
417 int running;
418 libusb_device *usb_dev;
419 libusb_device_handle *usb_dev_handle;
420 enum smartreader_chip_type type;
421 uint8_t in_ep; // 0x01
422 uint8_t out_ep; // 0x82
423 int index;
424 /** usb read timeout */
425 int usb_read_timeout;
426 /** usb write timeout */
427 int usb_write_timeout;
428 unsigned int writebuffer_chunksize;
429 unsigned char bitbang_enabled;
430 int baudrate;
431 int interface; // 0 or 1
432 /** maximum packet size. Needed for filtering modem status bytes every n packets. */
433 unsigned int max_packet_size;
434 unsigned char g_read_buffer[4096];
435 unsigned int g_read_buffer_size;
436 pthread_mutex_t g_read_mutex;
437 pthread_mutex_t g_usb_mutex;
438 pthread_t rt;
439 unsigned char modem_status;
440} SR_CONFIG;
441#endif
442
443typedef struct aes_entry {
444 ushort keyid;
445 ushort caid;
446 uint32 ident;
447 AES_KEY key;
448 struct aes_entry *next;
449} AES_ENTRY;
450
451struct s_ecm
452{
453 uchar ecmd5[CS_ECMSTORESIZE];
454 uchar cw[16];
455 ushort caid;
456 uint64 grp;
457 struct s_reader *reader;
458 struct s_ecm *next;
459 //int level;
460};
461
462struct s_emm
463{
464 uchar emmd5[CS_EMMSTORESIZE];
465 uchar type;
466 int count;
467};
468
469// failban listmember
470typedef struct v_ban {
471 uint v_ip;
472 time_t v_time;
473} GCC_PACK V_BAN;
474
475#define AVAIL_CHECK_CONNECTED 0
476#define AVAIL_CHECK_LOADBALANCE 1
477
478struct s_client ;
479struct ecm_request_t ;
480struct emm_packet_t ;
481
482struct s_module
483{
484 //int fd;
485 int multi;
486 int type;
487 int watchdog;
488 char desc[16];
489 char *logtxt;
490 //int s_port;
491 in_addr_t s_ip;
492 void *(*s_handler)();
493 int (*recv)(struct s_client *, uchar *, int);
494 void (*send_dcw)(struct s_client*, struct ecm_request_t *);
495 void (*cleanup)(struct s_client*);
496 int c_multi;
497 int (*c_recv_chk)(struct s_client*, uchar *, int *, uchar *, int);
498 int (*c_init)(struct s_client*);
499 int (*c_send_ecm)(struct s_client *, struct ecm_request_t *, uchar *);
500 int (*c_send_emm)(struct emm_packet_t *);
501 int (*c_init_log)(void);
502 int (*c_recv_log)(ushort *, ulong *, ushort *);
503 int (*c_available)(struct s_reader *, int); //Schlocke: available check for load-balancing,
504 //params:
505 //rdr (reader to check)
506 //int checktype (0=return connected, 1=return loadbalance-avail) return int
507 void (*c_idle)(void); //Schlocke: called when reader is idle
508 void (*c_card_info)(void); //Schlocke: request card infos
509 int c_port;
510 PTAB *ptab;
511 int num;
512};
513
514struct s_cardsystem
515{
516 char *desc;
517 int (*card_init)();
518 int (*card_info)();
519 int (*do_ecm)();
520 int (*do_emm)();
521 void (*post_process)();
522 int (*get_emm_type)();
523 void (*get_emm_filter)();
524 uchar caids[2];
525};
526
527#ifdef IRDETO_GUESSING
528struct s_irdeto_quess
529{
530 int b47;
531 ushort caid;
532 ushort sid;
533 struct s_irdeto_quess *next;
534};
535#endif
536
537#define MSGLOGSIZE 64
538typedef struct ecm_request_t
539{
540 uchar ecm[256];
541 uchar cw[16];
542 uchar ecmd5[CS_ECMSTORESIZE];
543// uchar l;
544 short l;
545 ushort caid;
546 ushort ocaid;
547 ushort srvid;
548 ushort chid;
549 ushort pid;
550 ushort idx;
551 ulong prid;
552 struct s_reader *selected_reader;
553 int matching_rdr[CS_MAXREADER];
554 struct s_client *client; //contains pointer to 'c' client while running in 'r' client
555 int cpti; // client pending table index
556 int stage; // processing stage in server module
557 int level; // send-level in client module
558 int rc;
559 uchar rcEx;
560 struct timeb tps; // incoming time stamp
561 uchar locals_done;
562 int btun; // mark er as betatunneled
563 int reader_avail; //count of available readers
564 int reader_count; //count of contacted readers
565
566#ifdef CS_WITH_DOUBLECHECK
567 int checked;
568 uchar cw_checked[16];
569 struct s_reader *origin_reader;
570#endif
571
572#ifdef CS_WITH_GBOX
573 ushort gbxCWFrom;
574 ushort gbxFrom;
575 ushort gbxTo;
576 uchar gbxForward[16];
577 int gbxRidx;
578#endif
579 char msglog[MSGLOGSIZE];
580
581} GCC_PACK ECM_REQUEST;
582
583struct s_client
584{
585 in_addr_t ip;
586 in_port_t port;
587 time_t login;
588 time_t last;
589 time_t lastswitch;
590 time_t lastemm;
591 time_t lastecm;
592 time_t expirationdate;
593 int allowedtimeframe[2];
594 int c35_suppresscmd08;
595 int c35_sleepsend;
596 int ncd_keepalive;
597 int disabled;
598 uint64 grp;
599 int crypted;
600 int dup;
601 struct s_reader *aureader; //the reader that needs EMMs from this client
602 int autoau;
603 int monlvl;
604 CAIDTAB ctab;
605 TUNTAB ttab;
606 SIDTABBITS sidtabok; // positiv services
607 SIDTABBITS sidtabno; // negative services
608 int typ; // first s_client is type s=starting (master) thread; type r = physical reader, type p = proxy reader both always have 1 s_reader struct allocated; type c = client (user logging in into oscam) type m = monitor type h = http server a = anticascader
609 int ctyp;
610 int stat;
611 int last_srvid;
612 int last_caid;
613 int tosleep;
614 char usr[32];
615 int udp_fd;
616 int fd_m2c; //master writes to this fd
617 int fd_m2c_c; //client reads from this fd
618 struct sockaddr_in udp_sa;
619 int log;
620 int logcounter;
621 int cwfound; // count found ECMs per client
622 int cwcache; // count ECMs from cache1/2 per client
623 int cwnot; // count not found ECMs per client
624 int cwtun; // count betatunneled ECMs per client
625 int cwignored; // count ignored ECMs per client
626 int cwtout; // count timeouted ECMs per client
627 int cwlastresptime; //last Responsetime (ms)
628 int emmok; // count EMM ok
629 int emmnok; // count EMM nok
630#ifdef WEBIF
631 int wihidden; // hidden in webinterface status
632 char lastreader[32]; // last cw got from this reader
633#endif
634 uchar ucrc[4]; // needed by monitor and used by camd35
635 ulong pcrc; // pwd crc
636 AES_KEY aeskey; // encryption key needed by monitor and used by camd33, camd35
637 AES_KEY aeskey_decrypt; // decryption key needed by monitor and used by camd33, camd35
638 ushort ncd_msgid;
639 char ncd_client_id[5];
640 uchar ncd_skey[16];
641 void *cc;
642 int port_idx; // index in server ptab
643 int ncd_server; // newcamd server
644#ifdef CS_ANTICASC
645 ushort ac_idx;
646 ushort ac_limit;
647 uchar ac_penalty;
648#endif
649 FTAB fchid;
650 FTAB ftab; // user [caid] and ident filter
651 CLASSTAB cltab;
652
653
654 int pfd; // Primary FD, must be closed on exit
655 struct s_reader *reader; //points to s_reader when cl->typ='r'
656 int cs_ptyp; // process-type
657
658 ECM_REQUEST *ecmtask;
659 struct s_emm *emmcache;
660
661 pthread_t thread;
662
663 //reader common
664 int last_idx;
665 ushort idx;
666 //int cs_ptyp_orig;
667 int rotate;
668
669 uchar *req;
670
671 //camd33
672 uchar camdbug[256];
673
674 int ncd_proto;
675
676 //camd35
677 uchar upwd[64];
678 int is_udp;
679 int stopped;
680 int lastcaid;
681 int lastsrvid;
682 int lastpid;
683 time_t emm_last;
684 int disable_counter;
685 uchar lastserial[8];
686
687 //cccam
688 int g_flag;
689 int cc_use_rc4;
690
691 //monitor
692 int auth;
693
694 //cs_hexdump buffer
695 uchar dump[520];
696
697 //oscam.c
698 struct timeval tv;
699
700 //failban value set bitwise - compared with BAN_
701 int failban;
702 struct s_client *next; //make client a linked list
703};
704
705
706//for viaccess var in s_reader:
707struct geo_cache
708{
709 ulong provid;
710 uchar geo[256];
711 uchar geo_len;
712 int number_ecm;
713};
714// for videoguard in s_reader
715struct s_CmdTabEntry {
716 unsigned char cla;
717 unsigned char cmd;
718 unsigned char len;
719 unsigned char mode;
720};
721
722struct s_CmdTab {
723 unsigned char index;
724 unsigned char size;
725 unsigned char Nentries;
726 unsigned char dummy;
727 struct s_CmdTabEntry e[1];
728};
729//ratelimit
730struct ecmrl {
731 ushort srvid;
732 time_t last;
733};
734#define MAXECMRATELIMIT 20
735
736struct s_reader //contains device info, reader info and card info
737{
738 ulong auprovid; // AU only for this provid
739 int audisabled; // exclude reader from auto AU
740 int deleted; // if this flag is set the reader is not shown in webif and becomes not writte to oscam.server
741 int smargopatch;
742 struct s_client * client; //pointer to 'r'client this reader is running in
743 int enable;
744 int available; //Schlocke: New flag for loadbalancing. Only reader if reader supports ph.c_available function
745 int fd_error;
746 int fd;
747 uint64 grp;
748 int fallback;
749 int typ;
750 int card_system;
751 char label[32];
752 char device[128];
753 ushort slot; //in case of multiple slots like sc8in1; first slot = 1
754 int handle; //device handle
755 int fdmc; //device handle for multicam
756#ifdef ST_LINUX
757 unsigned int stsmart_handle; //device handle for stsmart driver
758#endif
759 char pcsc_name[128];
760 int pcsc_has_card;
761 int detect;
762 int mhz; //actual clock rate of reader in 10khz steps
763 int cardmhz; //standard clock speed your card should have in 10khz steps; normally 357 but for Irdeto cards 600
764 int r_port;
765 char r_usr[64];
766 char r_pwd[64];
767 int r_crypted;
768 int l_port;
769 int log_port;
770 CAIDTAB ctab;
771 ulong boxid;
772 int nagra_read; // read nagra ncmed records: 0 disabled (default), 1 read all records, 2 read valid records only
773 uchar nagra_boxkey[16]; //n3 boxkey 8byte or tiger idea key 16byte
774 int has_rsa;
775 char country_code[3]; // irdeto country code.
776 int force_irdeto;
777 uchar aes_key[16];
778 uchar rsa_mod[120]; //rsa modulus for nagra cards.
779 uchar atr[64];
780 int atrlen;
781 SIDTABBITS sidtabok; // positiv services
782 SIDTABBITS sidtabno; // negative services
783 uchar hexserial[8];
784 int nprov;
785 uchar prid[CS_MAXPROV][8];
786 uchar availkeys[CS_MAXPROV][16]; // viaccess; misused in seca, if availkeys[PROV][0]=0 then expired, 1 then valid.
787 uchar sa[CS_MAXPROV][4]; // viaccess & seca
788 ushort acs; // irdeto
789 ushort caid[CS_MAXREADERCAID];
790 uchar b_nano[256];
791 int blockemm_unknown; //block EMMs that have unknown type
792 int blockemm_u; //blcok Unique EMMs
793 int blockemm_s; //block Shared EMMS
794 int blockemm_g; //block Global EMMs
795 char * emmfile;
796 char pincode[5];
797 int ucpk_valid;
798 int logemm;
799 int cachemm;
800 int rewritemm;
801 int card_status;
802 int deprecated; //if 0 ATR obeyed, if 1 default speed (9600) is chosen; for devices that cannot switch baudrate
803 struct s_module ph;
804 uchar ncd_key[16];
805 uchar ncd_skey[16];
806 int ncd_disable_server_filt;
807 ushort ncd_msgid;
808 int ncd_proto;
809 char cc_version[7]; // cccam version
810 char cc_build[7]; // cccam build number
811 int cc_maxhop; // cccam max distance
812 int cc_currenthops; // number of hops for CCCam
813 int cc_want_emu; //Schlocke: Client want to have EMUs, 0 - NO; 1 - YES
814 uint32 cc_id;
815 int cc_keepalive;
816 uchar tcp_connected;
817 int tcp_ito; // inactivity timeout
818 int tcp_rto; // reconnect timeout
819 struct timeb tcp_block_connect_till; //time tcp connect ist blocked
820 int tcp_block_delay; //incrementing block time
821 time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect )
822 time_t last_s; // send
823 uchar show_cls; // number of classes subscription showed on kill -31
824 int maxqlen; // max queue length
825 int qlen; // current queue length
826 FTAB fchid;
827 FTAB ftab;
828 CLASSTAB cltab;
829#ifdef CS_WITH_GBOX
830 uchar gbox_pwd[4];
831 uchar gbox_timecode[7];
832 int gbox_online;
833 uchar gbox_vers;
834 uchar gbox_prem;
835 int gbox_fd;
836 struct timeb gbox_lasthello; // incoming time stamp
837#endif
838
839 int init_history_pos;
840 int brk_pos;
841 int msg_idx;
842#ifdef WEBIF
843 int emmwritten[4]; //count written EMM
844 int emmskipped[4]; //count skipped EMM
845 int emmerror[4]; //count error EMM
846 int emmblocked[4]; //count blocked EMM
847 int lbvalue; //loadbalance Value
848#endif
849#ifdef HAVE_PCSC
850 SCARDCONTEXT hContext;
851 SCARDHANDLE hCard;
852 DWORD dwActiveProtocol;
853#endif
854#ifdef LIBUSB
855 uint8_t device_endpoint; // usb endpoint for Infinity USB Smart in smartreader mode.
856 SR_CONFIG *sr_config;
857#endif
858#ifdef AZBOX
859 int mode;
860#endif
861 ////variables from icc_async.h start
862 int convention; //Convention of this ICC
863 unsigned char protocol_type; // Type of protocol
864 unsigned short BWT,CWT; // (for overclocking uncorrected) block waiting time, character waiting time, in ETU
865 unsigned long current_baudrate; // (for overclocking uncorrected) baudrate to prevent unnecessary conversions from/to termios structure
866 unsigned int read_timeout; // Max timeout (ms) to receive characters
867 unsigned int block_delay; // Delay (ms) after starting to transmit
868 unsigned int char_delay; // Delay (ms) after transmiting each sucesive char
869 ////variables from io_serial.h
870 int written; //keep score of how much bytes are written to serial port, since they are echoed back they have to be read
871 ////variables from protocol_t1.h
872 unsigned short ifsc; /* Information field size for the ICC */
873 unsigned char ns; /* Send sequence number */
874 ////variables from reader-dre.c
875 unsigned char provider;
876 ////variables from reader-nagra.c
877 IDEA_KEY_SCHEDULE ksSession;
878 int is_pure_nagra;
879 int is_tiger;
880 int is_n3_na;
881 int has_dt08;
882 int swapCW;
883 uint8_t ExpiryDate[2];
884 uint8_t ActivationDate[2];
885 unsigned char rom[15];
886 unsigned char plainDT08RSA[64];
887 unsigned char IdeaCamKey[16];
888 unsigned char irdId[4];
889 unsigned char sessi[16];
890 unsigned char signature[8];
891 unsigned char cam_state[3];
892 ////variables from reader-cryptoworks.c
893 BIGNUM exp;
894 BIGNUM ucpk;
895 ////variables from reader-viaccess.c
896 struct geo_cache last_geo;
897 int cc_reshare;
898 int lb_weight; //loadbalance weight factor, if unset, weight=100. The higher the value, the higher the usage-possibility
899 int lb_usagelevel; //usagelevel for loadbalancer
900 int lb_usagelevel_ecmcount;
901 time_t lb_usagelevel_time; //time for counting ecms, this creates usagelevel
902 struct timeb lb_last; //time for oldest reader
903 LLIST *lb_stat; //loadbalancer reader statistics
904 // multi AES linked list
905 AES_ENTRY *aes_list;
906 // variables from reader-videoguard*
907 int ndsversion; // 0 auto (default), 1 NDS1, 12 NDS1+, 2 NDS2
908 const char * card_desc;
909 int card_baseyear;
910 int card_tierstart;
911 int card_system_version;
912 struct s_CmdTab *cmd_table;
913 unsigned short cardkeys[3][32];
914 unsigned char stateD3A[16];
915 AES_KEY ekey;
916 AES_KEY astrokey;
917 //ratelimit
918 int ratelimitecm;
919 int ratelimitseconds;
920 struct ecmrl rlecmh[MAXECMRATELIMIT];
921 struct s_reader *next;
922};
923
924#ifdef CS_ANTICASC
925
926struct s_acasc_shm {
927 ushort ac_count : 15;
928 ushort ac_deny : 1;
929};
930
931struct s_acasc {
932 ushort stat[10];
933 uchar idx; // current active index in stat[]
934};
935
936struct s_cpmap
937{
938 ushort caid;
939 ulong provid;
940 ushort sid;
941 ushort chid;
942 ushort dwtime;
943 struct s_cpmap *next;
944};
945#endif
946
947struct s_auth
948{
949 char usr[33];
950 char pwd[33];
951 int uniq;
952 struct s_reader *aureader;
953 int autoau;
954 int monlvl;
955 uint64 grp;
956 int tosleep;
957 CAIDTAB ctab;
958 SIDTABBITS sidtabok; // positiv services
959 SIDTABBITS sidtabno; // negative services
960 FTAB fchid;
961 FTAB ftab; // user [caid] and ident filter
962 CLASSTAB cltab;
963 TUNTAB ttab;
964#ifdef CS_ANTICASC
965 int ac_idx;
966 int ac_users; // 0 - unlimited
967 uchar ac_penalty; // 0 - log, >0 - fake dw
968#endif
969 in_addr_t dynip;
970 uchar dyndns[64];
971 time_t expirationdate;
972 int allowedtimeframe[2];
973 int c35_suppresscmd08;
974 int c35_sleepsend;
975 int ncd_keepalive;
976 int cccmaxhops;
977 int cccreshare;
978 int disabled;
979 int failban;
980 struct s_auth *next;
981};
982
983struct s_srvid
984{
985 int srvid;
986 int ncaid;
987 int caid[10];
988 char prov[33];
989 char name[33];
990 char type[33];
991 char desc[33];
992 struct s_srvid *next;
993};
994
995struct s_tierid
996{
997 int tierid;
998 int ncaid;
999 int caid[10];
1000 char name[33];
1001 struct s_tierid *next;
1002};
1003
1004//Todo #ifdef CCCAM
1005struct s_provid
1006{
1007 int caid;
1008 ulong provid;
1009 char prov[33];
1010 char sat[33];
1011 char lang[33];
1012 struct s_provid *next;
1013};
1014
1015struct s_ip
1016{
1017 in_addr_t ip[2];
1018 struct s_ip *next;
1019};
1020
1021struct s_config
1022{
1023 int nice;
1024 int debuglvl;
1025 ulong netprio;
1026 ulong ctimeout;
1027 ulong ftimeout;
1028 ulong cmaxidle;
1029 int ulparent;
1030 ulong delay;
1031 int bindwait;
1032 int resolvedelay;
1033 int clientdyndns;
1034 int tosleep;
1035 in_addr_t srvip;
1036 char *usrfile;
1037 char *cwlogdir;
1038 char *logfile;
1039 int disablelog;
1040 int disableuserfile;
1041 int usrfileflag;
1042 struct s_auth *account;
1043 struct s_srvid *srvid;
1044 struct s_tierid *tierid;
1045 //Todo #ifdef CCCAM
1046 struct s_provid *provid;
1047 struct s_sidtab *sidtab;
1048 int mon_port;
1049 in_addr_t mon_srvip;
1050 struct s_ip *mon_allowed;
1051 int mon_aulow;
1052 int mon_hideclient_to;
1053 int mon_level;
1054 int mon_appendchaninfo;
1055#ifdef WEBIF
1056 int http_port;
1057 char http_user[65];
1058 char http_pwd[65];
1059 char http_css[128];
1060 char http_jscript[128];
1061 char http_tpl[128];
1062 char http_script[128];
1063 int http_refresh;
1064 int http_hide_idle_clients;
1065 struct s_ip *http_allowed;
1066 int http_readonly;
1067 in_addr_t http_dynip;
1068 uchar http_dyndns[64];
1069 int http_use_ssl;
1070 char http_cert[128];
1071#endif
1072 int http_full_cfg;
1073 int failbantime;
1074 LLIST_D_ *v_list; //failban list
1075 int c33_port;
1076 in_addr_t c33_srvip;
1077 uchar c33_key[16];
1078 int c33_crypted;
1079 int c33_passive;
1080 struct s_ip *c33_plain;
1081 int c35_port;
1082 in_addr_t c35_srvip;
1083 int c35_suppresscmd08;
1084 PTAB c35_tcp_ptab;
1085 in_addr_t c35_tcp_srvip;
1086 PTAB ncd_ptab;
1087 in_addr_t ncd_srvip;
1088 uchar ncd_key[16];
1089 int ncd_keepalive;
1090 int ncd_mgclient;
1091 struct s_ip *ncd_allowed;
1092 PTAB cc_ptab;
1093 int rad_port;
1094 in_addr_t rad_srvip;
1095 int cc_port;
1096 int cc_reshare;
1097 int cc_ignore_reshare;
1098 int cc_update_interval;
1099 in_addr_t cc_srvip;
1100 char cc_version[7];
1101 int cc_minimize_cards;
1102 int cc_keep_connected;
1103 struct s_ip *rad_allowed;
1104 char rad_usr[32];
1105 char ser_device[512];
1106 ulong srtimeout; // SerialReaderTimeount in millisec
1107 int max_log_size;
1108 int waitforcards;
1109 int preferlocalcards;
1110 int saveinithistory;
1111 int reader_restart_seconds; //schlocke: reader restart auf x seconds, disable = 0
1112
1113//Loadbalancer-Config:
1114 int lb_mode; //schlocke: reader loadbalancing mode
1115 int lb_save; //schlocke: load/save statistics to file, save every x ecms
1116 int lb_nbest_readers; // count of best readers
1117 int lb_nfb_readers; // count of fallback readers
1118 int lb_min_ecmcount; // minimal ecm count to evaluate lbvalues
1119 int lb_max_ecmcount; // maximum ecm count before reseting lbvalues
1120 int lb_reopen_seconds; //time between retrying failed readers/caids/prov/srv
1121
1122 int resolve_gethostbyname;
1123
1124#ifdef CS_WITH_DOUBLECHECK
1125 int double_check; //schlocke: Double checks each ecm+dcw from two (or more) readers
1126#endif
1127
1128#ifdef CS_WITH_GBOX
1129 uchar gbox_pwd[8];
1130 uchar ignorefile[128];
1131 uchar cardfile[128];
1132 uchar gbxShareOnl[128];
1133 int maxdist;
1134 int num_locals;
1135 unsigned long locals[CS_MAXLOCALS];
1136#endif
1137
1138#ifdef IRDETO_GUESSING
1139 struct s_irdeto_quess *itab[0xff];
1140#endif
1141
1142#ifdef HAVE_DVBAPI
1143 int dvbapi_enabled;
1144 int dvbapi_au;
1145 char dvbapi_usr[33];
1146 int dvbapi_boxtype;
1147 int dvbapi_pmtmode;
1148 SIDTABBITS dvbapi_sidtabok; // positiv services
1149 SIDTABBITS dvbapi_sidtabno; // negative services
1150#endif
1151
1152#ifdef CS_ANTICASC
1153 char ac_enabled;
1154 int ac_users; // num of users for account (0 - default)
1155 int ac_stime; // time to collect AC statistics (3 min - default)
1156 int ac_samples; // qty of samples
1157 int ac_penalty; // 0 - write to log
1158 int ac_fakedelay; // 100-1000 ms
1159 int ac_denysamples;
1160 char ac_logfile[128];
1161 struct s_cpmap *cpmap;
1162#endif
1163
1164#ifdef QBOXHD_LED
1165 int disableqboxhdled; // disable qboxhd led , default = 0
1166#endif
1167};
1168
1169//Loadbalance constants:
1170#define LB_NONE 0
1171#define LB_FASTEST_READER_FIRST 1
1172#define LB_OLDEST_READER_FIRST 2
1173#define LB_LOWEST_USAGELEVEL 3
1174#define LB_MAX_STAT_TIME 20
1175
1176typedef struct reader_stat_t
1177{
1178 int rc;
1179 ushort caid;
1180 ulong prid;
1181 ushort srvid;
1182
1183 time_t last_received;
1184
1185 int ecm_count;
1186 int time_avg;
1187 int time_stat[LB_MAX_STAT_TIME];
1188 int time_idx;
1189
1190 int request_count;
1191} GCC_PACK READER_STAT;
1192
1193typedef struct emm_packet_t
1194{
1195 uchar emm[258];
1196 uchar l;
1197 uchar caid[2];
1198 uchar provid[4];
1199 uchar hexserial[8]; //contains hexserial or SA of EMM
1200 uchar type;
1201 struct s_client *client;
1202} GCC_PACK EMM_PACKET;
1203
1204//EMM types:
1205#define UNKNOWN 0
1206#define UNIQUE 1
1207#define SHARED 2
1208#define GLOBAL 3
1209
1210// oscam-simples
1211extern char *remote_txt(void);
1212extern char *trim(char *);
1213extern char *strtolower(char *);
1214extern int gethexval(char);
1215extern int cs_atob(uchar *, char *, int);
1216extern ulong cs_atoi(char *, int, int);
1217extern int byte_atob(char *);
1218extern long word_atob(char *);
1219extern long dyn_word_atob(char *asc);
1220extern int key_atob(char *, uchar *);
1221extern int key_atob14(char *, uchar *);
1222extern int key_atob_l(char *, uchar *, int);
1223extern char *key_btoa(char *, uchar *);
1224extern char *cs_hexdump(int, const uchar *, int);
1225extern in_addr_t cs_inet_order(in_addr_t);
1226extern char *cs_inet_ntoa(in_addr_t);
1227extern in_addr_t cs_inet_addr(char *txt);
1228extern ulong b2i(int, uchar *);
1229extern ullong b2ll(int, uchar *);
1230extern uchar *i2b(int, ulong);
1231extern ulong a2i(char *, int);
1232extern int boundary(int, int);
1233extern void cs_ftime(struct timeb *);
1234extern void cs_sleepms(unsigned int);
1235extern void cs_sleepus(unsigned int);
1236extern int bytes_available(int);
1237extern void cs_setpriority(int);
1238extern struct s_auth *find_user(char *);
1239#ifdef WEBIF
1240extern int x2i(int i);
1241extern void urldecode(char *s);
1242extern char to_hex(char code);
1243extern char *urlencode(char *str);
1244extern char *char_to_hex(const unsigned char* p_array, unsigned int p_array_len, char hex2ascii[256][2]);
1245extern void create_rand_str(char *dst, int size);
1246#endif
1247extern void sidtabbits2bitchar(SIDTABBITS value, char *result);
1248extern void long2bitchar(long value, char *result);
1249extern void uint642bitchar(uint64 value, char *result);
1250extern int file_exists(const char * filename);
1251extern void clear_sip(struct s_ip **sip);
1252extern void clear_ptab(struct s_ptab *ptab);
1253extern void clear_ftab(struct s_ftab *ftab);
1254void clear_caidtab(struct s_caidtab *ctab);
1255void clear_tuntab(struct s_tuntab *ttab);
1256extern int safe_overwrite_with_bak(char *destfile, char *tmpfile, char *bakfile, int forceBakOverWrite);
1257extern void fprintf_conf(FILE *f, int varnameWidth, const char *varname, const char *fmtstring, ...);
1258extern void cs_strncpy(char * destination, const char * source, size_t num);
1259extern char *get_servicename(int srvid, int caid);
1260extern char *get_tiername(int tierid, int caid);
1261extern char *get_provider(int caid, ulong provid);
1262extern void make_non_blocking(int fd);
1263extern uchar fast_rnd(void);
1264extern void init_rnd(void);
1265extern int hexserialset(struct s_reader *rdr);
1266extern char *monitor_get_proto(struct s_client *);
1267extern char *reader_get_type_desc(struct s_reader * rdr, int extended);
1268extern char *get_ncd_client_name(char *client_id);
1269
1270extern pthread_key_t getclient;
1271extern struct s_client * cur_client(void);
1272extern struct s_client *first_client;
1273extern struct s_reader *first_reader;
1274
1275// oscam variables
1276
1277extern int cs_dblevel, loghistidx;
1278
1279extern ushort len4caid[256];
1280
1281extern struct card_struct *Cards;
1282//extern struct idstore_struct *idstore;
1283extern unsigned long *IgnoreList;
1284
1285extern struct s_config *cfg;
1286extern char cs_confdir[];
1287extern char loghist[CS_MAXLOGHIST*CS_LOGHISTSIZE];
1288extern struct s_module ph[CS_MAX_MOD];
1289extern struct s_cardsystem cardsystem[CS_MAX_MOD];
1290//extern ECM_REQUEST *ecmtask;
1291
1292#ifdef CS_ANTICASC
1293extern FILE *fpa;
1294#endif
1295extern pthread_mutex_t gethostbyname_lock;
1296
1297// oscam
1298extern int recv_from_udpipe(uchar *);
1299extern char* username(struct s_client *);
1300extern struct s_client * get_client_by_tid(unsigned long);
1301extern int chk_bcaid(ECM_REQUEST *, CAIDTAB *);
1302extern void cs_exit(int sig);
1303extern int comp_timeb(struct timeb *tpa, struct timeb *tpb);
1304extern struct s_client * cs_fork(in_addr_t);
1305extern int cs_auth_client(struct s_client *, struct s_auth *, const char*);
1306extern void cs_disconnect_client(struct s_client *);
1307extern int check_cwcache2(ECM_REQUEST *, uint64);
1308extern int write_to_pipe(int, int, uchar *, int);
1309extern int read_from_pipe(int, uchar **, int);
1310extern int write_ecm_request(int, ECM_REQUEST *);
1311extern int write_ecm_answer(struct s_reader *, ECM_REQUEST *);
1312extern void log_emm_request(struct s_reader *);
1313extern ulong chk_provid(uchar *, ushort);
1314extern void guess_cardsystem(ECM_REQUEST *);
1315#ifdef IRDETO_GUESSING
1316extern void guess_irdeto(ECM_REQUEST *);
1317#endif
1318extern void get_cw(struct s_client *, ECM_REQUEST *);
1319extern void do_emm(struct s_client *, EMM_PACKET *);
1320extern ECM_REQUEST *get_ecmtask(void);
1321extern void request_cw(ECM_REQUEST *, int, int);
1322extern int send_dcw(struct s_client *, ECM_REQUEST *);
1323extern int process_input(uchar *, int, int);
1324extern int chk_srvid(struct s_client *, ECM_REQUEST *);
1325extern int chk_srvid_match(ECM_REQUEST *, SIDTAB *);
1326extern int chk_sfilter(ECM_REQUEST *, PTAB*);
1327extern int chk_ufilters(ECM_REQUEST *);
1328extern int chk_rfilter(ECM_REQUEST *, struct s_reader *);
1329extern int chk_rsfilter(struct s_reader * reader, ECM_REQUEST *);
1330extern int chk_avail_reader(ECM_REQUEST *, struct s_reader *);
1331extern int matching_reader(ECM_REQUEST *, struct s_reader *);
1332extern void set_signal_handler(int , int , void (*));
1333extern void cs_log_config(void);
1334extern void cs_waitforcardinit(void);
1335extern void cs_reinit_clients(void);
1336extern int process_client_pipe(struct s_client *cl, uchar *buf, int l);
1337extern void update_reader_config(uchar *ptr);
1338extern int chk_ctab(ushort caid, CAIDTAB *ctab);
1339extern int chk_srvid_match_by_caid_prov(ushort caid, ulong provid, SIDTAB *sidtab);
1340extern int chk_srvid_by_caid_prov(struct s_client *, ushort caid, ulong provid, int chk_neg);
1341extern void kill_thread(struct s_client *cl);
1342extern int get_threadnum(struct s_client *client);
1343extern int get_nr_of_readers(void);
1344extern int get_ridx(struct s_reader *reader);
1345
1346extern void cs_card_info(void);
1347extern void cs_debug_level(void);
1348
1349#ifdef CS_ANTICASC
1350extern void init_ac(void);
1351extern void ac_init_stat();
1352extern void ac_clear();
1353extern void ac_done_stat();
1354extern int ac_init_log();
1355extern void ac_do_stat(void);
1356extern void ac_init_client(struct s_auth *);
1357extern void ac_chk(ECM_REQUEST*, int);
1358#endif
1359
1360// oscam-nano
1361extern int chk_class(ECM_REQUEST *, CLASSTAB*, const char*, const char*);
1362
1363// oscam-config
1364extern int init_config(void);
1365extern int init_userdb(struct s_auth **authptr_org);
1366extern int init_readerdb(void);
1367extern int init_sidtab(void);
1368extern int init_srvid(void);
1369extern int init_tierid(void);
1370extern int search_boxkey(ushort, char *);
1371extern void init_len4caid(void);
1372#ifdef IRDETO_GUESSING
1373extern int init_irdeto_guess_tab(void);
1374#endif
1375extern void chk_caidtab(char *caidasc, CAIDTAB *ctab);
1376extern void chk_tuntab(char *tunasc, TUNTAB *ttab);
1377extern void chk_services(char *labels, SIDTABBITS *sidok, SIDTABBITS *sidno);
1378extern void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName);
1379extern void chk_cltab(char *classasc, CLASSTAB *clstab);
1380extern void chk_iprange(char *value, struct s_ip **base);
1381extern void chk_port_tab(char *portasc, PTAB *ptab);
1382#ifdef CS_ANTICASC
1383extern void chk_t_ac(char *token, char *value);
1384#endif
1385extern void chk_t_camd33(char *token, char *value);
1386extern void chk_t_camd35(char *token, char *value);
1387extern void chk_t_camd35_tcp(char *token, char *value);
1388extern void chk_t_newcamd(char *token, char *value);
1389extern void chk_t_radegast(char *token, char *value);
1390extern void chk_t_serial(char *token, char *value);
1391#ifdef CS_WITH_GBOX
1392extern void chk_t_gbox(char *token, char *value);
1393#endif
1394extern void chk_t_cccam(char *token, char *value);
1395extern void chk_t_global(const char *token, char *value);
1396extern void chk_t_monitor(char *token, char *value);
1397extern void chk_reader(char *token, char *value, struct s_reader *rdr);
1398
1399#ifdef HAVE_DVBAPI
1400extern void chk_t_dvbapi(char *token, char *value);
1401void dvbapi_chk_caidtab(char *caidasc, char type);
1402void dvbapi_read_priority();
1403#endif
1404
1405#ifdef WEBIF
1406extern void chk_t_webif(char *token, char *value);
1407#endif
1408
1409extern void cs_accounts_chk(void);
1410extern void chk_account(const char *token, char *value, struct s_auth *account);
1411extern void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab);
1412extern int write_services();
1413extern int write_userdb(struct s_auth *authptr);
1414extern int write_config();
1415extern int write_server();
1416extern void write_versionfile();
1417extern char *mk_t_caidtab(CAIDTAB *ctab);
1418extern char *mk_t_tuntab(TUNTAB *ttab);
1419extern char *mk_t_group(uint64 grp);
1420extern char *mk_t_ftab(FTAB *ftab);
1421//Todo #ifdef CCCAM
1422extern int init_provid();
1423extern char * get_tmp_dir();
1424
1425// oscam-reader
1426extern int logfd;
1427extern int reader_cmd2icc(struct s_reader * reader, const uchar *buf, const int l, uchar *response, ushort *response_length);
1428extern int card_write(struct s_reader * reader, const uchar *, const uchar *, uchar *, ushort *);
1429extern int check_sct_len(const unsigned char *data, int off);
1430extern void cs_ri_brk(struct s_reader * reader, int);
1431extern void cs_ri_log(struct s_reader * reader, char *,...);
1432extern void * start_cardreader(void *);
1433extern void reader_card_info(struct s_reader * reader);
1434extern int hostResolve(struct s_reader * reader);
1435extern int network_tcp_connection_open();
1436extern void network_tcp_connection_close(struct s_client *, int);
1437extern int casc_recv_timer(struct s_reader * reader, uchar *buf, int l, int msec);
1438extern void clear_reader_pipe(struct s_reader * reader);
1439extern void block_connect(struct s_reader *rdr);
1440extern int is_connect_blocked(struct s_reader *rdr);
1441
1442// oscam-log
1443extern int cs_init_log();
1444extern void cs_write_log(char *);
1445extern void cs_log(const char *,...);
1446#ifdef WITH_DEBUG
1447extern void cs_debug(const char *,...);
1448extern void cs_debug_mask(unsigned short, const char *,...);
1449extern void cs_ddump(const uchar *, int, char *, ...);
1450extern void cs_ddump_mask(unsigned short, const uchar *, int, char *, ...);
1451#else
1452#define cs_debug(...)
1453#define cs_debug_mask(...)
1454#define cs_ddump(...)
1455#define cs_ddump_mask(...)
1456#endif
1457extern void cs_close_log(void);
1458extern int cs_init_statistics();
1459extern void cs_dump(const uchar *, int, char *, ...);
1460
1461// oscam-aes
1462extern void aes_set_key(char *);
1463extern void add_aes_entry(struct s_reader *rdr, ushort caid, uint32 ident, int keyid, uchar *aesKey);
1464extern void aes_encrypt_idx(struct s_client *, uchar *, int);
1465extern void aes_decrypt(uchar *, int);
1466extern int aes_decrypt_from_list(AES_ENTRY *list, ushort caid, uint32 provid,int keyid, uchar *buf, int n);
1467extern int aes_present(AES_ENTRY *list, ushort caid, uint32 provid,int keyid);
1468extern void parse_aes_keys(struct s_reader *rdr,char *value);
1469extern void aes_clear_entries(struct s_reader *rdr);
1470
1471#define aes_encrypt(b, n) aes_encrypt_idx(cur_client(), b, n)
1472
1473// reader-common
1474extern int reader_device_init(struct s_reader * reader);
1475extern int reader_checkhealth(struct s_reader * reader);
1476extern void reader_post_process(struct s_reader * reader);
1477extern int reader_ecm(struct s_reader * reader, ECM_REQUEST *);
1478extern int reader_emm(struct s_reader * reader, EMM_PACKET *);
1479int reader_get_emm_type(EMM_PACKET *ep, struct s_reader * reader);
1480void get_emm_filter(struct s_reader * rdr, uchar *filter);
1481int get_cardsystem(ushort caid);
1482extern int check_emm_cardsystem(struct s_reader * rdr, EMM_PACKET *ep);
1483extern void reader_device_close(struct s_reader * reader);
1484
1485//module-stat
1486extern void init_stat();
1487extern int get_best_reader(ECM_REQUEST *er);
1488extern void clear_reader_stat(struct s_reader *reader);
1489extern void add_stat(struct s_reader *rdr, ushort caid, ulong prid, ushort srvid, int ecm_time, int rc);
1490#ifdef HAVE_PCSC
1491// reader-pcsc
1492extern void pcsc_close(struct s_reader *pcsc_reader);
1493#endif
1494
1495void reader_nagra();
1496void reader_irdeto();
1497void reader_cryptoworks();
1498void reader_viaccess();
1499void reader_conax();
1500void reader_seca();
1501void reader_videoguard1();
1502void reader_videoguard2();
1503void reader_videoguard12();
1504void reader_dre();
1505void reader_tongfang();
1506
1507// protocol modules
1508extern int monitor_send_idx(struct s_client *, char *);
1509extern void module_monitor(struct s_module *);
1510extern void module_camd35(struct s_module *);
1511extern void module_camd35_tcp(struct s_module *);
1512extern void module_camd33(struct s_module *);
1513extern void module_newcamd(struct s_module *);
1514extern void module_radegast(struct s_module *);
1515extern void module_oscam_ser(struct s_module *);
1516extern void module_cccam(struct s_module *);
1517extern void module_constcw(struct s_module *);
1518extern struct timeval *chk_pending(struct timeb tp_ctimeout);
1519#ifdef CS_WITH_GBOX
1520extern void module_gbox(struct s_module *);
1521#endif
1522#ifdef HAVE_DVBAPI
1523extern void module_dvbapi(struct s_module *);
1524#endif
1525
1526#ifdef WEBIF
1527// oscam-http
1528extern void http_srv();
1529#endif
1530
1531#endif // CS_GLOBALS
Note: See TracBrowser for help on using the repository browser.