source: trunk/globals.h@ 8370

Last change on this file since 8370 was 8370, checked in by TNe-TWo, 9 years ago

commit CW Cycle Check -> Thx Blaky
http://www.streamboard.tv/wbb2/thread.php?postid=440059#post440059

  • Property svn:eol-style set to LF
File size: 52.2 KB
Line 
1#ifndef GLOBALS_H_
2#define GLOBALS_H_
3
4#define _GNU_SOURCE //needed for PTHREAD_MUTEX_RECURSIVE on some plattforms and maybe other things; do not remove
5#include <stdlib.h>
6#include <stdio.h>
7#include <stdbool.h>
8#include <assert.h>
9#include <fcntl.h>
10#include <sys/ioctl.h>
11#include <sys/poll.h>
12#include <ctype.h>
13#include <sys/types.h>
14#include <sys/stat.h>
15#include <sys/wait.h>
16#include <unistd.h>
17#include <sys/mman.h>
18#include <stdarg.h>
19#include <time.h>
20#include <sys/time.h>
21#include <limits.h>
22#include <pwd.h>
23#include <netinet/tcp.h>
24#include <sys/socket.h>
25#include <netinet/in.h>
26#include <arpa/inet.h>
27#include <netdb.h>
28#include <string.h>
29#include <signal.h>
30#include <errno.h>
31#include <pthread.h>
32#include <dirent.h>
33#include <termios.h>
34
35//for reader-nagra variables in s_reader:
36#include "cscrypt/idea.h"
37
38/*
39 * The following hack is taken from Linux: include/linux/kconfig.h
40 * Original comment follows:
41 * Getting something that works in C and CPP for an arg that may or may
42 * not be defined is tricky. Here, if we have "#define CONFIG_BOOGER 1"
43 * we match on the placeholder define, insert the "0," for arg1 and generate
44 * the triplet (0, 1, 0). Then the last step cherry picks the 2nd arg (a one).
45 * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
46 * the last step cherry picks the 2nd arg, we get a zero.
47 */
48#define __ARG_PLACEHOLDER_1 0,
49#define config_enabled(cfg) _config_enabled(cfg)
50#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value)
51#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0)
52#define ___config_enabled(__ignored, val, ...) val
53
54#include "config.h"
55
56#if defined(WITH_SSL) && !defined(WITH_LIBCRYPTO)
57# define WITH_LIBCRYPTO 1
58#endif
59
60#if defined(__CYGWIN__) || defined(__arm__) || defined(__SH4__) || defined(__MIPS__) || defined(__MIPSEL__) || defined(__powerpc__)
61# define CS_LOGFILE "/dev/tty"
62#endif
63
64#if defined(__AIX__) || defined(__SGI__) || defined(__OSF__) || defined(__HPUX__) || defined(__SOLARIS__) || defined(__APPLE__)
65# define NEED_DAEMON
66#endif
67
68#if defined(__AIX__) || defined(__SGI__) || defined(__OSF__) || defined(__HPUX__) || defined(__SOLARIS__) || defined(__CYGWIN__)
69# define NO_ENDIAN_H
70#endif
71
72#if defined(__AIX__) || defined(__SGI__)
73# define socklen_t unsigned long
74#endif
75
76#if defined(__SOLARIS__) || defined(__FreeBSD__)
77# define BSD_COMP
78#endif
79
80#if defined(__HPUX__)
81# define _XOPEN_SOURCE_EXTENDED
82#endif
83
84#if defined(__APPLE__) && !defined(s6_addr32)
85#define s6_addr32 __u6_addr.__u6_addr32
86#endif
87
88#ifdef __ANDROID__
89#ifndef in_port_t
90#define in_port_t uint16_t
91#endif
92#define tcdrain(fd) ioctl(fd, TCSBRK, 1)
93#endif
94
95#include "cscrypt/cscrypt.h"
96
97#ifndef uchar
98typedef unsigned char uchar;
99#endif
100
101#ifdef IPV6SUPPORT
102#define IN_ADDR_T struct in6_addr
103#define SOCKADDR sockaddr_storage
104#else
105#define IN_ADDR_T in_addr_t
106#define SOCKADDR sockaddr_in
107#endif
108
109#ifndef NO_ENDIAN_H
110 #if defined(__APPLE__)
111 #include <machine/endian.h>
112 #define __BYTE_ORDER __DARWIN_BYTE_ORDER
113 #define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
114 #define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
115 #elif defined(__FreeBSD__)
116 #include <sys/endian.h>
117 #define __BYTE_ORDER _BYTE_ORDER
118 #define __BIG_ENDIAN _BIG_ENDIAN
119 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
120 #else
121 #include <endian.h>
122 #include <byteswap.h>
123 #endif
124#endif
125
126#ifdef CARDREADER_PCSC
127 #if defined(__CYGWIN__)
128 #define __reserved
129 #define __nullnullterminated
130 #include <specstrings.h>
131 #include "extapi/cygwin/WinSCard.h"
132 #else
133 #include <PCSC/pcsclite.h>
134 #if defined(__APPLE__)
135 #include <PCSC/wintypes.h>
136 #else
137 #include <PCSC/reader.h>
138 #endif
139 #endif
140#endif
141
142#ifdef UNUSED
143#elif __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
144# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
145#elif defined(__LCLINT__)
146# define UNUSED(x) /*@unused@*/ x
147#else
148# define UNUSED(x) x
149#endif
150
151#if __GNUC__ >= 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
152# define MUST_CHECK_RESULT __attribute__((warn_unused_result))
153#endif
154
155#ifdef OK
156#undef OK
157#endif
158
159#ifdef ERROR
160#undef ERROR
161#endif
162
163#ifdef WITH_DEBUG
164# define call(arg) \
165 if (arg) { \
166 cs_debug_mask(D_TRACE, "ERROR, function call %s returns error.",#arg); \
167 return ERROR; \
168 }
169#else
170# define call(arg) \
171 if (arg) { \
172 return ERROR; \
173 }
174#endif
175
176//checking if (X) free(X) unneccessary since freeing a null pointer doesnt do anything
177#define NULLFREE(X) {if (X) {void *tmpX=X; X=NULL; free(tmpX); }}
178
179#define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
180
181/* ===========================
182 * constants
183 * =========================== */
184#define CS_VERSION "1.20-unstable_svn"
185#ifndef CS_SVN_VERSION
186# define CS_SVN_VERSION "test"
187#endif
188#ifndef CS_TARGET
189# define CS_TARGET "unknown"
190#endif
191#ifndef CS_CONFDIR
192#define CS_CONFDIR "/usr/local/etc"
193#endif
194#ifndef CS_LOGFILE
195#define CS_LOGFILE "/var/log/oscam.log"
196#endif
197#define CS_QLEN 128 // size of request queue
198#define CS_MAXCAIDTAB 32 // max. caid-defs/user
199#define CS_MAXTUNTAB 50 // max. betatunnel mappings
200#define CS_MAXPROV 32
201#define CS_MAXPORTS 32 // max server ports
202#define CS_MAXFILTERS 16
203#define CS_MAX_CAIDVALUETAB 16
204#define CS_CLIENT_HASHBUCKETS 32
205
206#define CS_ECMSTORESIZE 16 // use MD5()
207#define CS_EMMSTORESIZE 16 // use MD5()
208#define CS_CLIENT_TIMEOUT 5000
209#define CS_CLIENT_MAXIDLE 120
210#define CS_BIND_TIMEOUT 120
211#define CS_DELAY 0
212#define CS_ECM_RINGBUFFER_MAX 0x10 // max size for ECM last responsetimes ringbuffer. Keep this set to power of 2 values!
213
214#ifndef PTHREAD_STACK_MIN
215#define PTHREAD_STACK_MIN 64000
216#endif
217#define PTHREAD_STACK_SIZE PTHREAD_STACK_MIN+32768
218
219#define CS_MAXEMMBLOCKBYLEN 10
220
221#define CS_EMMCACHESIZE 127 //nr of EMMs that each client will cache; cache is per client, so memory-expensive...
222#define MSGLOGSIZE 64 //size of string buffer for a ecm to return messages
223
224#define D_TRACE 0x0001 // Generate very detailed error/trace messages per routine
225#define D_ATR 0x0002 // Debug ATR parsing, dump of ecm, cw
226#define D_READER 0x0004 // Debug Reader/Proxy Process
227#define D_CLIENT 0x0008 // Debug Client Process
228#define D_IFD 0x0010 // Debug IFD+protocol
229#define D_DEVICE 0x0020 // Debug Reader I/O
230#define D_EMM 0x0040 // Dumps EMM
231#define D_DVBAPI 0x0080 // Debug DVBAPI
232#define D_LB 0x0100 // Debug Loadbalancer
233#define D_CACHEEX 0x0200 // Debug CACHEEX
234#define D_CLIENTECM 0x0400 // Debug Client ECMs
235#define D_CSPCWC 0x0800 // Debug CSP/CWC
236#define D_CSPCWCFUL 0x1000 // Debug CSP/CWC FULL
237#define D_ALL_DUMP 0xFFFF // dumps all
238
239#define MAX_DEBUG_LEVELS 11
240
241#define R_DB2COM1 0x1 // Reader Dbox2 @ com1
242#define R_DB2COM2 0x2 // Reader Dbox2 @ com1
243#define R_SC8in1 0x3 // Reader Sc8in1 or MCR
244#define R_MP35 0x4 // AD-Teknik Multiprogrammer 3.5 and 3.6 (only usb tested)
245#define R_MOUSE 0x5 // Reader smartcard mouse
246/////////////////// phoenix readers which need baudrate setting and timings need to be guarded by OSCam: BEFORE R_MOUSE
247#define R_INTERNAL 0x6 // Reader smartcard intern
248/////////////////// internal readers (Dreambox, Coolstream, IPBox) are all R_INTERNAL, they are determined compile-time
249/////////////////// readers that do not reed baudrate setting and timings are guarded by reader itself (large buffer built in): AFTER R_SMART
250#define R_SMART 0x7 // Smartreader+
251#define R_PCSC 0x8 // PCSC
252/////////////////// proxy readers after R_CS378X
253#define R_CAMD35 0x20 // Reader cascading camd 3.5x
254#define R_CAMD33 0x21 // Reader cascading camd 3.3x
255#define R_NEWCAMD 0x22 // Reader cascading newcamd
256#define R_RADEGAST 0x23 // Reader cascading radegast
257#define R_CS378X 0x24 // Reader cascading camd 3.5x TCP
258#define R_CONSTCW 0x25 // Reader for Constant CW
259#define R_CSP 0x26 // Cache CSP
260#define R_GHTTP 0x27 // Reader ghttp
261/////////////////// peer to peer proxy readers after R_CCCAM
262#define R_GBOX 0x30 // Reader cascading gbox
263#define R_CCCAM 0x35 // Reader cascading cccam
264#define R_PANDORA 0x36 // Reader cascading pandora
265#define R_SERIAL 0x80 // Reader serial
266#define R_IS_NETWORK 0x60
267#define R_IS_CASCADING 0xE0
268
269#define is_network_reader(__X) (__X->typ & R_IS_NETWORK)
270#define is_cascading_reader(__X) (__X->typ & R_IS_CASCADING)
271
272//ECM rc codes:
273#define E_FOUND 0
274#define E_CACHE1 1
275#define E_CACHE2 2
276#define E_CACHEEX 3
277///////above is all found
278#define E_NOTFOUND 4 //for selection of found, use < E_NOTFOUND
279#define E_TIMEOUT 5
280#define E_SLEEPING 6
281#define E_FAKE 7
282#define E_INVALID 8
283#define E_CORRUPT 9
284#define E_NOCARD 10
285#define E_EXPDATE 11
286#define E_DISABLED 12
287#define E_STOPPED 13 //for selection of error, use <= E_STOPPED and exclude selection of found
288///////above is all notfound, some error or problem
289#define E_99 99 //this code is undocumented
290#define E_UNHANDLED 100 //for selection of unhandled, use >= E_UNHANDLED
291
292#define CS_MAX_MOD 20
293#define MOD_CONN_TCP 1
294#define MOD_CONN_UDP 2
295#define MOD_CONN_NET 3
296#define MOD_CONN_SERIAL 4
297#define MOD_NO_CONN 8
298
299#define MOD_CARDSYSTEM 16
300#define MOD_ADDON 32
301
302#define EMM_UNIQUE 1
303#define EMM_SHARED 2
304#define EMM_GLOBAL 4
305#define EMM_UNKNOWN 8
306
307//Listener Types
308#define LIS_CAMD33TCP 1
309#define LIS_CAMD35UDP 2
310#define LIS_CAMD35TCP 4
311#define LIS_NEWCAMD 8
312#define LIS_CCCAM 16
313#define LIS_GBOX 32
314#define LIS_RADEGAST 64
315#define LIS_DVBAPI 128
316#define LIS_CONSTCW 256
317#define LIS_SERIAL 1024
318#define LIS_CSPUDP 2048
319
320//EMM types:
321#define UNKNOWN 0
322#define UNIQUE 1
323#define SHARED 2
324#define GLOBAL 3
325
326#define PIP_ID_ECM 0
327#define PIP_ID_EMM 1
328#define PIP_ID_CIN 2 // CARD_INFO
329#define PIP_ID_UDP 3
330#define PIP_ID_MAX PIP_ID_UDP
331#define PIP_ID_ERR (-1)
332#define PIP_ID_NUL (-2)
333
334#define cdiff *c_start
335
336#define NCD_AUTO 0
337#define NCD_524 1
338#define NCD_525 2
339
340// moved from reader-common.h
341#define UNKNOWN 0
342#define CARD_NEED_INIT 1
343#define CARD_INSERTED 2
344#define CARD_FAILURE 3
345#define NO_CARD 4
346
347// moved from stats
348#define DEFAULT_REOPEN_SECONDS 900
349#define DEFAULT_MIN_ECM_COUNT 5
350#define DEFAULT_MAX_ECM_COUNT 500
351#define DEFAULT_NBEST 1
352#define DEFAULT_NFB 1
353#define DEFAULT_RETRYLIMIT 800
354#define DEFAULT_LB_MODE 0
355#define DEFAULT_LB_STAT_CLEANUP 336
356#define DEFAULT_LB_REOPEN_MODE 0
357#define DEFAULT_UPDATEINTERVAL 240
358#define DEFAULT_LB_AUTO_BETATUNNEL 1
359#define DEFAULT_LB_AUTO_BETATUNNEL_MODE 0
360#define DEFAULT_LB_AUTO_BETATUNNEL_PREFER_BETA 50
361
362#define DEFAULT_MAX_CACHE_TIME 15
363#define DEFAULT_MAX_CACHE_COUNT 1000
364
365#define DEFAULT_LB_AUTO_TIMEOUT 0
366#define DEFAULT_LB_AUTO_TIMEOUT_P 30
367#define DEFAULT_LB_AUTO_TIMEOUT_T 300
368
369#define DEFAULT_GBOX_MAX_DIST 2
370#define DEFAULT_GBOX_MAX_ECM_SEND 3
371#define DEFAULT_GBOX_RECONNECT 300
372#define CS_GBOX_MAX_LOCAL_CARDS 16
373
374enum {E1_GLOBAL=0, E1_USER, E1_READER, E1_SERVER, E1_LSERVER};
375
376//LB blocking events:
377enum {E2_GLOBAL=0, E2_GROUP, E2_CAID, E2_IDENT, E2_CLASS, E2_CHID, E2_QUEUE, E2_OFFLINE,
378 E2_SID, E2_CCCAM_NOCARD,
379 //From here only LB nonblocking events:
380 E2_CCCAM_NOK1, E2_CCCAM_NOK2, E2_CCCAM_LOOP, E2_WRONG_CHKSUM, E2_RATELIMIT};
381
382#define LB_NONBLOCK_E2_FIRST E2_CCCAM_NOK1
383
384#define CTA_RES_LEN 512
385
386#define MAX_ATR_LEN 33 // max. ATR length
387#define MAX_HIST 15 // max. number of historical characters
388
389#define MAX_SIDBITS 64 // max services
390#define SIDTABBITS uint64_t // 64bit type for services, if a system does not support this type,
391 // please use a define and define it as uint32_t / MAX_SIDBITS 32
392
393#define BAN_UNKNOWN 1 // Failban mask for anonymous/ unknown contact
394#define BAN_DISABLED 2 // Failban mask for Disabled user
395#define BAN_SLEEPING 4 // Failban mask for sleeping user
396#define BAN_DUPLICATE 8 // Failban mask for duplicate user
397
398#define MAX_HTTP_DYNDNS 3 // maximum allowed Dyndns addresses for webif access
399
400#define CHECK_WAKEUP 1
401#define CHECK_ANTICASCADER 2
402#define CHECK_ECMCACHE 3
403
404#define AVAIL_CHECK_CONNECTED 0
405#define AVAIL_CHECK_LOADBALANCE 1
406
407#define ECM_FMT_LEN 109 //64
408#define CXM_FMT_LEN 209 // 160
409
410#define LB_MAX_STAT_TIME 10
411
412#if defined(__APPLE__) || defined(__FreeBSD__)
413#define OSCAM_SIGNAL_WAKEUP SIGCONT
414#else
415#define OSCAM_SIGNAL_WAKEUP SIGRTMAX-2
416#endif
417
418#define READER_ACTIVE 0x01
419#define READER_FALLBACK 0x02
420#define READER_LOCAL 0x04
421#define READER_CACHEEX 0x08
422
423#define REQUEST_SENT 0x10
424#define REQUEST_ANSWERED 0x20
425
426/* ===========================
427 * Default Values
428 * =========================== */
429#define DEFAULT_INACTIVITYTIMEOUT 0
430#define DEFAULT_TCP_RECONNECT_TIMEOUT 30
431#define DEFAULT_NCD_KEEPALIVE 0
432
433#define DEFAULT_CC_MAXHOPS 10
434#define DEFAULT_CC_RESHARE -1 // Use global cfg
435#define DEFAULT_CC_IGNRSHR -1 // Use global cfg
436#define DEFAULT_CC_STEALTH -1 // Use global cfg
437#define DEFAULT_CC_KEEPALIVE 0
438#define DEFAULT_CC_RECONNECT 12000
439#define DEFAULT_CC_RECV_TIMEOUT 2000
440
441#define DEFAULT_AC_USERS -1 // Use global cfg
442#define DEFAULT_AC_PENALTY -1 // Use global cfg
443
444// Return MPEG section length
445#define SCT_LEN(sct) (3+((sct[1]&0x0f)<<8)+sct[2])
446// Used by readers
447#define MAX_LEN 256
448
449#define NO_CAID_VALUE 0xfffe
450#define NO_SRVID_VALUE 0xfffe
451
452// If NULL return empty string
453#define ESTR(x) ((x) ? (x) : "")
454
455#ifndef MAX
456#define MAX(a,b) ((a) > (b) ? (a) : (b))
457#endif
458
459#ifndef MIN
460#define MIN(a,b) ((a) < (b) ? (a) : (b))
461#endif
462
463/*
464 See: http://stackoverflow.com/questions/10269685/kernels-container-of-any-way-to-make-it-iso-conforming
465 http://www.kroah.com/log/linux/container_of.html
466*/
467#define container_of(ptr, type, member) \
468 ((type *) ((char *) (ptr) - offsetof(type, member) + \
469 (&((type *) 0)->member == (ptr)) * 0))
470
471/* ===========================
472 * global structures
473 * =========================== */
474struct timeb {
475 time_t time;
476 uint16_t millitm;
477};
478
479typedef struct cs_mutexlock {
480 int32_t timeout;
481 pthread_mutex_t lock;
482 pthread_cond_t writecond, readcond;
483 const char *name;
484 int8_t flag;
485 int16_t writelock, readlock;
486} CS_MUTEX_LOCK;
487
488#include "oscam-llist.h"
489
490typedef struct s_caidvaluetab {
491 uint16_t n;
492 uint16_t caid[CS_MAX_CAIDVALUETAB];
493 uint16_t value[CS_MAX_CAIDVALUETAB];
494} CAIDVALUETAB;
495
496typedef struct s_classtab {
497 uchar an;
498 uchar bn;
499 uchar aclass[31];
500 uchar bclass[31];
501} CLASSTAB;
502
503typedef struct s_caidtab {
504 uint16_t caid[CS_MAXCAIDTAB];
505 uint16_t mask[CS_MAXCAIDTAB];
506 uint16_t cmap[CS_MAXCAIDTAB];
507} CAIDTAB;
508
509typedef struct s_tuntab {
510 uint16_t n;
511 uint16_t bt_caidfrom[CS_MAXTUNTAB];
512 uint16_t bt_caidto[CS_MAXTUNTAB];
513 uint16_t bt_srvid[CS_MAXTUNTAB];
514} TUNTAB;
515
516typedef struct s_sidtab {
517 char label[64];
518 uint16_t num_caid;
519 uint16_t num_provid;
520 uint16_t num_srvid;
521 uint16_t *caid;
522 uint32_t *provid;
523 uint16_t *srvid;
524 struct s_sidtab *next;
525} SIDTAB;
526
527typedef struct s_filter {
528 uint16_t caid;
529 uchar nprids;
530 uint32_t prids[CS_MAXPROV];
531} FILTER;
532
533typedef struct s_ftab {
534 int32_t nfilts;
535 FILTER filts[CS_MAXFILTERS];
536} FTAB;
537
538typedef struct s_port {
539 int32_t fd;
540 int32_t s_port;
541 int32_t ncd_key_is_set; //0 or 1
542 uint8_t ncd_key[14];
543 FTAB ftab;
544} PORT;
545
546typedef struct s_ptab {
547 int32_t nports;
548 PORT ports[CS_MAXPORTS];
549} PTAB;
550
551typedef struct aes_entry {
552 uint16_t keyid;
553 uint16_t caid;
554 uint32_t ident;
555 uchar plainkey[16];
556 AES_KEY key;
557 struct aes_entry *next;
558} AES_ENTRY;
559
560struct s_ecm {
561 uchar ecmd5[CS_ECMSTORESIZE];
562 uchar cw[16];
563 uint16_t caid;
564 uint64_t grp;
565 struct s_reader *reader;
566 int32_t rc;
567 time_t time;
568};
569
570struct s_emm {
571 uchar emmd5[CS_EMMSTORESIZE];
572 uchar type;
573 int32_t count;
574};
575
576typedef struct v_ban { // Failban listmember
577 int32_t v_count;
578 IN_ADDR_T v_ip;
579 int32_t v_port;
580 time_t v_time;
581 char *info;
582} V_BAN;
583
584typedef struct s_cacheex_stat_entry { // Cacheex stats listmember
585 int32_t cache_count;
586 time_t cache_last;
587 uint16_t cache_caid;
588 uint16_t cache_srvid;
589 uint32_t cache_prid;
590 int8_t cache_direction; // 0 = push / 1 = got
591} S_CACHEEX_STAT_ENTRY;
592
593typedef struct s_entitlement { // contains entitlement Info
594 uint64_t id; // the element ID
595 uint32_t type; // enumerator for tier,chid whatever
596 // 0="", 1="Package", 2="PPV-Event", 3="chid", 4="tier", 5 = "class", 6 = "PBM". 7 = "seca-admin"
597 uint16_t caid; // the caid of element
598 uint32_t provid; // the provid of element
599 uint32_t class; // the class needed for some systems
600 time_t start; // startdate
601 time_t end; // enddate
602} S_ENTITLEMENT;
603
604struct s_client ;
605struct ecm_request_t ;
606struct emm_packet_t ;
607struct s_ecm_answer ;
608
609struct s_module {
610 int8_t active;
611 int8_t type;
612 int8_t large_ecm_support;
613 int16_t listenertype;
614 char *desc;
615 //int32_t s_port;
616 IN_ADDR_T s_ip;
617 uint16_t bufsize;
618 void *(*s_handler)(struct s_client *, uchar *, int32_t);
619 void (*s_init)(struct s_client *);
620 int32_t (*recv)(struct s_client *, uchar *, int32_t);
621 void (*send_dcw)(struct s_client*, struct ecm_request_t *);
622 void (*cleanup)(struct s_client*);
623 int32_t (*c_recv_chk)(struct s_client*, uchar *, int32_t *, uchar *, int32_t);
624 int32_t (*c_init)(struct s_client*);
625 int32_t (*c_send_ecm)(struct s_client *, struct ecm_request_t *, uchar *);
626 int32_t (*c_send_emm)(struct emm_packet_t *);
627 int32_t (*c_available)(struct s_reader *, int32_t, struct ecm_request_t *); //Schlocke: available check for load-balancing,
628 // params:
629 // rdr (reader to check)
630 // int32_t checktype (0=return connected, 1=return loadbalance-avail) return int
631 void (*c_idle)(void); // Schlocke: called when reader is idle
632 void (*s_idle)(struct s_client*);
633 void (*c_card_info)(void); // Schlocke: request card infos
634#ifdef CS_CACHEEX
635 int32_t (*c_cache_push)(struct s_client*, struct ecm_request_t *); //Cache push
636 int32_t (*c_cache_push_chk)(struct s_client*, struct ecm_request_t *); //Cache push Node Check, 0=no push
637#endif
638 int32_t c_port;
639 PTAB *ptab;
640 int32_t num;
641};
642
643struct s_ATR ;
644
645struct s_cardreader
646{
647 char *desc;
648 int32_t (*reader_init)(struct s_reader*);
649 int32_t (*get_status)(struct s_reader*, int*);
650 int32_t (*activate)(struct s_reader*, struct s_ATR *);
651 int32_t (*transmit)(struct s_reader*, unsigned char *sent, uint32_t size, uint32_t delay, uint32_t timeout);
652 int32_t (*receive)(struct s_reader*, unsigned char *data, uint32_t size, uint32_t delay, uint32_t timeout);
653 int32_t (*lock_init)(struct s_reader *);
654 void (*lock)(struct s_reader *);
655 void (*unlock)(struct s_reader *);
656 int32_t (*close)(struct s_reader*);
657 int32_t (*set_parity)(struct s_reader*, uchar parity);
658 // FIXME: All parameters passed to write_settingsX should be put in a struct
659 int32_t (*write_settings)(struct s_reader*,
660 uint32_t ETU,
661 uint32_t EGT,
662 unsigned char P,
663 unsigned char I,
664 uint16_t Fi,
665 unsigned char Di,
666 unsigned char Ni);
667 // FIXME: write_settings2 is used by coolstream reader
668 int32_t (*write_settings2)(struct s_reader *, uint32_t EGT, uint32_t BGT);
669 // FIXME: write_settings3 is used by sci reader
670 int32_t (*write_settings3)(struct s_reader *, uint32_t ETU, uint32_t WWT, uint32_t I);
671 int32_t (*set_protocol)(struct s_reader*,
672 unsigned char * params,
673 uint32_t *length,
674 uint32_t len_request);
675 int32_t (*set_baudrate)(struct s_reader*,
676 uint32_t baud); //set only for readers which need baudrate setting and timings need to be guarded by OSCam
677 int32_t (*card_write)(struct s_reader *pcsc_reader,
678 const uchar *buf,
679 unsigned char *cta_res,
680 uint16_t *cta_lr,
681 int32_t l);
682 void (*display_msg)(struct s_reader *, char *msg);
683 void (*set_transmit_timeout)(struct s_reader *);
684
685 int32_t (*do_reset)(struct s_reader *, struct s_ATR *,
686 int32_t (*rdr_activate_card)(struct s_reader *, struct s_ATR *, uint16_t deprecated),
687 int32_t (*rdr_get_cardsystem)(struct s_reader *, struct s_ATR *));
688
689 bool (*set_DTS_RTS)(struct s_reader *, int32_t *dtr, int32_t *rts);
690
691 int32_t typ; // fixme: workaround, remove when all old code is converted
692
693 int8_t max_clock_speed; // 1 for reader->typ > R_MOUSE
694 int8_t need_inverse; // 0 = reader does inversing; 1 = inversing done by oscam
695 //io_serial config
696 int8_t flush;
697 int8_t read_written; // 1 = written bytes has to read from device
698 int8_t timings_in_etu; // timings in ETU instead of us
699 bool skip_extra_atr_parsing;
700 bool skip_t1_command_retries;
701 bool skip_setting_ifsc;
702};
703
704struct s_cardsystem {
705 int8_t active;
706 char *desc;
707 int32_t (*card_init)(struct s_reader *reader, struct s_ATR *);
708 int32_t (*card_info)(struct s_reader *);
709 int32_t (*do_ecm)(struct s_reader *, const struct ecm_request_t *, struct s_ecm_answer *);
710 int32_t (*do_emm)(struct s_reader *, struct emm_packet_t *);
711 void (*post_process)(struct s_reader *);
712 int32_t (*get_emm_type)(struct emm_packet_t *, struct s_reader *);
713 void (*get_emm_filter)(struct s_reader * rdr, uchar *filter);
714 uint16_t caids[2];
715};
716
717struct s_irdeto_quess {
718 int32_t b47;
719 uint16_t caid;
720 uint16_t sid;
721 struct s_irdeto_quess *next;
722};
723
724#define MAX_ECM_SIZE 512
725
726typedef struct ecm_request_t {
727 uchar ecm[MAX_ECM_SIZE];
728 uchar cw[16];
729 uchar ecmd5[CS_ECMSTORESIZE];
730 int16_t ecmlen;
731 uint16_t caid;
732 uint16_t ocaid; //original caid, used for betatunneling
733 uint16_t srvid;
734 uint16_t onid;
735 uint16_t tsid;
736 uint32_t ens;
737 uint16_t chid;
738 uint16_t pid;
739 uint16_t idx;
740 uint32_t prid;
741 struct s_reader *selected_reader;
742 struct s_ecm_answer *matching_rdr; //list of matching readers
743 const struct s_reader *fallback; //fallback is the first fallback reader in the list matching_rdr
744 struct s_client *client; //contains pointer to 'c' client while running in 'r' client
745 uint64_t grp;
746 int32_t msgid; // client pending table index
747 uint8_t stage; // processing stage in server module
748 int8_t rc;
749 uint8_t rcEx;
750 struct timeb tps; // incoming time stamp
751 uchar locals_done;
752 int8_t btun; // mark er as betatunneled
753 uint16_t reader_avail; // count of available readers
754 uint16_t reader_count; // count of contacted readers
755 uint16_t reader_requested; // count of real requested readers
756 int8_t checked; //for doublecheck
757 uchar cw_checked[16]; //for doublecheck
758 struct s_reader *origin_reader;
759
760#if defined MODULE_CCCAM
761 void *origin_card; // CCcam preferred card!
762#endif
763
764#if defined MODULE_GBOX
765 uint32_t gbox_crc; // rcrc for gbox, used to identify ECM task in peer responses
766 uint16_t gbox_ecm_id;
767 uint8_t gbox_ecm_ok;
768#endif
769
770 void *src_data;
771 struct ecm_request_t *ecmcacheptr; // Pointer to ecm-cw-rc-cache!
772#ifdef CS_CACHEEX
773 uchar cacheex_done;
774 struct s_client *cacheex_src; // Cacheex origin
775 int8_t cacheex_pushed; // to avoid duplicate pushs
776 int32_t csp_hash; // csp has its own hash
777 LLIST *csp_lastnodes; // last 10 Cacheex nodes atm cc-proto-only
778 uint32_t cacheex_wait_time; // cacheex wait time in ms
779 struct timeb cacheex_wait; // incoming time stamp (tps) + cacheex wait time
780#endif
781 char msglog[MSGLOGSIZE];
782 struct ecm_request_t *parent;
783 struct ecm_request_t *next;
784} ECM_REQUEST;
785
786
787struct s_ecm_answer {
788 uint8_t status;
789 struct s_reader *reader;
790 ECM_REQUEST *er;
791 int8_t rc;
792 uint8_t rcEx;
793 uchar cw[16];
794 char msglog[MSGLOGSIZE];
795#ifdef WITH_LB
796 int32_t value;
797 int32_t time;
798#endif
799 struct s_ecm_answer *next;
800};
801
802struct s_acasc_shm {
803 uint16_t ac_count : 15;
804 uint16_t ac_deny : 1;
805};
806
807struct s_acasc {
808 uint16_t stat[10];
809 uchar idx; // current active index in stat[]
810};
811
812struct s_cwresponse {
813 int32_t duration;
814 time_t timestamp;
815 int32_t rc;
816};
817
818struct s_cascadeuser {
819 uint16_t caid;
820 uint32_t prid;
821 uint16_t srvid;
822 time_t time;
823 int8_t cwrate;
824};
825
826typedef struct sidtabs {
827 SIDTABBITS ok; // positive services
828 SIDTABBITS no; // negative services
829} SIDTABS;
830
831struct s_client {
832 uint32_t tid;
833 int8_t init_done;
834 pthread_mutex_t thread_lock;
835 int8_t thread_active;
836 int8_t kill;
837 LLIST *joblist;
838 IN_ADDR_T ip;
839 in_port_t port;
840 time_t login; // connection
841 time_t logout; // disconnection
842 time_t last;
843 time_t lastswitch;
844 time_t lastemm;
845 time_t lastecm;
846 time_t expirationdate;
847 int32_t allowedtimeframe[2];
848 int8_t c35_suppresscmd08;
849 uint8_t c35_sleepsend;
850 int8_t ncd_keepalive;
851 int8_t disabled;
852 uint64_t grp;
853 int8_t crypted;
854 int8_t dup;
855 LLIST *aureader_list;
856 int8_t autoau;
857 int8_t monlvl;
858 CAIDTAB ctab;
859 TUNTAB ttab;
860 SIDTABS sidtabs;
861 int8_t 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
862 uint8_t module_idx;
863 uint16_t last_srvid;
864 uint16_t last_caid;
865 struct s_srvid *last_srvidptr;
866 int32_t tosleep;
867 struct s_auth *account;
868 int32_t udp_fd;
869 struct SOCKADDR udp_sa;
870 socklen_t udp_sa_len;
871 int8_t log;
872 int32_t logcounter;
873 int32_t cwfound; // count found ECMs per client
874 int32_t cwcache; // count ECMs from cache1/2 per client
875 int32_t cwnot; // count not found ECMs per client
876 int32_t cwtun; // count betatunneled ECMs per client
877 int32_t cwignored; // count ignored ECMs per client
878 int32_t cwtout; // count timeouted ECMs per client
879 int32_t cwlastresptime; //last Responsetime (ms)
880#ifdef CW_CYCLE_CHECK
881 int32_t cwcycledchecked; // count checked cwcycles per client
882 int32_t cwcycledok; // count pos checked cwcycles per client
883 int32_t cwcyclednok; // count neg checked cwcycles per client
884 int32_t cwcycledign; // count ign cwcycles per client
885#endif
886 int32_t emmok; // count EMM ok
887 int32_t emmnok; // count EMM nok
888 int8_t pending; // number of ECMs pending
889#ifdef CS_CACHEEX
890 int32_t cwcacheexpush; // count pushed ecms/cws
891 int32_t cwcacheexgot; // count got ecms/cws
892 int32_t cwcacheexhit; // count hit ecms/cws
893 LLIST *ll_cacheex_stats; // List for Cacheex statistics
894 int8_t cacheex_maxhop;
895 int32_t cwcacheexerr; //cw=00 or chksum wrong
896 int32_t cwcacheexerrcw; //Same Hex, different CW
897#endif
898
899#ifdef WEBIF
900 struct s_cwresponse cwlastresptimes[CS_ECM_RINGBUFFER_MAX]; //ringbuffer for last 20 times
901 int32_t cwlastresptimes_last; // ringbuffer pointer
902 int8_t wihidden; // hidden in webinterface status
903 char lastreader[64]; // last cw got from this reader
904#endif
905
906 uchar ucrc[4]; // needed by monitor and used by camd35
907 uint32_t pcrc; // password crc
908 AES_KEY aeskey; // encryption key needed by monitor and used by camd33, camd35
909 AES_KEY aeskey_decrypt; // decryption key needed by monitor and used by camd33, camd35
910 uint16_t ncd_msgid;
911 uint16_t ncd_client_id;
912 uchar ncd_skey[16]; //Also used for camd35 Cacheex to store remote node id
913
914#ifdef MODULE_CCCAM
915 void *cc;
916#endif
917
918#ifdef MODULE_GBOX
919 void *gbox;
920 uint8_t gbox_cw_id[2];
921 uint8_t gbox_peer_id[2];
922 uint8_t gbox_ver;
923#endif
924
925#ifdef MODULE_GHTTP
926 void *ghttp;
927#endif
928
929 int32_t port_idx; // index in server ptab
930 int32_t ncd_server; // newcamd server
931
932#ifdef CS_ANTICASC
933 int32_t ac_fakedelay; // When this is -1, the global ac_fakedelay is used
934 uint16_t ac_limit;
935 int8_t ac_penalty;
936 struct s_acasc_shm acasc;
937#endif
938
939 FTAB fchid;
940 FTAB ftab; // user [caid] and ident filter
941 CLASSTAB cltab;
942
943 int32_t pfd; // Primary FD, must be closed on exit
944 struct s_reader *reader; // points to s_reader when cl->typ='r'
945
946 ECM_REQUEST *ecmtask;
947 struct s_emm *emmcache;
948
949 pthread_t thread;
950
951#ifdef MODULE_SERIAL
952 struct s_serial_client *serialdata;
953#endif
954 //reader common
955 int32_t last_idx;
956 uint16_t idx;
957 int8_t rotate;
958
959 int8_t ncd_proto;
960 uint8_t ncd_header[12];
961
962 //camd35
963 uchar upwd[64];
964 int8_t is_udp;
965 int8_t stopped;
966 uint16_t lastcaid;
967 uint16_t lastsrvid;
968 int32_t lastpid;
969 time_t emm_last;
970 int8_t disable_counter;
971 uchar lastserial[8];
972
973 //monitor
974 int8_t auth;
975
976 //oscam.c
977 struct timeval tv;
978
979 // Failban value set bitwise - compared with BAN_
980 int32_t failban;
981 int8_t cleaned;
982
983 LLIST *cascadeusers; //s_cascadeuser
984
985#ifdef MODULE_PANDORA
986 int32_t pand_autodelay;
987 uint8_t pand_send_ecm;
988 uchar pand_ignore_ecm;
989 uchar pand_md5_key[16];
990#endif
991
992 struct s_client *next; //make client a linked list
993 struct s_client *nexthashed;
994};
995
996struct geo_cache { //for viaccess var in s_reader:
997 uint32_t provid;
998 uchar geo[256];
999 uchar geo_len;
1000 int32_t number_ecm;
1001};
1002
1003struct s_CmdTabEntry { // for videoguard in s_reader
1004 unsigned char cla;
1005 unsigned char cmd;
1006 unsigned char len;
1007 unsigned char mode;
1008};
1009
1010struct s_CmdTab {
1011 unsigned char index;
1012 unsigned char size;
1013 unsigned char Nentries;
1014 unsigned char dummy;
1015 struct s_CmdTabEntry e[1];
1016};
1017
1018struct s_ecmWhitelist {
1019 uint16_t caid;
1020 struct s_ecmWhitelistIdent *idents;
1021 struct s_ecmWhitelist *next;
1022};
1023
1024struct s_ecmWhitelistIdent {
1025 uint32_t ident;
1026 struct s_ecmWhitelistLen *lengths;
1027 struct s_ecmWhitelistIdent *next;
1028};
1029
1030struct s_ecmWhitelistLen {
1031 int16_t len;
1032 struct s_ecmWhitelistLen *next;
1033};
1034
1035struct s_ecmHeaderwhitelist {
1036 uint16_t caid;
1037 uint32_t provid;
1038 uchar header[20];
1039 int16_t len;
1040 struct s_ecmHeaderwhitelist *next;
1041};
1042
1043//ratelimit
1044struct ecmrl {
1045 uint16_t srvid;
1046 time_t last;
1047};
1048#define MAXECMRATELIMIT 20
1049
1050struct s_sc8in1_display {
1051 char *text;
1052 uint16_t text_length;
1053 uint16_t char_change_time;
1054 uint16_t last_char;
1055 uint8_t blocking;
1056 struct s_sc8in1_display *next;
1057};
1058struct s_sc8in1_config {
1059 struct termios stored_termio[8];
1060 uint16_t current_slot;
1061 uint32_t current_baudrate;
1062 struct s_reader *current_reader;
1063 unsigned char cardstatus;
1064 unsigned char mcr_type;
1065 CS_MUTEX_LOCK sc8in1_lock;
1066 struct s_sc8in1_display *display;
1067 CS_MUTEX_LOCK sc8in1_display_lock;
1068 unsigned char display_running;
1069 pthread_t display_thread;
1070};
1071
1072#ifdef CS_CACHEEX
1073typedef struct ce_csp_tab {
1074 uint16_t n;
1075 int32_t caid[CS_MAXCAIDTAB];
1076 int32_t cmask[CS_MAXCAIDTAB];
1077 int32_t prid[CS_MAXCAIDTAB];
1078 int32_t srvid[CS_MAXCAIDTAB];
1079 int16_t awtime[CS_MAXCAIDTAB];
1080 int16_t dwtime[CS_MAXCAIDTAB];
1081} CECSPVALUETAB;
1082
1083typedef struct ce_csp_t {
1084 int8_t mode;
1085 int8_t maxhop;
1086 CECSPVALUETAB filter_caidtab;
1087 uint8_t allow_request;
1088 uint8_t drop_csp;
1089} CECSP;
1090#endif
1091
1092struct s_reader //contains device info, reader info and card info
1093{
1094 uint8_t changes_since_shareupdate;
1095 int32_t resetcycle; // ECM until reset
1096 int32_t resetcounter; // actual count
1097 uint32_t auprovid; // AU only for this provid
1098 int8_t audisabled; // exclude reader from auto AU
1099 int8_t smargopatch;
1100 struct s_client *client; // pointer to 'r'client this reader is running in
1101 LLIST *ll_entitlements; // entitlements
1102 int8_t enable;
1103 int8_t active;
1104 int8_t dropbadcws; // Schlocke: 1=drops cw if checksum is wrong. 0=fix checksum (default)
1105 int8_t disablecrccws; // 1=disable cw checksum test. 0=enable checksum check
1106 int8_t fd_error;
1107 uint64_t grp;
1108 int8_t fallback;
1109#ifdef CS_CACHEEX
1110 CECSP cacheex; //CacheEx Settings
1111#endif
1112 int32_t typ;
1113#ifdef WITH_COOLAPI
1114 int32_t cool_timeout_init; // read/transmit timeout while init for coolstream internal reader
1115 int32_t cool_timeout_after_init; // read/transmit timeout after init for coolstream internal reader
1116#endif
1117 char label[64];
1118#ifdef WEBIF
1119 char *description;
1120#endif
1121 char device[128];
1122 void *spec_dev; // pointer to structure that contains specific device data
1123 uint16_t slot; // in case of multiple slots like sc8in1; first slot = 1
1124 int32_t handle; // device handle
1125 int32_t fdmc; // device handle for multicam
1126#ifdef WITH_STAPI
1127 uint32_t stsmart_handle; // device handle for stsmart driver
1128#endif
1129 char pcsc_name[128];
1130 int8_t pcsc_has_card;
1131 int32_t detect;
1132 int32_t mhz; // actual clock rate of reader in 10khz steps
1133 int32_t cardmhz; // standard clock speed your card should have in 10khz steps; normally 357 but for Irdeto cards 600
1134 int32_t divider; // PLL divider for internal readers
1135 int32_t r_port;
1136 char r_usr[64];
1137 char r_pwd[64];
1138 char l_pwd[64];
1139 int32_t l_port;
1140 CAIDTAB ctab;
1141 uint32_t boxid;
1142 int8_t nagra_read; // read nagra ncmed records: 0 Disabled (default), 1 read all records, 2 read valid records only
1143 uint8_t boxkey[8]; // n3 boxkey 8byte
1144 char country_code[3]; // irdeto country code.
1145 int8_t force_irdeto;
1146 uchar rsa_mod[120]; // rsa modulus for nagra cards.
1147 uchar atr[64];
1148 uchar card_atr[64]; // ATR readed from card
1149 int8_t card_atr_length; // length of ATR
1150 int32_t atrlen;
1151 SIDTABS sidtabs;
1152 uchar hexserial[8];
1153 int32_t nprov;
1154 uchar prid[CS_MAXPROV][8];
1155 uchar availkeys[CS_MAXPROV][16]; // viaccess; misused in seca, if availkeys[PROV][0]=0 then expired, 1 then valid.
1156 uchar sa[CS_MAXPROV][4]; // viaccess & seca
1157 uint16_t acs; // irdeto
1158 uint16_t caid;
1159 uint16_t b_nano;
1160 uint16_t s_nano;
1161 int8_t ecmcommand; // used for filtering nagra bad ecm commands
1162 uchar ecmcommandcache[4]; // cachebuff for ecm commands
1163 int32_t blockemm;
1164 int32_t saveemm;
1165 int16_t blockemmbylen[CS_MAXEMMBLOCKBYLEN];
1166 char *emmfile;
1167 char pincode[5];
1168 int32_t ucpk_valid;
1169 int8_t logemm;
1170 int8_t cachemm;
1171 int16_t rewritemm;
1172 int8_t card_status;
1173 int8_t deprecated; //if 0 ATR obeyed, if 1 default speed (9600) is chosen; for devices that cannot switch baudrate
1174 struct s_module ph;
1175 struct s_cardreader crdr;
1176 struct s_cardsystem csystem;
1177 uint8_t ncd_key[14];
1178 uchar ncd_skey[16];
1179 int8_t ncd_connect_on_init;
1180 int8_t ncd_disable_server_filt;
1181 int8_t ncd_proto;
1182 int8_t currenthops; // number of hops (cccam & gbox)
1183#ifdef MODULE_CCCAM
1184 char cc_version[7]; // cccam version
1185 char cc_build[7]; // cccam build number
1186 int8_t cc_maxhops; // cccam max distance
1187 int8_t cc_mindown; // cccam min downhops
1188 int8_t cc_want_emu; // Schlocke: Client want to have EMUs, 0 - NO; 1 - YES
1189 uint32_t cc_id;
1190 int8_t cc_keepalive;
1191 int8_t cc_hop; // For non-cccam reader: hop for virtual cards
1192 int8_t cc_reshare;
1193 int32_t cc_reconnect; //reconnect on ecm-request timeout
1194#endif
1195 int8_t tcp_connected;
1196 int32_t tcp_ito; // inactivity timeout
1197 int32_t tcp_rto; // reconnect timeout
1198 struct timeb tcp_block_connect_till; //time tcp connect ist blocked
1199 int32_t tcp_block_delay; //incrementing block time
1200 time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect )
1201 time_t last_s; // send
1202 time_t last_check; // last checked
1203 FTAB fchid;
1204 FTAB ftab;
1205 CLASSTAB cltab;
1206 struct s_ecmWhitelist *ecmWhitelist;
1207 struct s_ecmHeaderwhitelist *ecmHeaderwhitelist; // ECM Header Whitelist
1208 int32_t brk_pos;
1209 int32_t msg_idx;
1210 int32_t secatype; // 0=not determined, 2=seca2, 3=nagra(~seca3) this is only valid for localreaders!
1211 double worketu; // in us for internal and external readers calculated (1/D)*(F/cardclock)*1000000
1212 uint32_t maxreadtimeout; // in us
1213 uint32_t minreadtimeout; // in us
1214 uint32_t maxwritetimeout; // in us
1215 uint32_t minwritetimeout; // in us
1216#if defined(WEBIF) || defined(LCDSUPPORT)
1217 int32_t emmwritten[4]; // count written EMM
1218 int32_t emmskipped[4]; // count skipped EMM
1219 int32_t emmerror[4]; // count error EMM
1220 int32_t emmblocked[4]; // count blocked EMM
1221 int32_t lbvalue; // loadbalance Value
1222#endif
1223#ifdef CARDREADER_PCSC
1224 SCARDCONTEXT hContext;
1225 SCARDHANDLE hCard;
1226 DWORD dwActiveProtocol;
1227#endif
1228#ifdef CARDREADER_SMART
1229 struct s_sr_config *sr_config;
1230#endif
1231#ifdef WITH_AZBOX
1232 int32_t azbox_mode;
1233#endif
1234 int32_t use_gpio; // Should this reader use GPIO functions
1235 int gpio_outen; // fd of opened /dev/gpio/outen
1236 int gpio_out; // fd of opened /dev/gpio/out
1237 int gpio_in; // fd of opened /dev/gpio/in
1238 uint32_t gpio; // gpio addr
1239 ////variables from icc_async.h start
1240#ifdef WITH_CARDREADER
1241 int32_t convention; // Convention of this ICC
1242 unsigned char protocol_type; // Type of protocol
1243 uint32_t current_baudrate; // (for overclocking uncorrected) baudrate to prevent unnecessary conversions from/to termios structure
1244 uint32_t read_timeout; // Max timeout (ms) to receive characters
1245 uint32_t block_delay; // Delay (ms) after starting to transmit
1246 uint32_t char_delay; // Delay (ms) after transmiting each sucesive char
1247 ////variables from io_serial.h
1248 int32_t written; // keep score of how much bytes are written to serial port, since they are echoed back they have to be read
1249#endif
1250 uint32_t BWT,CWT; // (for overclocking uncorrected) block waiting time, character waiting time, in ETU
1251 ////variables from protocol_t1.h
1252 uint16_t ifsc; // Information field size for the ICC
1253 unsigned char ns; // Send sequence number
1254 ////variables from reader-dre.c
1255 unsigned char provider;
1256 ////variables from reader-nagra.c
1257 IDEA_KEY_SCHEDULE ksSession;
1258 int8_t is_pure_nagra;
1259 int8_t is_tiger;
1260 int8_t is_n3_na;
1261 int8_t has_dt08;
1262 int8_t swapCW;
1263 uint8_t ExpiryDate[2];
1264 uint8_t ActivationDate[2];
1265 unsigned char rom[15];
1266 unsigned char plainDT08RSA[64];
1267 unsigned char IdeaCamKey[16];
1268 unsigned char irdId[4];
1269 unsigned char sessi[16];
1270 unsigned char signature[8];
1271 unsigned char cam_state[3];
1272 ////variables from reader-irdeto.c
1273 int32_t acs57; // A flag for the ACS57 ITA DVB-T
1274 ////variables from reader-cryptoworks.c
1275 BIGNUM exp;
1276 BIGNUM ucpk;
1277 ////variables from reader-viaccess.c
1278 struct geo_cache last_geo;
1279#ifdef WITH_LB
1280 int32_t lb_weight; //loadbalance weight factor, if unset, weight=100. The higher the value, the higher the usage-possibility
1281 int32_t lb_usagelevel; //usagelevel for loadbalancer
1282 int32_t lb_usagelevel_ecmcount;
1283 time_t lb_usagelevel_time; //time for counting ecms, this creates usagelevel
1284 struct timeb lb_last; //time for oldest reader
1285 LLIST *lb_stat; //loadbalancer reader statistics
1286 CS_MUTEX_LOCK lb_stat_lock;
1287#endif
1288
1289 AES_ENTRY *aes_list; // multi AES linked list
1290 // variables from reader-videoguard*
1291 int8_t ndsversion; // 0 auto (default), 1 NDS1, 12 NDS1+, 2 NDS2
1292 const char *card_desc;
1293 int32_t card_baseyear;
1294 int32_t card_tierstart;
1295 int32_t card_system_version;
1296 time_t card_valid_to;
1297 struct s_CmdTab *cmd_table;
1298 uint16_t cardkeys[3][32];
1299 unsigned char stateD3A[16];
1300 AES_KEY ekey;
1301 AES_KEY astrokey;
1302 //ratelimit
1303 int32_t ratelimitecm;
1304 int32_t ratelimitseconds;
1305 time_t lastdvbapirateoverride;
1306 uint32_t ecmsok;
1307 uint32_t ecmsnok;
1308 uint32_t ecmnotfoundlimit; // config setting. restart reader if ecmsnok >= ecmnotfoundlimit
1309 int32_t ecmsfilteredhead; // count filtered ECM's by ECM Headerwhitelist
1310 int32_t ecmsfilteredlen; // count filtered ECM's by ECM Whitelist
1311 float ecmshealthok;
1312 float ecmshealthnok;
1313 int32_t cooldown[2];
1314 int8_t cooldownstate;
1315 time_t cooldowntime;
1316 struct ecmrl rlecmh[MAXECMRATELIMIT];
1317 int8_t fix_9993;
1318 uint8_t ins7E[0x1A+1];
1319 uint8_t ins7E11[0x01+1];
1320 int8_t ins7e11_fast_reset;
1321 struct s_sc8in1_config *sc8in1_config;
1322 uint8_t sc8in1_dtrrts_patch; // fix for kernel commit 6a1a82df91fa0eb1cc76069a9efe5714d087eccd
1323#ifdef MODULE_GBOX
1324 char gbox_my_password[9];
1325 int8_t gbox_maxdist;
1326 int8_t gbox_maxecmsend;
1327 int8_t gbox_reshare;
1328 uint16_t gbox_peer_id;
1329 uint64_t gbox_grp;
1330#endif
1331
1332#ifdef MODULE_PANDORA
1333 uint8_t pand_send_ecm;
1334#endif
1335 uint8_t cnxlastecm; // == 0 - las ecm has not been paired ecm, > 0 last ecm has been paired ecm
1336
1337 uint8_t bulcrypt_version;
1338 uint8_t griffin_cmd_base; // Griffin command base, depends on the card
1339
1340 struct s_reader *next;
1341};
1342
1343struct s_cpmap
1344{
1345 uint16_t caid;
1346 uint32_t provid;
1347 uint16_t sid;
1348 uint16_t chid;
1349 uint16_t dwtime;
1350 struct s_cpmap *next;
1351};
1352
1353struct s_auth
1354{
1355 char usr[64];
1356 char *pwd;
1357#ifdef WEBIF
1358 char *description;
1359#endif
1360 int8_t uniq;
1361#ifdef CS_CACHEEX
1362 CECSP cacheex; //CacheEx Settings
1363#endif
1364 int16_t allowedprotocols;
1365 LLIST *aureader_list;
1366 int8_t autoau;
1367 int8_t monlvl;
1368 uint64_t grp;
1369 int32_t tosleep;
1370 CAIDTAB ctab;
1371 SIDTABS sidtabs;
1372 FTAB fchid;
1373 FTAB ftab; // user [caid] and ident filter
1374 CLASSTAB cltab;
1375 TUNTAB ttab;
1376#ifdef CS_ANTICASC
1377 int32_t ac_fakedelay; // When this is -1, the global ac_fakedelay is used
1378 int32_t ac_users; // 0 - unlimited
1379 int8_t ac_penalty; // 0 - log, >0 - fake dw
1380 struct s_acasc ac_stat;
1381#endif
1382 IN_ADDR_T dynip;
1383 char *dyndns;
1384 time_t expirationdate;
1385 time_t firstlogin;
1386 int32_t allowedtimeframe[2];
1387 int8_t c35_suppresscmd08;
1388 uint8_t c35_sleepsend;
1389 int8_t ncd_keepalive;
1390#ifdef MODULE_CCCAM
1391 int32_t cccmaxhops;
1392 int8_t cccreshare;
1393 int8_t cccignorereshare;
1394 int8_t cccstealth;
1395#endif
1396 int8_t disabled;
1397 int32_t failban;
1398
1399 int32_t cwfound;
1400 int32_t cwcache;
1401 int32_t cwnot;
1402 int32_t cwtun;
1403 int32_t cwignored;
1404 int32_t cwtout;
1405#ifdef CW_CYCLE_CHECK
1406 int32_t cwcycledchecked; // count checked cwcycles per client
1407 int32_t cwcycledok; // count pos checked cwcycles per client
1408 int32_t cwcyclednok; // count neg checked cwcycles per client
1409 int32_t cwcycledign; // count ign cwcycles per client
1410#endif
1411 int32_t emmok;
1412 int32_t emmnok;
1413#ifdef CS_CACHEEX
1414 int32_t cwcacheexpush; // count pushed ecms/cws
1415 int32_t cwcacheexgot; // count got ecms/cws
1416 int32_t cwcacheexhit; // count hit ecms/cws
1417 int32_t cwcacheexerr; //cw=00 or chksum wrong
1418 int32_t cwcacheexerrcw; //Same Hex, different CW
1419#endif
1420 struct s_auth *next;
1421};
1422
1423struct s_srvid
1424{
1425 uint16_t srvid;
1426 int8_t ncaid;
1427 uint16_t caid[10];
1428 char *data;
1429 char *prov;
1430 char *name;
1431 char *type;
1432 char *desc;
1433 struct s_srvid *next;
1434};
1435
1436struct s_tierid
1437{
1438 uint16_t tierid;
1439 int8_t ncaid;
1440 uint16_t caid[10];
1441 char name[33];
1442 struct s_tierid *next;
1443};
1444
1445struct s_provid
1446{
1447 uint16_t caid;
1448 uint32_t provid;
1449 char prov[33];
1450 char sat[33];
1451 char lang[33];
1452 struct s_provid *next;
1453};
1454
1455struct s_ip
1456{
1457 IN_ADDR_T ip[2];
1458 struct s_ip *next;
1459};
1460
1461struct s_global_whitelist
1462{
1463 uint32_t line; //linenr of oscam.whitelist file, starting with 1
1464 char type; // w or i or l
1465 uint16_t caid;
1466 uint32_t provid;
1467 uint16_t srvid;
1468 uint16_t chid;
1469 uint16_t pid;
1470 uint16_t ecmlen;
1471 uint16_t mapcaid;
1472 uint32_t mapprovid;
1473 struct s_global_whitelist *next;
1474};
1475
1476struct s_cacheex_matcher
1477{
1478 uint32_t line; //linenr of oscam.Cacheex file, starting with 1
1479 char type; // m
1480 uint16_t caid;
1481 uint32_t provid;
1482 uint16_t srvid;
1483 uint16_t chid;
1484 uint16_t pid;
1485 uint16_t ecmlen;
1486
1487 uint16_t to_caid;
1488 uint32_t to_provid;
1489 uint16_t to_srvid;
1490 uint16_t to_chid;
1491 uint16_t to_pid;
1492 uint16_t to_ecmlen;
1493
1494 int32_t valid_from;
1495 int32_t valid_to;
1496
1497 struct s_cacheex_matcher *next;
1498};
1499
1500typedef struct csp_ce_hit_t {
1501 time_t time;
1502 int16_t ecmlen;
1503 uint16_t caid;
1504 uint32_t prid;
1505 uint16_t srvid;
1506 uint64_t grp;
1507 struct csp_ce_hit_t *prev;
1508 struct csp_ce_hit_t *next;
1509} CSPCEHIT;
1510
1511struct s_config
1512{
1513 int32_t nice;
1514 uint32_t netprio;
1515 uint32_t ctimeout;
1516 uint32_t ftimeout;
1517 uint32_t cmaxidle;
1518 int32_t ulparent;
1519 uint32_t delay;
1520 int32_t bindwait;
1521 int32_t tosleep;
1522 IN_ADDR_T srvip;
1523 char *usrfile;
1524 char *cwlogdir;
1525 char *emmlogdir;
1526 char *logfile;
1527 char *mailfile;
1528 uint8_t logtostdout;
1529 uint8_t logtosyslog;
1530 int8_t logduplicatelines;
1531#if defined(WEBIF) || defined(MODULE_MONITOR)
1532 uint32_t loghistorysize;
1533#endif
1534 int8_t disablelog;
1535 int8_t disablemail;
1536 int8_t disableuserfile;
1537 int8_t usrfileflag;
1538 struct s_auth *account;
1539 struct s_srvid *srvid[16];
1540 struct s_tierid *tierid;
1541 //Todo #ifdef CCCAM
1542 struct s_provid *provid;
1543 struct s_sidtab *sidtab;
1544#ifdef MODULE_MONITOR
1545 int32_t mon_port;
1546 IN_ADDR_T mon_srvip;
1547 struct s_ip *mon_allowed;
1548 uint8_t mon_level;
1549#endif
1550 int32_t aulow;
1551 int32_t hideclient_to;
1552 int8_t appendchaninfo;
1553#ifdef WEBIF
1554 int32_t http_port;
1555 char *http_user;
1556 char *http_pwd;
1557 char *http_css;
1558 int32_t http_prepend_embedded_css;
1559 char *http_jscript;
1560 char *http_tpl;
1561 char *http_script;
1562 int32_t http_refresh;
1563 int8_t http_hide_idle_clients;
1564 char *http_hide_type;
1565 int8_t http_showpicons;
1566 struct s_ip *http_allowed;
1567 int8_t http_readonly;
1568 IN_ADDR_T http_dynip[MAX_HTTP_DYNDNS];
1569 uchar http_dyndns[MAX_HTTP_DYNDNS][64];
1570 int8_t http_use_ssl;
1571 int8_t http_force_sslv3;
1572 char *http_cert;
1573 char *http_help_lang;
1574#endif
1575 int8_t http_full_cfg;
1576 int32_t failbantime;
1577 int32_t failbancount;
1578 LLIST *v_list; // Failban list
1579 int32_t c33_port;
1580 IN_ADDR_T c33_srvip;
1581 uint8_t c33_key[16];
1582 int32_t c33_crypted;
1583 int32_t c33_passive;
1584 struct s_ip *c33_plain;
1585 int32_t c35_port;
1586 IN_ADDR_T c35_srvip;
1587 int8_t c35_suppresscmd08;
1588 int8_t c35_tcp_suppresscmd08;
1589 int8_t c35_udp_suppresscmd08;
1590 PTAB c35_tcp_ptab;
1591 IN_ADDR_T c35_tcp_srvip;
1592 PTAB ncd_ptab;
1593 IN_ADDR_T ncd_srvip;
1594 uint8_t ncd_key[14];
1595 int8_t ncd_keepalive;
1596 int8_t ncd_mgclient;
1597 struct s_ip *ncd_allowed;
1598 int32_t rad_port;
1599 IN_ADDR_T rad_srvip;
1600#ifdef MODULE_CCCAM
1601 uint16_t cc_port[CS_MAXPORTS];
1602 int8_t cc_reshare;
1603 int8_t cc_ignore_reshare;
1604 int32_t cc_update_interval;
1605 IN_ADDR_T cc_srvip;
1606 char cc_version[7];
1607 int8_t cc_minimize_cards;
1608 int8_t cc_keep_connected;
1609 int8_t cc_stealth;
1610 int8_t cc_reshare_services;
1611 int8_t cc_forward_origin_card;
1612 uint8_t cc_fixed_nodeid[8];
1613 uint32_t cc_recv_timeout; // The poll() timeout parameter in ms. Default: DEFAULT_CC_RECV_TIMEOUT (2000 ms).
1614#endif
1615#ifdef MODULE_GBOX
1616 char *gbox_hostname;
1617 unsigned long gbox_card[CS_GBOX_MAX_LOCAL_CARDS]; // gbox list of local cards
1618 int32_t gbox_local_cards_num; // number of local card gbox cards
1619 int32_t gbox_reconnect;
1620#endif
1621 struct s_ip *rad_allowed;
1622 char *rad_usr;
1623 char *ser_device;
1624 uint32_t srtimeout; // SerialReaderTimeount in millisec
1625 int32_t max_log_size;
1626 int8_t waitforcards;
1627 int32_t waitforcards_extra_delay;
1628 int8_t preferlocalcards;
1629 int32_t reader_restart_seconds; // schlocke: reader restart auf x seconds, disable = 0
1630 int8_t dropdups; // drop duplicate logins
1631
1632
1633//Loadbalancer-Config:
1634#ifdef WITH_LB
1635 int32_t lb_mode; // schlocke: reader loadbalancing mode
1636 int32_t lb_save; // schlocke: load/save statistics to file, save every x ecms
1637 int32_t lb_nbest_readers; // count of best readers
1638 int32_t lb_nfb_readers; // count of fallback readers
1639 int32_t lb_min_ecmcount; // minimal ecm count to evaluate lbvalues
1640 int32_t lb_max_ecmcount; // maximum ecm count before reseting lbvalues
1641 int32_t lb_reopen_seconds; // time between retrying failed readers/caids/prov/srv
1642 int32_t lb_retrylimit; // reopen only happens if reader response time > retrylimit
1643 CAIDVALUETAB lb_retrylimittab;
1644 CAIDVALUETAB lb_nbest_readers_tab; // like nbest_readers, but for special caids
1645 CAIDTAB lb_noproviderforcaid; // do not store loadbalancer stats with providers for this caid
1646 char *lb_savepath; // path where the stat file is save. Empty=default=/tmp/.oscam/stat
1647 int32_t lb_stat_cleanup; // duration in hours for cleaning old statistics
1648 int32_t lb_reopen_mode; // reopen readers mode
1649 int32_t lb_max_readers; // limit the amount of readers during learning
1650 int32_t lb_auto_betatunnel; // automatic selection of betatunnel convertion based on learned data
1651 int32_t lb_auto_betatunnel_mode; // automatic selection of betatunnel direction
1652 int32_t lb_auto_betatunnel_prefer_beta; // prefer-beta-over-nagra factor
1653 int32_t lb_auto_timeout; // Automatic timeout by loadbalancer statistics
1654 int32_t lb_auto_timeout_p; // percent added to avg time as timeout time
1655 int32_t lb_auto_timeout_t; // minimal time added to avg time as timeout time
1656#endif
1657 int32_t resolve_gethostbyname;
1658 int8_t double_check; // schlocke: Double checks each ecm+dcw from two (or more) readers
1659 CAIDTAB double_check_caid; // do not store loadbalancer stats with providers for this caid
1660
1661#ifdef IRDETO_GUESSING
1662 struct s_irdeto_quess *itab[0xff];
1663#endif
1664
1665#ifdef HAVE_DVBAPI
1666 int8_t dvbapi_enabled;
1667 int8_t dvbapi_au;
1668 char *dvbapi_usr;
1669 int8_t dvbapi_boxtype;
1670 int8_t dvbapi_pmtmode;
1671 int8_t dvbapi_requestmode;
1672 SIDTABS dvbapi_sidtabs;
1673 int8_t dvbapi_reopenonzap;
1674 int8_t dvbapi_decodeforever; // do not stop after 3 tries
1675 int32_t dvbapi_delayer; // delayer ms, minimum time to write cw
1676#endif
1677
1678#ifdef CS_ANTICASC
1679 int8_t ac_enabled;
1680 int32_t ac_users; // num of users for account (0 - default)
1681 int32_t ac_stime; // time to collect AC statistics (3 min - default)
1682 int32_t ac_samples; // qty of samples
1683 int8_t ac_penalty; // 0 - write to log
1684 int32_t ac_fakedelay; // 100-1000 ms
1685 int32_t ac_denysamples;
1686 char *ac_logfile;
1687 struct s_cpmap *cpmap;
1688#endif
1689
1690#ifdef LEDSUPPORT
1691 int8_t enableled; // 0=disabled led, 1=enable led for routers, 2=enable qboxhd led
1692#endif
1693
1694#ifdef LCDSUPPORT
1695 int8_t enablelcd;
1696 char *lcd_output_path;
1697 int32_t lcd_hide_idle;
1698 int32_t lcd_write_intervall;
1699#endif
1700
1701#ifdef MODULE_PANDORA
1702 int8_t pand_skip_send_dw;
1703 struct s_ip *pand_allowed;
1704 char *pand_usr;
1705 char *pand_pass;
1706 int8_t pand_ecm;
1707 int32_t pand_port;
1708 IN_ADDR_T pand_srvip;
1709#endif
1710
1711 uint32_t max_cache_time; //seconds
1712 uint32_t max_cache_count; //count ecms
1713
1714 int8_t block_same_ip; //0=allow all, 1=block client requests to reader with same ip (default=1)
1715 int8_t block_same_name; //0=allow all, 1=block client requests to reader with same name (default=1)
1716
1717#ifdef CS_CACHEEX
1718 IN_ADDR_T csp_srvip;
1719 int32_t csp_port;
1720 CECSPVALUETAB cacheex_wait_timetab;
1721 CECSP csp; //CSP Settings
1722 uint8_t cacheex_enable_stats; //enable stats
1723 struct s_cacheex_matcher *cacheex_matcher;
1724#endif
1725
1726#ifdef CW_CYCLE_CHECK
1727 int8_t cwcycle_check_enable; // on or off
1728 CAIDTAB cwcycle_check_caidtab; // Caid for CW Cycle Check
1729 int32_t keepcycletime; // how long stay the learned Cycletime in Memory
1730 int32_t maxcyclelist; // max size of cwcyclelist
1731 int8_t onbadcycle; // what to do on bad cwcycle
1732 int8_t cwcycle_dropold; // what to do on old ecmd5/cw
1733#endif
1734
1735 //Global whitelist:
1736 struct s_global_whitelist *global_whitelist;
1737 int8_t global_whitelist_use_l;
1738 int8_t global_whitelist_use_m;
1739
1740 char *ecmfmt;
1741 char *pidfile;
1742
1743 int32_t max_pending;
1744};
1745
1746struct s_clientinit
1747{
1748 void *(*handler)(struct s_client*);
1749 struct s_client * client;
1750};
1751
1752struct s_clientmsg {
1753 uint8_t msg[1024];
1754 int32_t len;
1755 int32_t cmd;
1756};
1757
1758typedef struct reader_stat_t
1759{
1760 int32_t rc;
1761 uint16_t caid;
1762 uint32_t prid;
1763 uint16_t srvid;
1764 uint32_t chid;
1765 int16_t ecmlen;
1766
1767 time_t last_received;
1768
1769 int32_t ecm_count;
1770 int32_t time_avg;
1771 int32_t time_stat[LB_MAX_STAT_TIME];
1772 int32_t time_idx;
1773
1774 int32_t fail_factor;
1775} READER_STAT;
1776
1777typedef struct cs_stat_query {
1778 uint16_t caid;
1779 uint32_t prid;
1780 uint16_t srvid;
1781 uint32_t chid;
1782 int16_t ecmlen;
1783} STAT_QUERY;
1784
1785
1786typedef struct emm_packet_t
1787{
1788 uchar emm[258];
1789 int16_t emmlen;
1790 uchar caid[2];
1791 uchar provid[4];
1792 uchar hexserial[8]; //contains hexserial or SA of EMM
1793 uchar type;
1794 struct s_client *client;
1795} EMM_PACKET;
1796
1797
1798/* ===========================
1799 * global variables
1800 * =========================== */
1801extern pthread_key_t getclient;
1802extern struct s_client *first_client;
1803extern CS_MUTEX_LOCK config_lock;
1804extern CS_MUTEX_LOCK clientlist_lock;
1805extern CS_MUTEX_LOCK readerlist_lock;
1806extern struct s_reader *first_active_reader; //points to list of _active_ readers (enable = 1, deleted = 0)
1807extern LLIST *configured_readers;
1808
1809// These are used pretty much everywhere
1810extern struct s_config cfg;
1811extern uint16_t cs_dblevel;
1812
1813#include "oscam-log.h"
1814#include "oscam-log-reader.h"
1815
1816// Add here *only* funcs that are implemented in oscam.c and are called in other places
1817void cs_exit(int32_t sig);
1818void cs_exit_oscam(void);
1819void cs_restart_oscam(void);
1820int32_t cs_get_restartmode(void);
1821
1822void set_thread_name(const char *thread_name);
1823void start_thread(void *startroutine, char *nameroutine);
1824void kill_thread(struct s_client *cl);
1825
1826struct s_module *get_module(struct s_client *cl);
1827void module_reader_set(struct s_reader *rdr);
1828
1829// Until we find a better place for these (they are implemented in oscam-simples.h)
1830char *get_servicename(struct s_client *cl, uint16_t srvid, uint16_t caid, char *buf);
1831char *get_tiername(uint16_t tierid, uint16_t caid, char *buf);
1832char *get_provider(uint16_t caid, uint32_t provid, char *buf, uint32_t buflen);
1833void add_provider(uint16_t caid, uint32_t provid, const char *name, const char *sat, const char *lang);
1834
1835#endif
Note: See TracBrowser for help on using the repository browser.