source: trunk/globals.h@ 8432

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