4 #define _GNU_SOURCE // needed for PTHREAD_MUTEX_RECURSIVE on some plattforms and maybe other things; do not remove
12 #include <sys/ioctl.h>
15 #include <sys/types.h>
25 #include <netinet/tcp.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
38 #include <sys/utsname.h>
40 #if !defined(__APPLE__)
41 #include <sys/sysmacros.h>
45 * The following hack is taken from Linux: include/linux/kconfig.h
46 * Original comment follows:
47 * Getting something that works in C and CPP for an arg that may or may
48 * not be defined is tricky. Here, if we have "#define CONFIG_BOOGER 1"
49 * we match on the placeholder define, insert the "0," for arg1 and generate
50 * the triplet (0, 1, 0). Then the last step cherry picks the 2nd arg (a one).
51 * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
52 * the last step cherry picks the 2nd arg, we get a zero.
54 #define __ARG_PLACEHOLDER_1 0,
55 #define config_enabled(cfg) _config_enabled(cfg)
56 #define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value)
57 #define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0)
58 #define ___config_enabled(__ignored, val, ...) val
62 #if defined(WITH_SSL) && !defined(WITH_LIBCRYPTO)
63 # define WITH_LIBCRYPTO 1
66 /* For deprecated but still needed cryptography functions:
67 * 10002 corresponds to OpenSSL version 1.0.2*/
69 #define OPENSSL_API_COMPAT 10002
71 #if defined(__CYGWIN__) || defined(__arm__) || defined(__SH4__) || defined(__MIPS__) || defined(__MIPSEL__) || defined(__powerpc__)
72 # define CS_LOGFILE "/dev/tty"
75 #if defined(__AIX__) || defined(__SGI__) || defined(__OSF__) || defined(__HPUX__) || defined(__SOLARIS__) || defined(__APPLE__)
79 #if defined(__AIX__) || defined(__SGI__) || defined(__OSF__) || defined(__HPUX__) || defined(__SOLARIS__) || defined(__CYGWIN__)
83 #if defined(__AIX__) || defined(__SGI__)
84 # define socklen_t unsigned long
87 #if defined(__SOLARIS__) || defined(__FreeBSD__) || defined(__OpenBSD__)
92 # define _XOPEN_SOURCE_EXTENDED
95 #if (defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)) && !defined(s6_addr32)
96 #define s6_addr32 __u6_addr.__u6_addr32
101 #define in_port_t uint16_t
103 #define tcdrain(fd) ioctl(fd, TCSBRK, 1)
110 // Prevent warnings about openssl functions. Apple may consider 'openssl'
111 // deprecated but changing perfectly working portable code just because they
112 // introduced some proprietary API is not going to happen.
113 #if defined(__APPLE__)
114 #define __AVAILABILITY_MACROS_USES_AVAILABILITY 0
115 #define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_6
118 #include "cscrypt/aes.h"
121 #define IN_ADDR_T struct in6_addr
122 #define SOCKADDR sockaddr_storage
123 #define ADDR_ANY in6addr_any
124 #define DEFAULT_AF AF_INET6
126 #define IN_ADDR_T in_addr_t
127 #define SOCKADDR sockaddr_in
128 #define ADDR_ANY INADDR_ANY
129 #define DEFAULT_AF AF_INET
133 #if defined(__APPLE__)
134 #include <machine/endian.h>
135 #define __BYTE_ORDER __DARWIN_BYTE_ORDER
136 #define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
137 #define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
138 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
139 #include <sys/endian.h>
140 #define __BYTE_ORDER _BYTE_ORDER
141 #define __BIG_ENDIAN _BIG_ENDIAN
142 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
145 #include <byteswap.h>
149 /* ===========================
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
181 #define getpwuid(a) UNSAFE_GETPWUID_NOT_THREADSAFE_USE_GETPWUID_R
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
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
207 #if __GNUC__ >= 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
208 # define MUST_CHECK_RESULT __attribute__((warn_unused_result))
219 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
225 cs_log_dbg(D_TRACE, "ERROR, function call %s returns error.",#arg); \
236 // checking if (X) free(X) unneccessary since freeing a null pointer doesnt do anything
237 #define NULLFREE(X) {if (X) {void *tmpX=X; X=NULL; free(tmpX); }}
240 #define cs_recv(a,b,c,d) cygwin_recv(a,b,c,d)
242 #define cs_recv(a,b,c,d) recv(a,b,c,d)
245 // safe wrappers to pthread functions
246 #define fprintf_stderr(fmt, params...) fprintf(stderr, fmt, ##params)
248 #define SAFE_PTHREAD_1ARG(a, b, c) { \
249 int32_t pter = a(b); \
252 c("FATAL ERROR: %s() failed in %s with error %d %s\n", #a, __func__, pter, strerror(pter)); \
255 #define SAFE_MUTEX_LOCK(a) SAFE_PTHREAD_1ARG(pthread_mutex_lock, a, cs_log)
256 #define SAFE_MUTEX_UNLOCK(a) SAFE_PTHREAD_1ARG(pthread_mutex_unlock, a, cs_log)
257 #define SAFE_COND_SIGNAL(a) SAFE_PTHREAD_1ARG(pthread_cond_signal, a, cs_log)
258 #define SAFE_COND_BROADCAST(a) SAFE_PTHREAD_1ARG(pthread_cond_broadcast, a, cs_log)
259 #define SAFE_RWLOCK_RDLOCK(a) SAFE_PTHREAD_1ARG(pthread_rwlock_rdlock, a, cs_log)
260 #define SAFE_RWLOCK_WRLOCK(a) SAFE_PTHREAD_1ARG(pthread_rwlock_wrlock, a, cs_log)
261 #define SAFE_RWLOCK_UNLOCK(a) SAFE_PTHREAD_1ARG(pthread_rwlock_unlock, a, cs_log)
262 #define SAFE_ATTR_INIT(a) SAFE_PTHREAD_1ARG(pthread_attr_init, a, cs_log)
263 #define SAFE_MUTEXATTR_INIT(a) SAFE_PTHREAD_1ARG(pthread_mutexattr_init, a, cs_log)
264 #define SAFE_CONDATTR_INIT(a) SAFE_PTHREAD_1ARG(pthread_condattr_init, a, cs_log)
266 #define SAFE_MUTEX_LOCK_NOLOG(a) SAFE_PTHREAD_1ARG(pthread_mutex_lock, a, fprintf_stderr)
267 #define SAFE_MUTEX_UNLOCK_NOLOG(a) SAFE_PTHREAD_1ARG(pthread_mutex_unlock, a, fprintf_stderr)
268 #define SAFE_COND_SIGNAL_NOLOG(a) SAFE_PTHREAD_1ARG(pthread_cond_signal, a, fprintf_stderr)
269 #define SAFE_MUTEX_UNLOCK_NOLOG(a) SAFE_PTHREAD_1ARG(pthread_mutex_unlock, a, fprintf_stderr)
270 #define SAFE_ATTR_INIT_NOLOG(a) SAFE_PTHREAD_1ARG(pthread_attr_init, a, fprintf_stderr)
271 #define SAFE_CONDATTR_INIT_NOLOG(a) SAFE_PTHREAD_1ARG(pthread_condattr_init, a, fprintf_stderr)
273 #define SAFE_PTHREAD_2ARG(a, b, c, d) { \
274 int32_t pter = a(b, c); \
277 d("FATAL ERROR: %s() failed in %s with error %d %s\n", #a, __func__, pter, strerror(pter)); \
280 #define SAFE_COND_WAIT(a,b) SAFE_PTHREAD_2ARG(pthread_cond_wait, a, b, cs_log)
281 #define SAFE_THREAD_JOIN(a,b) SAFE_PTHREAD_2ARG(pthread_join, a, b, cs_log)
282 #define SAFE_SETSPECIFIC(a,b) SAFE_PTHREAD_2ARG(pthread_setspecific, a, b, cs_log)
283 #define SAFE_MUTEXATTR_SETTYPE(a,b) SAFE_PTHREAD_2ARG(pthread_mutexattr_settype, a, b, cs_log)
284 #define SAFE_MUTEX_INIT(a,b) SAFE_PTHREAD_2ARG(pthread_mutex_init, a, b, cs_log)
285 #define SAFE_COND_INIT(a,b) SAFE_PTHREAD_2ARG(pthread_cond_init, a, b, cs_log)
286 #define SAFE_CONDATTR_SETCLOCK(a,b) SAFE_PTHREAD_2ARG(pthread_condattr_setclock, a, b, cs_log)
288 #define SAFE_MUTEX_INIT_NOLOG(a,b) SAFE_PTHREAD_2ARG(pthread_mutex_init, a, b, fprintf_stderr)
289 #define SAFE_COND_INIT_NOLOG(a,b) SAFE_PTHREAD_2ARG(pthread_cond_init, a, b, fprintf_stderr)
290 #define SAFE_THREAD_JOIN_NOLOG(a,b) SAFE_PTHREAD_2ARG(pthread_join, a, b, fprintf_stderr)
291 #define SAFE_CONDATTR_SETCLOCK_NOLOG(a,b) SAFE_PTHREAD_2ARG(pthread_condattr_setclock, a, b, fprintf_stderr)
293 #define SAFE_PTHREAD_1ARG_R(a, b, c, d) { \
294 int32_t pter = a(b); \
297 c("FATAL ERROR: %s() failed in %s (called from %s) with error %d %s\n", #a, __func__, d, pter, strerror(pter)); \
300 #define SAFE_MUTEX_LOCK_R(a, b) SAFE_PTHREAD_1ARG_R(pthread_mutex_lock, a, cs_log, b)
301 #define SAFE_MUTEX_UNLOCK_R(a, b) SAFE_PTHREAD_1ARG_R(pthread_mutex_unlock, a, cs_log, b)
302 #define SAFE_COND_SIGNAL_R(a, b) SAFE_PTHREAD_1ARG_R(pthread_cond_signal, a, cs_log, b)
303 #define SAFE_COND_BROADCAST_R(a, b) SAFE_PTHREAD_1ARG_R(pthread_cond_broadcast, a, cs_log, b)
304 #define SAFE_CONDATTR_INIT_R(a, b) SAFE_PTHREAD_1ARG_R(pthread_condattr_init, a, cs_log, b)
306 #define SAFE_MUTEX_LOCK_NOLOG_R(a, b) SAFE_PTHREAD_1ARG_R(pthread_mutex_lock, a, fprintf_stderr, b)
307 #define SAFE_MUTEX_UNLOCK_NOLOG_R(a, b) SAFE_PTHREAD_1ARG_R(pthread_mutex_unlock, a, fprintf_stderr, b)
308 #define SAFE_CONDATTR_INIT_NOLOG_R(a, b) SAFE_PTHREAD_1ARG_R(pthread_condattr_init, a, fprintf_stderr, b)
310 #define SAFE_PTHREAD_2ARG_R(a, b, c, d, e) { \
311 int32_t pter = a(b, c); \
314 d("FATAL ERROR: %s() failed in %s (called from %s) with error %d %s\n", #a, __func__, e, pter, strerror(pter)); \
317 #define SAFE_MUTEX_INIT_R(a,b,c) SAFE_PTHREAD_2ARG_R(pthread_mutex_init, a, b, cs_log, c)
318 #define SAFE_COND_INIT_R(a,b,c) SAFE_PTHREAD_2ARG_R(pthread_cond_init, a, b, cs_log, c)
319 #define SAFE_CONDATTR_SETCLOCK_R(a,b,c) SAFE_PTHREAD_2ARG(pthread_condattr_setclock, a, b, cs_log, c)
321 #define SAFE_MUTEX_INIT_NOLOG_R(a,b,c) SAFE_PTHREAD_2ARG_R(pthread_mutex_init, a, b, fprintf_stderr, c)
322 #define SAFE_COND_INIT_NOLOG_R(a,b,c) SAFE_PTHREAD_2ARG_R(pthread_cond_init, a, b, fprintf_stderr, c)
323 #define SAFE_CONDATTR_SETCLOCK_NOLOG_R(a,b,c) SAFE_PTHREAD_2ARG(pthread_condattr_setclock, a, b, fprintf_stderr, c)
325 #define SAFE_COND_TIMEDWAIT(a, b, c) { \
327 if((c)->tv_nsec < 0) (c)->tv_nsec = 0; \
328 if((c)->tv_nsec > 999999999) (c)->tv_nsec = 999999999; \
329 pter = pthread_cond_timedwait(a, b, c); \
330 if(pter != 0 && pter != ETIMEDOUT) \
332 cs_log("FATAL ERROR: pthread_cond_timedwait failed in %s with error %d %s\n", __func__, pter, strerror(pter)); \
335 #define SAFE_COND_TIMEDWAIT_R(a, b, c, d) { \
337 if((c)->tv_nsec < 0) (c)->tv_nsec = 0; \
338 if((c)->tv_nsec > 999999999) (c)->tv_nsec = 999999999; \
339 pter = pthread_cond_timedwait(a, b, c); \
340 if(pter != 0 && pter != ETIMEDOUT) \
342 cs_log("FATAL ERROR: pthread_cond_timedwait failed in %s (called from %s) with error %d %s\n", __func__, d, pter, strerror(pter)); \
345 #define SAFE_ATTR_SETSTACKSIZE(a,b) { \
346 int32_t pter = pthread_attr_setstacksize(a, b); \
349 cs_log("WARNING: pthread_attr_setstacksize() failed in %s with error %d %s\n", __func__, pter, strerror(pter)); \
352 #define SAFE_ATTR_SETSTACKSIZE_NOLOG(a,b) { \
353 int32_t pter = pthread_attr_setstacksize(a, b); \
356 fprintf_stderr("WARNING: pthread_attr_setstacksize() failed in %s with error %d %s\n", __func__, pter, strerror(pter)); \
359 #ifdef NO_PTHREAD_STACKSIZE
360 #undef SAFE_ATTR_SETSTACKSIZE
361 #undef SAFE_ATTR_SETSTACKSIZE_NOLOG
362 #define SAFE_ATTR_SETSTACKSIZE(a,b)
363 #define SAFE_ATTR_SETSTACKSIZE_NOLOG(a,b)
366 #define CHECK_BIT(var,pos) (((var) & (1<<(pos)))? 1 : 0)
368 /* ===========================
370 * =========================== */
371 #define CS_VERSION "1.30_svn"
372 #ifndef CS_SVN_VERSION
373 # define CS_SVN_VERSION "test"
376 #ifdef CS_CACHEEX_AIO
377 #define CS_AIO_VERSION CS_SVN_VERSION
381 # define CS_TARGET "unknown"
384 #define CS_CONFDIR "/usr/local/etc"
387 #define CS_LOGFILE "/var/log/oscam.log"
389 #define CS_QLEN 128 // size of request queue
390 #define CS_MAXPROV 32
391 #define CS_MAXPORTS 32 // max server ports
392 #define CS_CLIENT_HASHBUCKETS 32
393 #define CS_SERVICENAME_SIZE 32
395 #define CS_ECMSTORESIZE 16 // use MD5()
396 #define CS_EMMSTORESIZE 16 // use MD5()
397 #define CS_CLIENT_TIMEOUT 5000
398 #define CS_CLIENT_MAXIDLE 120
399 #define CS_BIND_TIMEOUT 120
401 #define CS_ECM_RINGBUFFER_MAX 0x10 // max size for ECM last responsetimes ringbuffer. Keep this set to power of 2 values!
403 // Support for multiple CWs per channel and other encryption algos
404 //#define WITH_EXTENDED_CW 1
406 #define MAX_ECM_SIZE 1024
407 #define MAX_EMM_SIZE 1024
409 #define MAX_CMD_SIZE 0xff + 5 // maximum value from length byte + command header
412 #define CS_EMMCACHESIZE 1024 // nr of EMMs that EMU reader will cache
414 #define CS_EMMCACHESIZE 512 // nr of EMMs that each reader will cache
416 #define MSGLOGSIZE 64 // size of string buffer for a ecm to return messages
418 #define D_TRACE 0x0001 // Generate very detailed error/trace messages per routine
419 #define D_ATR 0x0002 // Debug ATR parsing, dump of ecm, cw
420 #define D_READER 0x0004 // Debug Reader/Proxy Process
421 #define D_CLIENT 0x0008 // Debug Client Process
422 #define D_IFD 0x0010 // Debug IFD+protocol
423 #define D_DEVICE 0x0020 // Debug Reader I/O
424 #define D_EMM 0x0040 // Dumps EMM
425 #define D_DVBAPI 0x0080 // Debug DVBAPI
426 #define D_LB 0x0100 // Debug Loadbalancer/ECM handler
427 #define D_CACHEEX 0x0200 // Debug CACHEEX
428 #define D_CLIENTECM 0x0400 // Debug Client ECMs
429 #define D_CSP 0x0800 // Debug CSP
430 #define D_CWC 0x1000 // Debug CWC
431 #ifdef CS_CACHEEX_AIO
432 #define D_CW_CACHE 0x2000 // Debug CW Cache
434 #define D_ALL_DUMP 0xFFFF // dumps all
436 #ifdef CS_CACHEEX_AIO
437 #define MAX_DEBUG_LEVELS 14
439 #define MAX_DEBUG_LEVELS 13
442 /////// phoenix readers which need baudrate setting and timings need to be guarded by OSCam: BEFORE R_MOUSE
443 #define R_DB2COM1 0x1 // Reader Dbox2 @ com1
444 #define R_DB2COM2 0x2 // Reader Dbox2 @ com1
445 #define R_SC8in1 0x3 // Reader Sc8in1 or MCR
446 #define R_MP35 0x4 // AD-Teknik Multiprogrammer 3.5 and 3.6 (only usb tested)
447 #define R_MOUSE 0x5 // Reader smartcard mouse
448 /////// internal readers (Dreambox, Coolstream, IPBox) are all R_INTERNAL, they are determined compile-time
449 #define R_INTERNAL 0x6 // Reader smartcard intern
450 /////// readers that do not reed baudrate setting and timings are guarded by reader itself (large buffer built in): AFTER R_SMART
451 #define R_SMART 0x7 // Smartreader+
452 #define R_PCSC 0x8 // PCSC
453 #define R_DRECAS 0x9 // Reader DRECAS
454 #define R_EMU 0x17 // Reader EMU
455 /////// proxy readers after R_CS378X
456 #define R_CAMD35 0x20 // Reader cascading camd 3.5x
457 #define R_CAMD33 0x21 // Reader cascading camd 3.3x
458 #define R_NEWCAMD 0x22 // Reader cascading newcamd
459 #define R_RADEGAST 0x23 // Reader cascading radegast
460 #define R_CS378X 0x24 // Reader cascading camd 3.5x TCP
461 #define R_CONSTCW 0x25 // Reader for Constant CW
462 #define R_CSP 0x26 // Cache CSP
463 #define R_GHTTP 0x27 // Reader ghttp
464 #define R_SCAM 0x28 // Reader cascading scam
465 /////// peer to peer proxy readers after R_CCCAM
466 #define R_GBOX 0x30 // Reader cascading gbox
467 #define R_CCCAM 0x35 // Reader cascading cccam
468 #define R_PANDORA 0x36 // Reader cascading pandora
469 #define R_SERIAL 0x80 // Reader serial
470 #define R_IS_NETWORK 0x60
471 #define R_IS_CASCADING 0xE0
473 #define is_network_reader(__X) (__X->typ & R_IS_NETWORK)
474 #define is_cascading_reader(__X) (__X->typ & R_IS_CASCADING)
475 #define is_smargo_reader(__X) (__X->crdr && strcmp(__X->crdr->desc, "smargo") == 0)
483 /////// all notfound, some error or problem
484 #define E_NOTFOUND 4 // for selection of found, use < E_NOTFOUND
492 #define E_DISABLED 12
493 #define E_STOPPED 13 // for selection of error, use <= E_STOPPED and exclude selection of found
495 #define E_ALREADY_SENT 101
496 #define E_WAITING 102
497 #define E_99 99 // this code is undocumented
498 #define E_UNHANDLED 100 // for selection of unhandled, use >= E_UNHANDLED
500 #define CS_MAX_MOD 20
501 #define MOD_CONN_TCP 1
502 #define MOD_CONN_UDP 2
503 #define MOD_CONN_NET 3
504 #define MOD_CONN_SERIAL 4
505 #define MOD_NO_CONN 8
510 #define EMM_UNKNOWN 8
513 #define LIS_CAMD33TCP 1
514 #define LIS_CAMD35UDP 2
515 #define LIS_CAMD35TCP 4
516 #define LIS_NEWCAMD 8
519 #define LIS_RADEGAST 64
520 #define LIS_DVBAPI 128
521 #define LIS_CONSTCW 256
522 #define LIS_SERIAL 1024
523 #define LIS_CSPUDP 2048
524 #define LIS_SCAM 4096
536 // moved from reader-common.h
538 #define CARD_NEED_INIT 1
539 #define CARD_INSERTED 2
540 #define CARD_FAILURE 3
542 #define READER_DEVICE_ERROR 5
545 #define DEFAULT_REOPEN_SECONDS 30
546 #define DEFAULT_MIN_ECM_COUNT 5
547 #define DEFAULT_MAX_ECM_COUNT 500
548 #define DEFAULT_NBEST 1
549 #define DEFAULT_NFB 1
550 #define DEFAULT_RETRYLIMIT 0
551 #define DEFAULT_LB_MODE 0
552 #define DEFAULT_LB_STAT_CLEANUP 336
553 #define DEFAULT_UPDATEINTERVAL 240
554 #define DEFAULT_LB_AUTO_BETATUNNEL 1
555 #define DEFAULT_LB_AUTO_BETATUNNEL_MODE 0
556 #define DEFAULT_LB_AUTO_BETATUNNEL_PREFER_BETA 50
558 #define DEFAULT_MAX_CACHE_TIME 15
559 #define DEFAULT_MAX_HITCACHE_TIME 15
561 #define DEFAULT_LB_AUTO_TIMEOUT 0
562 #define DEFAULT_LB_AUTO_TIMEOUT_P 30
563 #define DEFAULT_LB_AUTO_TIMEOUT_T 300
565 enum {E1_GLOBAL
= 0, E1_USER
, E1_READER
, E1_SERVER
, E1_LSERVER
};
567 // LB blocking events:
568 enum {E2_GLOBAL
= 0, E2_GROUP
, E2_CAID
, E2_IDENT
, E2_CLASS
, E2_CHID
, E2_QUEUE
, E2_OFFLINE
,
569 E2_SID
, E2_CCCAM_NOCARD
,
570 // From here only LB nonblocking events:
571 E2_CCCAM_NOK1
, E2_CCCAM_NOK2
, E2_CCCAM_LOOP
, E2_WRONG_CHKSUM
, E2_RATELIMIT
574 #define LB_NONBLOCK_E2_FIRST E2_CCCAM_NOK1
576 #define CTA_RES_LEN 512
578 #define MAX_ATR_LEN 33 // max. ATR length
579 #define MAX_HIST 15 // max. number of historical characters
581 #define MAX_SIDBITS 64 // max services
582 #define SIDTABBITS uint64_t // 64bit type for services, if a system does not support this type,
583 // please use a define and define it as uint32_t / MAX_SIDBITS 32
585 #define BAN_UNKNOWN 1 // Failban mask for anonymous/ unknown contact
586 #define BAN_DISABLED 2 // Failban mask for Disabled user
587 #define BAN_SLEEPING 4 // Failban mask for sleeping user
588 #define BAN_DUPLICATE 8 // Failban mask for duplicate user
590 #define MAX_HTTP_DYNDNS 3 // maximum allowed Dyndns addresses for webif access
592 #define CHECK_WAKEUP 1
593 #define CHECK_ANTICASCADER 2
594 #define CHECK_ECMCACHE 3
596 #define AVAIL_CHECK_CONNECTED 0
597 #define AVAIL_CHECK_LOADBALANCE 1
599 #define ECM_FMT_LEN 109 // 64
600 #define CXM_FMT_LEN 209 // 160
602 #define LB_MAX_STAT_TIME 10
604 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
605 #define OSCAM_SIGNAL_WAKEUP SIGCONT
607 #define OSCAM_SIGNAL_WAKEUP SIGRTMAX-2
610 #define READER_ACTIVE 0x01
611 #define READER_FALLBACK 0x02
612 #define READER_LOCAL 0x04
613 #define READER_CACHEEX 0x08
615 #define REQUEST_SENT 0x10
616 #define REQUEST_ANSWERED 0x20
618 #define CW_MODE_ONE_CW 0
619 #define CW_MODE_MULTIPLE_CW 1
620 #define CW_TYPE_VIDEO 0
621 #define CW_TYPE_AUDIO 1
622 #define CW_TYPE_DATA 2
623 #define CW_ALGO_CSA 0
624 #define CW_ALGO_DES 1
625 #define CW_ALGO_AES128 2
626 #define CW_ALGO_CSA_ALT 3
627 #define CW_ALGO_MODE_ECB 0
628 #define CW_ALGO_MODE_CBC 1
630 #define SIZE_SHORTDAY 8
631 #define MAXALLOWEDTF 1001 // 10 allowed time frame slots for everyday + all [(3 + 1 + 10*(12) + 1)*8]
632 extern const char *shortDay
[SIZE_SHORTDAY
];
633 extern const char *weekdstr
;
635 /* ===========================
637 * =========================== */
638 #define DEFAULT_INACTIVITYTIMEOUT 0
639 #define DEFAULT_TCP_RECONNECT_TIMEOUT 30
640 #define DEFAULT_NCD_KEEPALIVE 0
642 #define DEFAULT_CC_MAXHOPS 10
643 #define DEFAULT_CC_RESHARE -1 // Use global cfg
644 #define DEFAULT_CC_IGNRSHR -1 // Use global cfg
645 #define DEFAULT_CC_STEALTH -1 // Use global cfg
646 #define DEFAULT_CC_KEEPALIVE 0
647 #define DEFAULT_CC_RECONNECT 12000
648 #define DEFAULT_CC_RECV_TIMEOUT 2000
650 #define DEFAULT_AC_USERS -1 // Use global cfg
651 #define DEFAULT_AC_PENALTY -1 // Use global cfg
653 // Return MPEG section length
654 #define SCT_LEN(sct) (3+((sct[1]&0x0f)<<8)+sct[2])
658 #define NO_CAID_VALUE 0xfffe
659 #define NO_PROVID_VALUE 0xfffffe
660 #define NO_SRVID_VALUE 0xfffe
662 // If NULL return empty string
663 #define ESTR(x) ((x) ? (x) : "")
666 #define MAX(a,b) ((a) > (b) ? (a) : (b))
670 #define MIN(a,b) ((a) < (b) ? (a) : (b))
674 See: http://stackoverflow.com/questions/10269685/kernels-container-of-any-way-to-make-it-iso-conforming
675 http://www.kroah.com/log/linux/container_of.html
677 #define container_of(ptr, type, member) \
678 ((type *) ((char *) (ptr) - offsetof(type, member) + \
679 (&((type *) 0)->member == (ptr)) * 0))
681 /* ===========================
683 * =========================== */
690 typedef struct cs_mutexlock
693 pthread_mutex_t lock
;
694 pthread_cond_t writecond
, readcond
;
697 int16_t writelock
, readlock
;
700 #include "oscam-llist.h"
702 typedef struct s_caidvaluetab_data
708 typedef struct s_caidvaluetab
711 CAIDVALUETAB_DATA
*cvdata
;
714 typedef struct s_classtab
722 typedef struct s_caidtab_data
729 typedef struct s_caidtab
732 CAIDTAB_DATA
*ctdata
;
735 typedef struct s_tuntab_data
737 uint16_t bt_caidfrom
;
742 typedef struct s_tuntab
748 typedef struct s_sidtab
751 #ifdef CS_CACHEEX_AIO
752 uint8_t disablecrccws_only_for_exception
;
753 uint8_t no_wait_time
;
754 uint8_t lg_only_exception
;
762 struct s_sidtab
*next
;
765 typedef struct s_filter
769 uint32_t prids
[CS_MAXPROV
];
772 typedef struct s_ftab
778 typedef struct s_ncd_ftab
791 typedef struct s_port
795 struct ncd_port
*ncd
; // newcamd specific settings
798 typedef struct s_ptab
801 PORT ports
[CS_MAXPORTS
];
804 typedef struct aes_entry
809 uint8_t plainkey
[16];
811 struct aes_entry
*next
;
816 AES_KEY aeskey_encrypt
; // encryption key needed by monitor and used by camd33, camd35
817 AES_KEY aeskey_decrypt
; // decryption key needed by monitor and used by camd33, camd35
822 uint8_t ecmd5
[CS_ECMSTORESIZE
];
826 struct s_reader
*reader
;
833 uint8_t emmd5
[CS_EMMSTORESIZE
];
836 struct timeb firstwritten
;
837 struct timeb lastwritten
;
842 uint8_t emmd5
[CS_EMMSTORESIZE
];
845 uint8_t emm
[MAX_EMM_SIZE
];
846 struct timeb firstseen
;
847 struct timeb lastseen
;
850 struct s_csystem_emm_filter
858 typedef struct v_ban
// Failban listmember
865 int32_t acosc_penalty_dur
;
869 typedef struct s_cacheex_stat_entry
// Cacheex stats listmember
874 uint16_t cache_srvid
;
876 int8_t cache_direction
; // 0 = push / 1 = got
877 #ifdef CS_CACHEEX_AIO
878 int32_t cache_count_lg
;
880 } S_CACHEEX_STAT_ENTRY
;
882 typedef struct s_entitlement
// contains entitlement Info
884 uint64_t id
; // the element ID
885 uint32_t type
; // enumerator for tier,chid whatever
886 // 0="", 1="Package", 2="PPV-Event", 3="chid", 4="tier", 5 = "class", 6 = "PBM". 7 = "seca-admin"
887 uint16_t caid
; // the caid of element
888 uint32_t provid
; // the provid of element
889 uint32_t class; // the class needed for some systems
890 time_t start
; // startdate
891 time_t end
; // enddate
902 struct ecm_request_t
;
908 #define DEFAULT_MODULE_BUFSIZE 1024
914 int8_t large_ecm_support
;
915 int16_t listenertype
;
919 void *(*s_handler
)(struct s_client
*, uint8_t *, int32_t);
920 void (*s_init
)(struct s_client
*);
921 int32_t (*recv
)(struct s_client
*, uint8_t *, int32_t);
922 void (*send_dcw
)(struct s_client
*, struct ecm_request_t
*);
923 void (*cleanup
)(struct s_client
*);
924 int32_t (*c_recv_chk
)(struct s_client
*, uint8_t *, int32_t *, uint8_t *, int32_t);
925 int32_t (*c_init
)(struct s_client
*);
926 int32_t (*c_send_ecm
)(struct s_client
*, struct ecm_request_t
*);
927 int32_t (*c_send_emm
)(struct emm_packet_t
*);
928 int32_t (*c_available
)(struct s_reader
*, int32_t, struct ecm_request_t
*); // Schlocke: available check for load-balancing,
930 // rdr (reader to check)
931 // int32_t checktype (0=return connected, 1=return loadbalance-avail) return int
932 void (*c_idle
)(void); // Schlocke: called when reader is idle
933 void (*s_idle
)(struct s_client
*);
934 void (*s_peer_idle
)(struct s_client
*);
935 void (*c_card_info
)(void); // Schlocke: request card infos
937 int32_t (*c_capmt
)(struct s_client
*, struct demux_s
*);
940 int32_t (*c_cache_push
)(struct s_client
*, struct ecm_request_t
*); // Cache push
941 int32_t (*c_cache_push_chk
)(struct s_client
*, struct ecm_request_t
*); // Cache push Node Check, 0=no push
950 struct s_cardreader_settings
968 int32_t (*reader_init
)(struct s_reader
*);
969 int32_t (*get_status
)(struct s_reader
*, int *);
970 int32_t (*activate
)(struct s_reader
*, struct s_ATR
*);
971 int32_t (*transmit
)(struct s_reader
*, uint8_t *sent
, uint32_t size
, uint32_t expectedlen
, uint32_t delay
, uint32_t timeout
);
972 int32_t (*receive
)(struct s_reader
*, uint8_t *data
, uint32_t size
, uint32_t delay
, uint32_t timeout
);
973 int32_t (*lock_init
)(struct s_reader
*);
974 void (*lock
)(struct s_reader
*);
975 void (*unlock
)(struct s_reader
*);
976 int32_t (*close
)(struct s_reader
*);
977 int32_t (*set_parity
)(struct s_reader
*, uint8_t parity
);
978 int32_t (*write_settings
)(struct s_reader
*, struct s_cardreader_settings
*s
);
979 int32_t (*set_protocol
)(struct s_reader
*, uint8_t *params
, uint32_t *length
, uint32_t len_request
);
980 int32_t (*set_baudrate
)(struct s_reader
*, uint32_t baud
); // set only for readers which need baudrate setting and timings need to be guarded by OSCam
981 int32_t (*card_write
)(struct s_reader
*pcsc_reader
, const uint8_t *buf
, uint8_t *cta_res
, uint16_t *cta_lr
, int32_t l
);
982 void (*display_msg
)(struct s_reader
*, char *msg
);
984 int32_t (*do_reset
)(struct s_reader
*, struct s_ATR
*, int32_t (*rdr_activate_card
)(struct s_reader
*, struct s_ATR
*, uint16_t deprecated
), int32_t (*rdr_get_cardsystem
)(struct s_reader
*, struct s_ATR
*));
986 bool (*set_DTS_RTS
)(struct s_reader
*, int32_t *dtr
, int32_t *rts
);
988 int32_t typ
; // fixme: workaround, remove when all old code is converted
990 int8_t max_clock_speed
; // 1 for reader->typ > R_MOUSE
991 int8_t need_inverse
; // 0 = reader does inversing; 1 = inversing done by oscam
994 int8_t read_written
; // 1 = written bytes has to read from device
995 bool skip_extra_atr_parsing
;
996 bool skip_t1_command_retries
;
997 bool skip_setting_ifsc
;
1003 const uint16_t *caids
;
1004 int32_t (*card_init
)(struct s_reader
*reader
, struct s_ATR
*);
1005 void (*card_done
)(struct s_reader
*reader
);
1006 int32_t (*card_info
)(struct s_reader
*);
1007 void (*poll_status
)(struct s_reader
*);
1008 int32_t (*do_ecm
)(struct s_reader
*, const struct ecm_request_t
*, struct s_ecm_answer
*);
1009 int32_t (*do_emm_reassembly
)(struct s_reader
*, struct s_client
*, struct emm_packet_t
*); // Returns 1/true if the EMM is ready to be written in the card
1010 int32_t (*do_emm
)(struct s_reader
*, struct emm_packet_t
*);
1011 int32_t (*do_rawcmd
)(struct s_reader
*, struct cmd_packet_t
*);
1012 void (*post_process
)(struct s_reader
*);
1013 int32_t (*get_emm_type
)(struct emm_packet_t
*, struct s_reader
*);
1014 int32_t (*get_emm_filter
)(struct s_reader
*, struct s_csystem_emm_filter
**, uint32_t *);
1015 int32_t (*get_emm_filter_adv
)(struct s_reader
*, struct s_csystem_emm_filter
**, uint32_t *, uint16_t, uint32_t, uint16_t, uint16_t, uint16_t, uint32_t);
1016 int32_t (*get_tunemm_filter
)(struct s_reader
*, struct s_csystem_emm_filter
**, uint32_t *);
1019 typedef struct cw_extendted_t
1021 #ifdef WITH_EXTENDED_CW
1023 uint8_t audio
[4][16]; // 4 x odd/even pairs of 8 byte CWs
1024 uint8_t data
[16]; // odd/even pair of 8 byte CW or 16 byte IV
1025 uint8_t session_word
[32]; // odd/even pair of 16 byte CW
1026 uint8_t algo
; // CSA, DES or AES128
1027 uint8_t algo_mode
; // ECB or CBC
1033 typedef struct ecm_request_t
1035 uint8_t ecm
[MAX_ECM_SIZE
];
1038 uint8_t ecmd5
[CS_ECMSTORESIZE
];
1041 uint16_t ocaid
; // original caid, used for betatunneling
1046 uint32_t ens
; // enigma namespace
1047 uint32_t vpid
; // videopid
1052 struct s_reader
*selected_reader
;
1053 struct s_ecm_answer
*matching_rdr
; // list of matching readers
1054 const struct s_reader
*fallback
; // fallback is the first fallback reader in the list matching_rdr
1055 struct s_client
*client
; // contains pointer to 'c' client while running in 'r' client
1057 int32_t msgid
; // client pending table index
1058 uint8_t stage
; // processing stage in server module
1061 struct timeb tps
; // incoming time stamp
1062 int8_t btun
; // mark er as betatunneled
1063 uint16_t reader_avail
; // count of available readers for ecm
1064 uint16_t readers
; // count of available used readers for ecm
1065 uint16_t reader_requested
; // count of real requested readers
1066 uint16_t localreader_count
; // count of selected local readers
1067 uint16_t cacheex_reader_count
; // count of selected cacheex mode-1 readers
1068 uint16_t fallback_reader_count
; // count of selected fb readers
1069 uint16_t reader_count
; // count of selected not fb readers
1070 int8_t preferlocalcards
;
1071 int8_t checked
; // for doublecheck
1072 uint8_t cw_checked
[16]; // for doublecheck
1073 int8_t readers_timeout_check
; // set to 1 after ctimeout occurs and readers not answered are checked
1074 struct s_reader
*origin_reader
;
1076 #if defined MODULE_CCCAM
1077 void *origin_card
; // CCcam preferred card!
1080 #if defined MODULE_GBOX
1081 uint32_t gbox_crc
; // rcrc for gbox, used to identify ECM task in peer responses
1082 uint16_t gbox_cw_src_peer
;
1083 uint16_t gbox_ecm_src_peer
;
1084 uint8_t gbox_ecm_dist
;
1085 uint8_t gbox_ecm_status
;
1086 LLIST
*gbox_cards_pending
; // type gbox_card_pending
1090 uint32_t csp_hash
; // csp has its own hash
1092 struct s_client
*cacheex_src
; // Cacheex origin
1094 int8_t cacheex_pushed
; // to avoid duplicate pushs
1095 uint8_t csp_answered
; // =1 if er get answer by csp
1096 LLIST
*csp_lastnodes
; // last 10 Cacheex nodes atm cc-proto-only
1097 uint32_t cacheex_wait_time
; // cacheex wait time in ms
1098 uint8_t cacheex_wait_time_expired
; // =1 if cacheex wait_time expires
1099 uint16_t cacheex_mode1_delay
; // cacheex mode 1 delay
1100 uint8_t cacheex_hitcache
; // =1 if wait_time due hitcache
1101 void *cw_cache
; // pointer to cw stored in cache
1103 #ifdef CS_CACHEEX_AIO
1104 int32_t ecm_time
; // ecm-time in ms
1105 uint8_t localgenerated
; // flag for local generated CW
1108 uint8_t from_csp
; // =1 if er from csp cache
1109 uint8_t from_cacheex
; // =1 if er from cacheex client pushing cache
1110 uint8_t from_cacheex1_client
; // =1 if er from cacheex-1 client
1111 char msglog
[MSGLOGSIZE
];
1112 uint8_t cwc_cycletime
;
1113 uint8_t cwc_next_cw_cycle
;
1114 #ifdef CW_CYCLE_CHECK
1115 char cwc_msg_log
[MSGLOGSIZE
];
1120 struct ecm_request_t
*parent
;
1121 struct ecm_request_t
*next
;
1123 uint8_t adapter_index
;
1131 struct s_reader
*reader
;
1137 char msglog
[MSGLOGSIZE
];
1138 struct timeb time_request_sent
; // using for evaluate ecm_time
1140 uint16_t tier
; // only filled by local videoguard reader atm
1145 struct s_ecm_answer
*next
;
1146 CS_MUTEX_LOCK ecmanswer_lock
;
1147 struct s_ecm_answer
*pending
;
1148 struct s_ecm_answer
*pending_next
;
1154 uint16_t ac_count
: 15;
1155 uint16_t ac_deny
: 1;
1161 uint8_t idx
; // current active index in stat[]
1171 struct s_cascadeuser
1180 typedef struct sidtabs
1182 SIDTABBITS ok
; // positive services
1183 SIDTABBITS no
; // negative services
1192 int8_t request_stage
;
1201 uint8_t emm
[MAX_EMM_SIZE
];
1208 pthread_mutex_t thread_lock
;
1209 int8_t thread_active
;
1211 int8_t kill_started
;
1215 time_t login
; // connection
1216 time_t logout
; // disconnection
1221 time_t expirationdate
;
1222 uint32_t allowedtimeframe
[SIZE_SHORTDAY
][24][2]; // day[0-sun to 6-sat, 7-ALL],hours,minutes use as binary flags to reduce mem usage
1223 uint8_t allowedtimeframe_set
; // flag for internal use to mention if allowed time frame is used
1224 int8_t c35_suppresscmd08
;
1225 uint8_t c35_sleepsend
;
1226 int8_t ncd_keepalive
;
1231 LLIST
*aureader_list
;
1233 LLIST
*ra_buf
; // EMM reassembly buffer for viaccess
1234 struct emm_rass
*cw_rass
; // EMM reassembly buffer for cryptoworks
1240 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
1242 uint16_t last_srvid
;
1243 uint32_t last_provid
;
1245 struct s_provid
*last_providptr
;
1246 struct s_srvid
*last_srvidptr
;
1247 uint32_t last_srvidptr_search_provid
;
1249 struct s_auth
*account
;
1251 struct SOCKADDR udp_sa
;
1252 socklen_t udp_sa_len
;
1256 int32_t cwfound
; // count found ECMs per client
1257 int32_t cwcache
; // count ECMs from cache1/2 per client
1258 int32_t cwnot
; // count not found ECMs per client
1259 int32_t cwtun
; // count betatunneled ECMs per client
1260 int32_t cwignored
; // count ignored ECMs per client
1261 int32_t cwtout
; // count timeouted ECMs per client
1262 int32_t cwlastresptime
; // last Responsetime (ms)
1263 #ifdef CW_CYCLE_CHECK
1264 int32_t cwcycledchecked
; // count checked cwcycles per client
1265 int32_t cwcycledok
; // count pos checked cwcycles per client
1266 int32_t cwcyclednok
; // count neg checked cwcycles per client
1267 int32_t cwcycledign
; // count ign cwcycles per client
1269 int32_t emmok
; // count EMM ok
1270 int32_t emmnok
; // count EMM nok
1271 int8_t pending
; // number of ECMs pending
1273 int32_t cwcacheexpush
; // count pushed ecms/cws
1274 int32_t cwcacheexgot
; // count got ecms/cws
1275 int32_t cwcacheexhit
; // count hit ecms/cws
1276 LLIST
*ll_cacheex_stats
; // list for Cacheex statistics
1277 int8_t cacheex_maxhop
;
1278 int32_t cwcacheexerr
; // cw=00 or chksum wrong
1279 int32_t cwcacheexerrcw
; // same Hex, different CW
1280 int16_t cwcacheexping
; // peer ping in ms, only used by csp
1281 int32_t cwc_info
; // count of in/out comming cacheex ecms with CWCinfo
1282 #ifdef CS_CACHEEX_AIO
1283 int32_t cwcacheexgotlg
; // count got localgenerated-flagged CWs
1284 int32_t cwcacheexpushlg
; // count pushed localgenerated-flagged CWs
1286 uint8_t cacheex_needfilter
; // flag for cachex mode 3 used with camd35
1287 #ifdef CS_CACHEEX_AIO
1288 uint8_t cacheex_aio_checked
; // flag for cacheex aio detection done
1292 struct s_zap_list client_zap_list
[15]; // 15 last zappings from client used for ACoSC
1295 struct s_cwresponse cwlastresptimes
[CS_ECM_RINGBUFFER_MAX
]; // ringbuffer for last 20 times
1296 int32_t cwlastresptimes_last
; // ringbuffer pointer
1297 int8_t wihidden
; // hidden in webinterface status
1298 char lastreader
[64]; // last cw got from this reader
1301 uint8_t ucrc
[4]; // needed by monitor and used by camd35
1302 uint32_t pcrc
; // password crc
1303 struct aes_keys
*aes_keys
; // used by camd33 and camd35
1305 uint16_t ncd_client_id
;
1306 uint8_t ncd_skey
[16]; // Also used for camd35 Cacheex to store remote node id
1312 #ifdef CS_CACHEEX_AIO
1313 #if defined(MODULE_CAMD35) || defined(MODULE_CAMD35_TCP)
1314 uint8_t c35_extmode
;
1320 uint16_t gbox_peer_id
;
1327 int32_t port_idx
; // index in server ptab
1328 int32_t ncd_server
; // newcamd server
1331 int32_t ac_fakedelay
; // When this is -1, the global ac_fakedelay is used
1334 struct s_acasc_shm acasc
;
1338 FTAB ftab
; // user [caid] and ident filter
1341 int32_t pfd
; // Primary FD, must be closed on exit
1342 struct s_reader
*reader
; // points to s_reader when cl->typ='r'
1344 ECM_REQUEST
*ecmtask
;
1348 #ifdef MODULE_SERIAL
1349 struct s_serial_client
*serialdata
;
1356 uint8_t ncd_header
[12];
1365 int8_t disable_counter
;
1366 uint8_t lastserial
[8];
1368 // Failban value set bitwise - compared with BAN_
1371 LLIST
*cascadeusers
; // s_cascadeuser
1373 int32_t n_request
[2]; // count for number of request per minute by client
1375 void *work_mbuf
; // Points to local data allocated in work_thread when the thread is running
1376 void *work_job_data
; // Points to current job_data when work_thread is running
1378 #ifdef MODULE_PANDORA
1379 int32_t pand_autodelay
;
1380 uint8_t pand_send_ecm
;
1381 uint8_t pand_ignore_ecm
;
1382 uint8_t pand_md5_key
[16];
1388 void *module_data
; // private module data
1390 struct s_client
*next
; // make client a linked list
1391 struct s_client
*nexthashed
;
1393 int8_t start_hidecards
;
1396 typedef struct s_ecm_whitelist_data
1401 } ECM_WHITELIST_DATA
;
1403 typedef struct s_ecm_whitelist
1406 ECM_WHITELIST_DATA
*ewdata
;
1409 typedef struct s_ecm_hdr_whitelist_data
1415 } ECM_HDR_WHITELIST_DATA
;
1417 typedef struct s_ecm_hdr_whitelist
1420 ECM_HDR_WHITELIST_DATA
*ehdata
;
1421 } ECM_HDR_WHITELIST
;
1429 uint8_t ecmd5
[CS_ECMSTORESIZE
];
1434 int32_t ratelimitecm
;
1435 int32_t ratelimittime
;
1436 int32_t srvidholdtime
;
1438 #define MAXECMRATELIMIT 20
1440 #ifdef MODULE_SERIAL
1451 typedef struct ce_csp_tab_data
1459 } CECSPVALUETAB_DATA
;
1461 typedef struct ce_csp_tab
1464 CECSPVALUETAB_DATA
*cevdata
;
1467 typedef struct cacheex_check_cw_tab_data
1477 typedef struct cacheex_check_cw_tab
1480 CWCHECKTAB_DATA
*cwcheckdata
;
1484 typedef struct cacheex_check_cw
1490 typedef struct ce_csp_t
1494 #ifdef CS_CACHEEX_AIO
1497 CECSPVALUETAB filter_caidtab
;
1498 uint8_t allow_request
;
1499 uint8_t allow_reforward
;
1501 uint8_t allow_filter
;
1502 #ifdef CS_CACHEEX_AIO
1503 uint8_t allow_maxhop
;
1505 uint8_t block_fakecws
;
1506 #ifdef CS_CACHEEX_AIO
1507 uint8_t cw_check_for_push
;
1508 uint8_t localgenerated_only
;
1509 CAIDTAB localgenerated_only_caidtab
;
1511 uint8_t localgenerated_only_in
;
1512 CAIDTAB localgenerated_only_in_caidtab
;
1513 FTAB lg_only_in_tab
;
1514 uint8_t lg_only_in_aio_only
;
1515 uint8_t lg_only_remote_settings
;
1516 int32_t feature_bitfield
;
1517 CAIDVALUETAB cacheex_nopushafter_tab
;
1518 char aio_version
[12];
1522 struct s_emmlen_range
1528 typedef struct emm_packet_t
1530 uint8_t emm
[MAX_EMM_SIZE
];
1534 uint8_t hexserial
[8]; // contains hexserial or SA of EMM
1536 uint8_t skip_filter_check
;
1537 struct s_client
*client
;
1540 typedef struct cmd_packet_t
1542 uint8_t cmd
[MAX_CMD_SIZE
];
1544 struct s_client
*client
;
1547 struct s_reader
// contains device info, reader info and card info
1550 uint8_t changes_since_shareupdate
;
1551 int32_t resetcycle
; // ECM until reset
1552 int32_t resetcounter
; // actual count
1553 uint32_t auprovid
; // AU only for this provid
1554 int8_t audisabled
; // exclude reader from auto AU
1556 int8_t needsemmfirst
; // 0: reader descrambles without emm first, 1: reader needs emms before it can descramble
1557 struct timeb emm_last
; // time of last successfully written emm
1559 int8_t autospeed
; // 1 clockspeed set according to atr f max
1560 struct s_client
*client
; // pointer to 'r'client this reader is running in
1561 LLIST
*ll_entitlements
; // entitlements
1564 int8_t dropbadcws
; // Schlocke: 1=drops cw if checksum is wrong. 0=fix checksum (default)
1565 int8_t disablecrccws
; // 1=disable cw checksum test. 0=enable checksum check
1568 FTAB fallback_percaid
;
1570 FTAB disablecrccws_only_for
; // ignore checksum for selected caid provid
1571 #ifdef READER_CRYPTOWORKS
1572 int8_t needsglobalfirst
; // 0:Write one Global EMM for SHARED EMM disabled 1:Write one Global EMM for SHARED EMM enabled
1574 #if defined(READER_NAGRA)
1575 uint8_t cak63nuid
[4];
1576 uint8_t cak63nuid_length
;
1577 uint8_t cak63cwekey
[16];
1578 uint8_t cak63cwekey_length
;
1580 #ifdef READER_NAGRA_MERLIN
1582 uint8_t mod1_length
;
1583 uint8_t cmd0eprov
[2];
1584 uint8_t cmd0eprov_length
;
1586 uint8_t mod2_length
;
1587 uint8_t tmprsa
[112];
1589 uint8_t data50_length
;
1591 uint8_t mod50_length
;
1592 uint8_t key3588
[136];
1593 uint8_t key3588_length
;
1598 uint8_t key3des
[16];
1599 uint8_t klucz68
[24];
1602 uint8_t key3460
[96];
1603 uint8_t key3460_length
;
1604 uint8_t key3310
[16];
1605 uint8_t key3310_length
;
1606 uint8_t cwekey
[8][16];
1607 uint8_t cwekey_length
[8];
1609 uint8_t idird_length
;
1610 uint8_t kdt05_00
[216];
1611 uint8_t kdt05_10
[208];
1616 uint8_t ideakey1
[16];
1620 uint32_t dword_83DBC
;
1622 uint8_t ecmheader
[4];
1623 uint8_t timestmp1
[4];
1624 uint8_t timestmp2
[4];
1625 uint8_t cak7expo
[0x11];
1627 uint8_t step1
[0x60];
1628 uint8_t step2
[0x68];
1629 uint8_t step3
[0x6c];
1630 uint8_t encrypted
[0x68];
1631 uint8_t result
[104];
1632 uint8_t stillencrypted
[0x50];
1633 uint8_t resultrsa
[0x50];
1635 uint32_t needrestart
;
1637 uint8_t otpcsc_length
;
1639 uint8_t otacsc_length
;
1640 uint8_t forcepair
[1];
1641 uint8_t forcepair_length
;
1642 uint8_t cak7_camstate
;
1643 uint8_t cak7_aes_key
[32];
1644 uint8_t cak7_aes_iv
[16];
1652 CECSP cacheex
; // CacheEx Settings
1660 uint16_t slot
; // in case of multiple slots like sc8in1; first slot = 1
1661 int32_t handle
; // device handle
1662 int64_t handle_nr
; // device handle_nr for mutiple readers same driver
1663 int32_t fdmc
; // device handle for multicam
1665 int32_t mhz
; // actual clock rate of reader in 10khz steps
1666 int32_t cardmhz
; // standard clock speed your card should have in 10khz steps; normally 357 but for Irdeto cards 600
1667 int32_t divider
; // PLL divider for internal readers
1676 uint8_t cwpkcaid
[2];
1677 uint8_t cwpkcaid_length
;
1679 uint8_t nuid_length
;
1680 int8_t nagra_read
; // read nagra ncmed records: 0 Disabled (default), 1 read all records, 2 read valid records only
1681 int8_t detect_seca_nagra_tunneled_card
;
1682 int8_t force_irdeto
;
1683 uint8_t boxkey
[16]; // n3 boxkey 8 bytes, seca sessionkey 16 bytes, viaccess camid 4 bytes
1684 uint8_t boxkey_length
;
1685 uint8_t rsa_mod
[120]; // rsa modulus for nagra cards.
1686 uint8_t rsa_mod_length
;
1687 uint8_t cwpk_mod
[16]; // cwpk modulus for conax cards.
1688 uint8_t cwpk_mod_length
;
1689 uint8_t des_key
[128]; // 3des key for Viaccess 16 bytes, des key for Dre 128 bytes
1690 uint8_t des_key_length
;
1692 uint8_t card_atr
[64]; // ATR readed from card
1693 int8_t card_atr_length
; // length of ATR
1694 int8_t seca_nagra_card
; // seca nagra card
1698 uint8_t hexserial
[8];
1705 uint8_t prid
[CS_MAXPROV
][8];
1706 uint8_t sa
[CS_MAXPROV
][4]; // viaccess & seca
1707 uint8_t emm84
[CS_MAXPROV
][3];
1708 uint8_t emm83u
[CS_MAXPROV
][6];
1709 uint8_t emm83s
[CS_MAXPROV
][6];
1710 uint8_t emm87
[CS_MAXPROV
][6];
1712 uint8_t read_old_classes
; // viaccess
1713 uint8_t maturity
; // viaccess & seca maturity level
1717 int8_t ecmcommand
; // used for filtering nagra bad ecm commands
1718 uint8_t ecmcommandcache
[5]; // cachebuff for ecm commands
1721 LLIST
*blockemmbylen
;
1727 int16_t deviceemm
; // catch device specific emms (so far only used for viaccess)
1729 int8_t deprecated
; // if 0 ATR obeyed, if 1 default speed (9600) is chosen; for devices that cannot switch baudrate
1731 const struct s_cardreader
*crdr
;
1732 void *crdr_data
; // Private card reader data
1733 bool crdr_flush
; // sci readers may disable flush per reader
1734 const struct s_cardsystem
*csystem
;
1735 void *csystem_data
; // Private card system data
1736 bool csystem_active
;
1737 uint8_t ncd_key
[14];
1738 uint8_t ncd_skey
[16];
1739 int8_t ncd_connect_on_init
;
1740 int8_t ncd_disable_server_filt
;
1742 int8_t currenthops
; // number of hops (cccam & gbox)
1743 int8_t sh4_stb
; // to set sh4 type box used to identify sci type.
1745 char cc_version
[7]; // cccam version
1746 char cc_build
[7]; // cccam build number
1747 int8_t cc_maxhops
; // cccam max distance
1748 int8_t cc_mindown
; // cccam min downhops
1749 int8_t cc_want_emu
; // Schlocke: Client want to have EMUs, 0 - NO; 1 - YES
1751 int8_t cc_keepalive
;
1752 int8_t cc_hop
; // For non-cccam reader: hop for virtual cards
1754 int32_t cc_reconnect
; // reconnect on ecm-request timeout
1756 int8_t tcp_connected
;
1757 int32_t tcp_ito
; // inactivity timeout
1758 int32_t tcp_rto
; // reconnect timeout
1759 int32_t tcp_reconnect_delay
; // max tcp connection block delay
1761 struct timeb tcp_block_connect_till
; // time tcp connect ist blocked
1762 int32_t tcp_block_delay
; // incrementing block time
1763 time_t last_g
; // get (if last_s-last_g>tcp_rto - reconnect )
1764 time_t last_s
; // send
1765 time_t last_check
; // last checked
1766 time_t last_poll
; // last poll
1770 ECM_WHITELIST ecm_whitelist
;
1771 ECM_HDR_WHITELIST ecm_hdr_whitelist
;
1774 int32_t secatype
; // 0=not determined, 2=seca2, 3=nagra(~seca3) this is only valid for localreaders!
1775 uint32_t maxreadtimeout
; // in us
1776 uint32_t minreadtimeout
; // in us
1777 uint32_t maxwritetimeout
; // in us
1778 uint32_t minwritetimeout
; // in us
1779 #if defined(WEBIF) || defined(LCDSUPPORT)
1780 int32_t emmwritten
[4]; // count written EMM
1781 int32_t emmskipped
[4]; // count skipped EMM
1782 int32_t emmerror
[4]; // count error EMM
1783 int32_t emmblocked
[4]; // count blocked EMM
1784 int32_t webif_emmwritten
[4]; // count written EMM for webif reader info
1785 int32_t webif_emmskipped
[4]; // count skipped EMM for webif reader info
1786 int32_t webif_emmerror
[4]; // count error EMM for reader webif info
1787 int32_t webif_emmblocked
[4]; // count blocked EMM for reader webif info
1788 int32_t lbvalue
; // loadbalance Value
1793 int32_t use_gpio
; // Should this reader use GPIO functions
1794 int gpio_outen
; // fd of opened /dev/gpio/outen
1795 int gpio_out
; // fd of opened /dev/gpio/out
1796 int gpio_in
; // fd of opened /dev/gpio/in
1797 uint32_t gpio
; // gpio addr
1798 #ifdef WITH_CARDREADER
1799 // variables from icc_async.h start
1800 int32_t convention
; // Convention of this ICC
1801 uint8_t protocol_type
; // Type of protocol
1802 uint32_t current_baudrate
; // (for overclocking uncorrected) baudrate to prevent unnecessary conversions from/to termios structure
1803 double worketu
; // in us for internal and external readers calculated (1/D)*(F/cardclock)*1000000
1804 uint32_t read_timeout
; // Max timeout (ETU) to receive characters
1805 uint32_t char_delay
; // Delay (ETU) after transmiting each successive char
1806 uint32_t block_delay
; // Delay (ms) after starting to transmit
1807 uint32_t BWT
, CWT
; // (for overclocking uncorrected) block waiting time, character waiting time, in ETU
1808 // variables from io_serial.h
1809 int32_t written
; // keep score of how much bytes are written to serial port, since they are echoed back they have to be read
1810 // variables from protocol_t1.h
1811 uint16_t ifsc
; // Information field size for the ICC
1812 uint8_t ns
; // Send sequence number
1813 int16_t smartdev_found
;
1818 #ifdef READER_CRYPTOWORKS
1819 EMM_PACKET
*last_g_emm
; // last global EMM
1820 bool last_g_emm_valid
; // status of last global EMM
1824 uint8_t payload4C
[15];
1828 uint8_t VgCountryC
[3];
1829 uint8_t VgRegionC
[8];
1830 uint8_t VgLastPayload
[6];
1832 int32_t lb_weight
; // loadbalance weight factor, if unset, weight=100. The higher the value, the higher the usage-possibility
1833 int8_t lb_force_fallback
; // force this reader as fallback if fallback or fallback_percaid paramters set
1834 int32_t lb_usagelevel
; // usagelevel for loadbalancer
1835 int32_t lb_usagelevel_ecmcount
;
1836 struct timeb lb_usagelevel_time
; // time for counting ecms, this creates usagelevel
1837 struct timeb lb_last
; // time for oldest reader
1838 LLIST
*lb_stat
; // loadbalancer reader statistics
1839 CS_MUTEX_LOCK lb_stat_lock
;
1840 int32_t lb_stat_busy
; // do not add while saving
1843 AES_ENTRY
*aes_list
; // multi AES linked list
1844 int8_t ndsversion
; // 0 auto (default), 1 NDS1, 12 NDS1+, 2 NDS2
1845 time_t card_valid_to
;
1847 int32_t ratelimitecm
;
1848 int32_t ratelimittime
; // ratelimit time in ms (everything below 60 ms is converted to ms by applying *1000)
1849 int8_t ecmunique
; // check for matching ecm hash in ratelimitslot
1850 int32_t srvidholdtime
; // time in ms to keep srvid in ratelimitslot (during this time not checked for ecmunique!)
1851 // (everything below 60 ms is converted to ms by applying *1000)
1852 struct timeb lastdvbapirateoverride
;
1854 #ifdef CS_CACHEEX_AIO
1857 uint32_t webif_ecmsok
;
1859 uint32_t webif_ecmsnok
;
1861 uint32_t webif_ecmstout
;
1862 uint32_t ecmnotfoundlimit
; // config setting. restart reader if ecmsnok >= ecmnotfoundlimit
1863 int32_t ecmsfilteredhead
; // count filtered ECM's by ECM Headerwhitelist
1864 int32_t ecmsfilteredlen
; // count filtered ECM's by ECM Whitelist
1865 int32_t webif_ecmsfilteredhead
; // count filtered ECM's by ECM Headerwhitelist to readers ecminfo
1866 int32_t webif_ecmsfilteredlen
; // count filtered ECM's by ECM Whitelist to readers ecm info
1868 #ifdef CS_CACHEEX_AIO
1869 float ecmshealthoklg
;
1871 float ecmshealthnok
;
1872 float ecmshealthtout
;
1873 int32_t cooldown
[2];
1874 int8_t cooldownstate
;
1875 struct timeb cooldowntime
;
1876 struct ecmrl rlecmh
[MAXECMRATELIMIT
];
1879 int8_t readtiers
; // method to get videoguard tiers
1880 uint8_t ins7E
[0x1A + 1];
1881 uint8_t ins7E11
[0x01 + 1];
1882 uint8_t ins42
[0x25 + 1];
1883 uint8_t ins2e06
[0x04 + 1];
1884 int8_t ins7e11_fast_reset
;
1885 uint8_t k1_generic
[0x10 + 1]; // k1 for generic pairing mode
1886 uint8_t k1_unique
[0x10 + 1]; // k1 for unique pairing mode
1887 uint8_t sc8in1_dtrrts_patch
; // fix for kernel commit 6a1a82df91fa0eb1cc76069a9efe5714d087eccd
1889 #ifdef READER_VIACCESS
1890 uint8_t initCA28
; // To set when CA28 succeed
1891 uint32_t key_schedule1
[32];
1892 uint32_t key_schedule2
[32];
1895 #if defined(READER_DRE) || defined(READER_DRECAS)
1900 #ifdef READER_DRECAS
1905 uint8_t gbox_maxdist
;
1906 uint8_t gbox_maxecmsend
;
1907 uint8_t gbox_reshare
;
1908 int8_t gbox_cccam_reshare
;
1909 char last_gsms
[128];
1910 uint16_t gbox_remm_peer
;
1911 uint16_t gbox_gsms_peer
;
1912 uint8_t gbox_force_remm
;
1913 uint16_t gbox_cw_src_peer
;
1914 uint8_t gbox_crd_slot_lev
;
1915 FTAB ccc_gbx_reshare_ident
;
1916 uint8_t send_offline_cmd
;
1917 uint16_t nb_send_crds
;
1920 #ifdef MODULE_PANDORA
1921 uint8_t pand_send_ecm
;
1924 uint8_t ghttp_use_ssl
;
1927 FTAB emu_auproviders
; // AU providers for Emu reader
1928 int8_t emu_datecodedenabled
; // date-coded keys for BISS
1930 uint8_t cnxlastecm
; // == 0 - last ecm has not been paired ecm, > 0 last ecm has been paired ecm
1931 LLIST
*emmstat
; // emm stats
1932 CS_MUTEX_LOCK emmstat_lock
;
1933 struct s_reader
*next
;
1943 struct s_cpmap
*next
;
1955 CECSP cacheex
; // CacheEx Settings
1956 uint8_t no_wait_time
;
1957 uint8_t disablecrccacheex
;
1958 FTAB disablecrccacheex_only_for
;
1960 int16_t allowedprotocols
;
1961 LLIST
*aureader_list
;
1963 uint8_t emm_reassembly
; // 0 = OFF; 1 = OFF / DVBAPI = ON; 2 = ON (default)
1971 FTAB ftab
; // user [caid] and ident filter
1974 int8_t preferlocalcards
;
1975 uint32_t max_connections
;
1977 int32_t ac_fakedelay
; // When this is -1, the global ac_fakedelay is used
1978 int32_t ac_users
; // 0 - unlimited
1979 int8_t ac_penalty
; // 0 - log, >0 - fake dw
1980 struct s_acasc ac_stat
;
1981 int8_t acosc_max_ecms_per_minute
; // user value 0 - unlimited
1982 int8_t acosc_max_active_sids
; // user value 0 - unlimited
1983 int8_t acosc_zap_limit
; // user value 0 - unlimited
1984 int8_t acosc_penalty
; // user value penalty
1985 int32_t acosc_penalty_duration
; // user value how long is penalty activ in sek.
1986 time_t acosc_penalty_until
;
1987 int8_t acosc_penalty_active
; // 0-deaktiv 1-max_active_sids 2-zap_limit 3-max_ecms_per_minute 4-penaly_duration
1988 int32_t acosc_delay
; // user value
1989 int8_t acosc_user_zap_count
;
1990 time_t acosc_user_zap_count_start_time
;
1993 int32_t lb_nbest_readers
; // When this is -1, the global lb_nbest_readers is used
1994 int32_t lb_nfb_readers
; // When this is -1, the global lb_nfb_readers is used
1995 CAIDVALUETAB lb_nbest_readers_tab
; // like nbest_readers, but for special caids
1999 time_t expirationdate
;
2001 uint32_t allowedtimeframe
[SIZE_SHORTDAY
][24][2]; // day[0-sun to 6-sat, 7-ALL],hours,minutes use as binary flags to reduce mem usage
2002 uint8_t allowedtimeframe_set
; // flag for internal use to mention if allowed time frame is used
2003 int8_t c35_suppresscmd08
;
2004 uint8_t c35_sleepsend
;
2005 int8_t ncd_keepalive
;
2009 int8_t cccignorereshare
;
2021 #ifdef CW_CYCLE_CHECK
2022 int32_t cwcycledchecked
; // count checked cwcycles per client
2023 int32_t cwcycledok
; // count pos checked cwcycles per client
2024 int32_t cwcyclednok
; // count neg checked cwcycles per client
2025 int32_t cwcycledign
; // count ign cwcycles per client
2026 int8_t cwc_disable
; // disable cwc checking for this Client
2031 int32_t cwcacheexpush
; // count pushed ecms/cws
2032 int32_t cwcacheexgot
; // count got ecms/cws
2033 int32_t cwcacheexhit
; // count hit ecms/cws
2034 int32_t cwcacheexerr
; // cw=00 or chksum wrong
2035 int32_t cwcacheexerrcw
; // Same Hex, different CW
2036 int32_t cwc_info
; // count of in/out comming cacheex ecms with CWCinfo
2037 #ifdef CS_CACHEEX_AIO
2038 int32_t cwcacheexgotlg
; // count got localgenerated-flagged CWs
2039 int32_t cwcacheexpushlg
; // count pushed localgenerated-flagged CWs
2042 struct s_auth
*next
;
2057 struct s_srvid_caid
*caid
;
2063 struct s_srvid
*next
;
2069 struct s_rlimit
*next
;
2083 #ifdef MODULE_SERIAL
2087 struct s_twin
*next
;
2097 struct s_tierid
*next
;
2108 struct s_provid
*next
;
2117 struct s_global_whitelist
2119 uint32_t line
; // linenr of oscam.whitelist file, starting with 1
2120 char type
; // w or i or l
2129 struct s_global_whitelist
*next
;
2132 struct s_cacheex_matcher
2134 uint32_t line
; // linenr of oscam.Cacheex file, starting with 1
2153 struct s_cacheex_matcher
*next
;
2162 CAIDVALUETAB ftimeouttab
;
2174 int8_t disablecrccws
; // 1=disable cw checksum test. 0=enable checksum check
2175 FTAB disablecrccws_only_for
; // ignore checksum for selected caid provid
2176 uint8_t logtostdout
;
2177 uint8_t logtosyslog
;
2178 int8_t logduplicatelines
;
2179 int32_t initial_debuglevel
;
2182 #if defined(WEBIF) || defined(MODULE_MONITOR)
2183 uint32_t loghistorylines
;
2187 int8_t disableuserfile
;
2189 struct s_auth
*account
;
2190 struct s_srvid
*srvid
[16];
2191 struct s_tierid
*tierid
;
2192 struct s_provid
*provid
;
2193 struct s_sidtab
*sidtab
;
2194 #ifdef MODULE_MONITOR
2196 IN_ADDR_T mon_srvip
;
2197 struct s_ip
*mon_allowed
;
2201 int32_t hideclient_to
;
2204 IN_ADDR_T http_srvip
;
2208 int8_t http_prepend_embedded_css
;
2211 char *http_piconpath
;
2213 #ifndef WEBIF_JQUERY
2214 char *http_extern_jquery
;
2216 int32_t http_refresh
;
2217 int32_t poll_refresh
;
2218 int8_t http_hide_idle_clients
;
2219 char *http_hide_type
;
2220 int8_t http_showpicons
;
2221 int8_t http_picon_size
;
2222 int8_t http_status_log
;
2223 int8_t http_showmeminfo
;
2224 int8_t http_showecminfo
;
2225 int8_t http_showloadinfo
;
2226 int8_t http_showuserinfo
;
2227 int8_t http_showreaderinfo
;
2228 int8_t http_showcacheexinfo
;
2229 struct s_ip
*http_allowed
;
2230 int8_t http_readonly
;
2231 IN_ADDR_T http_dynip
[MAX_HTTP_DYNDNS
];
2232 uint8_t http_dyndns
[MAX_HTTP_DYNDNS
][64];
2233 int8_t http_use_ssl
;
2234 int8_t https_force_secure_mode
;
2236 char *http_help_lang
;
2238 char *http_oscam_label
;
2239 int32_t http_emmu_clean
;
2240 int32_t http_emms_clean
;
2241 int32_t http_emmg_clean
;
2243 int8_t http_full_cfg
;
2244 int8_t http_overwrite_bak_file
;
2245 int32_t failbantime
;
2246 int32_t failbancount
;
2247 LLIST
*v_list
; // Failban list
2248 #ifdef MODULE_CAMD33
2250 IN_ADDR_T c33_srvip
;
2251 uint8_t c33_key
[16];
2252 int32_t c33_crypted
;
2253 int32_t c33_passive
;
2254 struct s_ip
*c33_plain
;
2256 #if defined(MODULE_CAMD35) || defined(MODULE_CAMD35_TCP)
2258 IN_ADDR_T c35_srvip
;
2259 int8_t c35_tcp_suppresscmd08
;
2260 int8_t c35_udp_suppresscmd08
;
2262 IN_ADDR_T c35_tcp_srvip
;
2264 int8_t c35_suppresscmd08
; // used in cccam module
2265 int8_t getblockemmauprovid
;
2266 int32_t umaxidle
; //User max Idle
2267 #ifdef MODULE_NEWCAMD
2269 IN_ADDR_T ncd_srvip
;
2270 uint8_t ncd_key
[14];
2271 int8_t ncd_keepalive
;
2272 int8_t ncd_mgclient
;
2273 struct s_ip
*ncd_allowed
;
2275 #ifdef MODULE_RADEGAST
2277 IN_ADDR_T rad_srvip
;
2278 struct s_ip
*rad_allowed
;
2282 uint16_t cc_port
[CS_MAXPORTS
];
2284 int8_t cc_ignore_reshare
;
2285 int32_t cc_update_interval
;
2288 int8_t cc_minimize_cards
;
2289 int8_t cc_keep_connected
;
2291 int8_t cc_reshare_services
;
2292 int8_t cc_forward_origin_card
;
2293 uint8_t cc_fixed_nodeid
[8];
2294 uint32_t cc_recv_timeout
; // The poll() timeout parameter in ms. Default: DEFAULT_CC_RECV_TIMEOUT (2000 ms).
2297 #define GBOX_MY_VERS_DEF 0x2A
2298 #define GBOX_MY_CPU_API_DEF 0x61
2299 #define GBOX_MAX_PROXY_CARDS 32
2300 #define GBOX_MAX_IGNORED_PEERS 16
2301 #define GBOX_MAX_BLOCKED_ECM 16
2302 #define GBOX_MAX_REMM_PEERS 8
2303 #define GBOX_MAX_DEST_PEERS 16
2304 #define GBOX_MAX_MSG_TXT 127
2305 uint16_t gbox_port
[CS_MAXPORTS
];
2306 char *gbox_hostname
;
2307 uint32_t gbox_reconnect
;
2308 uint32_t gbox_password
;
2309 unsigned long gbox_proxy_card
[GBOX_MAX_PROXY_CARDS
];
2310 int8_t gbox_proxy_cards_num
;
2311 uint32_t gbox_my_vers
;
2312 uint8_t gbox_my_cpu_api
;
2315 uint8_t dis_attack_txt
;
2317 uint8_t cc_gbx_reshare_en
;
2318 uint16_t gbox_ignored_peer
[GBOX_MAX_IGNORED_PEERS
];
2319 uint8_t gbox_ignored_peer_num
;
2320 uint16_t accept_remm_peer
[GBOX_MAX_REMM_PEERS
];
2321 uint8_t accept_remm_peer_num
;
2322 uint16_t gbox_block_ecm
[GBOX_MAX_BLOCKED_ECM
];
2323 uint8_t gbox_block_ecm_num
;
2324 uint8_t gbox_save_gsms
;
2325 uint8_t gbox_msg_type
;
2326 uint16_t gbox_dest_peers
[GBOX_MAX_DEST_PEERS
];
2327 uint8_t gbox_dest_peers_num
;
2328 char gbox_msg_txt
[GBOX_MAX_MSG_TXT
+1];
2330 #ifdef MODULE_SERIAL
2333 int32_t max_log_size
;
2334 int8_t waitforcards
;
2335 int32_t waitforcards_extra_delay
;
2336 int8_t preferlocalcards
;
2337 int32_t reader_restart_seconds
; // schlocke: reader restart auf x seconds, disable = 0
2338 int8_t dropdups
; // drop duplicate logins
2341 // Loadbalancer-Config:
2342 int32_t lb_mode
; // schlocke: reader loadbalancing mode
2343 int32_t lb_auto_betatunnel
; // automatic selection of betatunnel convertion based on learned data
2344 int32_t lb_auto_betatunnel_mode
; // automatic selection of betatunnel direction
2346 int32_t lb_save
; // schlocke: load/save statistics to file, save every x ecms
2347 int32_t lb_nbest_readers
; // count of best readers
2348 int32_t lb_nfb_readers
; // count of fallback readers
2349 int32_t lb_min_ecmcount
; // minimal ecm count to evaluate lbvalues
2350 int32_t lb_max_ecmcount
; // maximum ecm count before reseting lbvalues
2351 int32_t lb_reopen_seconds
; // time between retrying failed readers/caids/prov/srv
2352 int8_t lb_reopen_invalid
; // default=1; if 0, rc=E_INVALID will be blocked until stats cleaned
2353 int8_t lb_force_reopen_always
; // force reopening immediately all failing readers if no matching reader found
2354 int32_t lb_retrylimit
; // reopen only happens if reader response time > retrylimit
2355 CAIDVALUETAB lb_retrylimittab
;
2356 CAIDVALUETAB lb_nbest_readers_tab
; // like nbest_readers, but for special caids
2357 CAIDTAB lb_noproviderforcaid
; // do not store loadbalancer stats with providers for this caid
2358 char *lb_savepath
; // path where the stat file is save. Empty=default=/tmp/.oscam/stat
2359 int32_t lb_stat_cleanup
; // duration in hours for cleaning old statistics
2360 int32_t lb_max_readers
; // limit the amount of readers during learning
2361 int32_t lb_auto_betatunnel_prefer_beta
; // prefer-beta-over-nagra factor
2362 int32_t lb_auto_timeout
; // Automatic timeout by loadbalancer statistics
2363 int32_t lb_auto_timeout_p
; // percent added to avg time as timeout time
2364 int32_t lb_auto_timeout_t
; // minimal time added to avg time as timeout time
2366 int32_t resolve_gethostbyname
;
2367 int8_t double_check
; // schlocke: Double checks each ecm+dcw from two (or more) readers
2368 FTAB double_check_caid
; // do not store loadbalancer stats with providers for this caid
2371 int8_t dvbapi_enabled
;
2374 int8_t dvbapi_boxtype
;
2375 int8_t dvbapi_pmtmode
;
2376 int8_t dvbapi_requestmode
;
2377 int32_t dvbapi_listenport
; // TCP port to listen instead of camd.socket (network mode, default=0 -> disabled)
2378 SIDTABS dvbapi_sidtabs
;
2379 int32_t dvbapi_delayer
; // delayer ms, minimum time to write cw
2380 int8_t dvbapi_ecminfo_file
; // Enable or disable ecm.info file creation
2381 int8_t dvbapi_ecminfo_type
;
2382 int8_t dvbapi_read_sdt
;
2383 int8_t dvbapi_write_sdt_prov
;
2384 int8_t dvbapi_extended_cw_api
;
2385 #ifdef MODULE_STREAMRELAY
2386 int8_t dvbapi_demuxer_fix
;
2392 int32_t ac_users
; // num of users for account (0 - default)
2393 int32_t ac_stime
; // time to collect AC statistics (3 min - default)
2394 int32_t ac_samples
; // qty of samples
2395 int8_t ac_penalty
; // 0 - write to log
2396 int32_t ac_fakedelay
; // 100-1000 ms
2397 int32_t ac_denysamples
;
2399 struct s_cpmap
*cpmap
;
2400 int8_t acosc_enabled
;
2401 int8_t acosc_max_ecms_per_minute
; // global value 0 - unlimited
2402 int8_t acosc_max_active_sids
; // global value 0 - unlimited
2403 int8_t acosc_zap_limit
; // global value 0 - unlimited
2404 int32_t acosc_penalty_duration
; // global value how long is penalty activ in sek.
2405 int8_t acosc_penalty
; // global value
2406 int32_t acosc_delay
; // global value
2410 int8_t enableled
; // 0=disabled led, 1=enable led for routers, 2=enable qboxhd led
2415 char *lcd_output_path
;
2416 int32_t lcd_hide_idle
;
2417 int32_t lcd_write_intervall
;
2420 #ifdef MODULE_PANDORA
2421 int8_t pand_skip_send_dw
;
2422 struct s_ip
*pand_allowed
;
2427 IN_ADDR_T pand_srvip
;
2432 IN_ADDR_T scam_srvip
;
2433 struct s_ip
*scam_allowed
;
2436 #ifdef MODULE_STREAMRELAY
2437 char *stream_source_host
;
2438 int32_t stream_source_port
;
2439 char *stream_source_auth_user
;
2440 char *stream_source_auth_password
;
2441 int32_t stream_relay_port
;
2442 #ifdef MODULE_RADEGAST
2443 int8_t stream_client_source_host
;
2445 int8_t stream_relay_enabled
;
2446 uint32_t stream_relay_buffer_time
;
2447 CAIDTAB stream_relay_ctab
; // use the stream server for these caids
2448 #ifdef WITH_NEUTRINO
2449 #define DEFAULT_STREAM_SOURCE_PORT 31339 //Neutrino
2451 #define DEFAULT_STREAM_SOURCE_PORT 8001 //Enigma2
2455 int32_t max_cache_time
; // seconds ecms are stored in ecmcwcache
2456 int32_t max_hitcache_time
; // seconds hits are stored in cspec_hitcache (to detect dyn wait_time)
2458 int8_t reload_useraccounts
;
2459 int8_t reload_readers
;
2460 int8_t reload_provid
;
2461 int8_t reload_services_ids
;
2462 int8_t reload_tier_ids
;
2463 int8_t reload_fakecws
;
2464 int8_t reload_ac_stat
;
2467 int8_t block_same_ip
; // 0=allow all, 1=block client requests to reader with same ip (default=1)
2468 int8_t block_same_name
; // 0=allow all, 1=block client requests to reader with same name (default=1)
2471 #ifdef CS_CACHEEX_AIO
2472 uint32_t cw_cache_size
;
2473 uint32_t cw_cache_memory
;
2474 CWCHECKTAB cw_cache_settings
;
2476 uint32_t ecm_cache_size
;
2477 uint32_t ecm_cache_memory
;
2478 int32_t ecm_cache_droptime
;
2480 uint8_t wait_until_ctimeout
;
2481 CWCHECKTAB cacheex_cwcheck_tab
;
2482 IN_ADDR_T csp_srvip
;
2484 CECSPVALUETAB cacheex_wait_timetab
;
2485 CAIDVALUETAB cacheex_mode1_delay_tab
;
2486 #ifdef CS_CACHEEX_AIO
2487 CAIDVALUETAB cacheex_nopushafter_tab
;
2488 uint8_t waittime_block_start
;
2489 uint16_t waittime_block_time
;
2491 CECSP csp
; // CSP Settings
2492 uint8_t cacheex_enable_stats
; // enable stats
2493 struct s_cacheex_matcher
*cacheex_matcher
;
2494 #ifdef CS_CACHEEX_AIO
2495 uint8_t cacheex_dropdiffs
;
2496 uint8_t cacheex_lg_only_remote_settings
;
2497 uint8_t cacheex_localgenerated_only
;
2498 CAIDTAB cacheex_localgenerated_only_caidtab
;
2499 FTAB cacheex_lg_only_tab
;
2500 uint8_t cacheex_localgenerated_only_in
;
2501 CAIDTAB cacheex_localgenerated_only_in_caidtab
;
2502 FTAB cacheex_lg_only_in_tab
;
2503 uint8_t cacheex_lg_only_in_aio_only
;
2504 CECSPVALUETAB cacheex_filter_caidtab
;
2505 CECSPVALUETAB cacheex_filter_caidtab_aio
;
2506 uint64_t cacheex_push_lg_groups
;
2510 #ifdef CW_CYCLE_CHECK
2511 int8_t cwcycle_check_enable
; // on or off
2512 CAIDTAB cwcycle_check_caidtab
; // Caid for CW Cycle Check
2513 int32_t keepcycletime
; // how long stay the learned Cycletime in Memory
2514 int32_t maxcyclelist
; // max size of cwcyclelist
2515 int8_t onbadcycle
; // what to do on bad cwcycle
2516 int8_t cwcycle_dropold
; // what to do on old ecmd5/cw
2517 int8_t cwcycle_sensitive
;
2518 int8_t cwcycle_allowbadfromffb
; // allow Bad cycles from Fixed Fallbackreader
2519 int8_t cwcycle_usecwcfromce
; // Use CWC Info from Cacheex Sources for CWC Checking
2522 // Global whitelist:
2523 struct s_global_whitelist
*global_whitelist
;
2524 int8_t global_whitelist_use_l
;
2525 int8_t global_whitelist_use_m
;
2530 int32_t max_pending
;
2533 struct s_rlimit
*ratelimit_list
;
2536 struct s_fakecws fakecws
[0x100];
2538 #ifdef MODULE_SERIAL
2539 struct s_twin
*twin_list
;
2545 void *(*handler
)(struct s_client
*);
2546 struct s_client
*client
;
2556 typedef struct reader_stat_t
2565 struct timeb last_received
;
2569 int32_t time_stat
[LB_MAX_STAT_TIME
];
2572 int32_t fail_factor
;
2575 typedef struct cs_stat_query
2584 struct s_write_from_cache
2586 ECM_REQUEST
*er_new
;
2587 ECM_REQUEST
*er_cache
;
2590 /* ===========================
2592 * =========================== */
2593 extern pthread_key_t getclient
;
2594 extern struct s_client
*first_client
;
2595 extern CS_MUTEX_LOCK config_lock
;
2596 extern CS_MUTEX_LOCK clientlist_lock
;
2597 extern CS_MUTEX_LOCK readerlist_lock
;
2598 extern struct s_reader
*first_active_reader
; // points to list of _active_ readers (enable = 1, deleted = 0)
2599 extern LLIST
*configured_readers
;
2601 // These are used pretty much everywhere
2602 extern struct s_config cfg
;
2603 extern uint16_t cs_dblevel
;
2605 #include "oscam-log.h"
2606 #include "oscam-log-reader.h"
2608 // Add here *only* funcs that are implemented in oscam.c and are called in other places
2609 void cs_exit(int32_t sig
);
2610 void cs_exit_oscam(void);
2611 void cs_restart_oscam(void);
2612 int32_t cs_get_restartmode(void);
2614 void set_thread_name(const char *thread_name
);
2615 int32_t start_thread(char *nameroutine
, void *startroutine
, void *arg
, pthread_t
*pthread
, int8_t detach
, int8_t modify_stacksize
);
2616 int32_t start_thread_nolog(char *nameroutine
, void *startroutine
, void *arg
, pthread_t
*pthread
, int8_t detach
, int8_t modify_stacksize
);
2617 void kill_thread(struct s_client
*cl
);
2619 struct s_module
*get_module(struct s_client
*cl
);
2620 void module_reader_set(struct s_reader
*rdr
);
2622 // Until we find a better place for these (they are implemented in oscam-simples.h)
2623 char *get_servicename(struct s_client
*cl
, uint16_t srvid
, uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
);
2624 char *get_servicename_or_null(struct s_client
*cl
, uint16_t srvid
, uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
);
2625 char *get_picon_servicename_or_null(struct s_client
*cl
, uint16_t srvid
, uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
);
2626 int32_t picon_servicename_remve_hd(char *buf
, uint32_t buflen
);
2627 char *get_tiername(uint16_t tierid
, uint16_t caid
, char *buf
);
2628 char *get_tiername_defaultid(uint16_t tierid
, uint16_t caid
, char *buf
);
2629 char *get_provider(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
);
2630 char *get_providername(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
);
2631 char *get_providername_or_null(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
);
2632 void add_provider(uint16_t caid
, uint32_t provid
, const char *name
, const char *sat
, const char *lang
);
2633 const char *get_cl_lastprovidername(struct s_client
*cl
);
2634 bool boxtype_is(const char *boxtype
);
2635 bool boxname_is(const char *boxname
);
2636 const char *boxtype_get(void);
2637 const char *boxname_get(void);
2638 static inline bool caid_is_fake(uint16_t caid
) { return caid
== 0xffff; }
2639 static inline bool caid_is_biss(uint16_t caid
) { return caid
>> 8 == 0x26; }
2640 static inline bool caid_is_biss_fixed(uint16_t caid
) { return caid
== 0x2600 || caid
== 0x2602; } // fixed cw, fake ecm
2641 static inline bool caid_is_biss_dynamic(uint16_t caid
) { return caid
== 0x2610; } // dynamic cw, real ecm and emm
2642 static inline bool caid_is_seca(uint16_t caid
) { return caid
>> 8 == 0x01; }
2643 static inline bool caid_is_viaccess(uint16_t caid
) { return caid
>> 8 == 0x05; }
2644 static inline bool caid_is_irdeto(uint16_t caid
) { return caid
>> 8 == 0x06; }
2645 static inline bool caid_is_videoguard(uint16_t caid
) { return caid
>> 8 == 0x09; }
2646 static inline bool caid_is_conax(uint16_t caid
) { return caid
>> 8 == 0x0B; }
2647 static inline bool caid_is_cryptoworks(uint16_t caid
) { return caid
>> 8 == 0x0D; }
2648 static inline bool caid_is_powervu(uint16_t caid
) { return caid
>> 8 == 0x0E; }
2649 static inline bool caid_is_director(uint16_t caid
) { return caid
>> 8 == 0x10; }
2650 static inline bool caid_is_betacrypt(uint16_t caid
) { return caid
>> 8 == 0x17; }
2651 static inline bool caid_is_nagra(uint16_t caid
) { return caid
>> 8 == 0x18; }
2652 static inline bool caid_is_bulcrypt(uint16_t caid
) { return caid
== 0x5581 || caid
== 0x4AEE; }
2653 static inline bool caid_is_dre(uint16_t caid
) { return caid
== 0x4AE0 || caid
== 0x4AE1 || caid
== 0x2710;}
2654 const char *get_cardsystem_desc_by_caid(uint16_t caid
);
2657 FILTER
*get_emu_prids_for_caid(struct s_reader
*rdr
, uint16_t caid
);