source: trunk/globals.h

Last change on this file was 11726, checked in by bust3d, 3 weeks ago

Thanks for @Miese.Ratte
Patch for Baseyear
Patch for sendcmd
Patch for SSL

  • Property svn:eol-style set to LF
File size: 80.1 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 <stdint.h>
9#include <stddef.h>
10#include <assert.h>
11#include <fcntl.h>
12#include <sys/ioctl.h>
13#include <poll.h>
14#include <ctype.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17#include <sys/wait.h>
18#include <unistd.h>
19#include <sys/mman.h>
20#include <stdarg.h>
21#include <time.h>
22#include <sys/time.h>
23#include <limits.h>
24#include <pwd.h>
25#include <netinet/tcp.h>
26#include <sys/socket.h>
27#include <netinet/in.h>
28#include <arpa/inet.h>
29#include <netdb.h>
30#include <string.h>
31#include <strings.h>
32#include <signal.h>
33#include <errno.h>
34#include <pthread.h>
35#include <dirent.h>
36#include <termios.h>
37#include <inttypes.h>
38#include <sys/utsname.h>
39
40#if !defined(__APPLE__)
41#include <sys/sysmacros.h>
42#endif
43
44/*
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.
53 */
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
59
60#include "config.h"
61
62#if defined(WITH_SSL) && !defined(WITH_LIBCRYPTO)
63# define WITH_LIBCRYPTO 1
64#endif
65
66/* For deprecated but still needed cryptography functions:
67 * 10002 corresponds to OpenSSL version 1.0.2*/
68
69#define OPENSSL_API_COMPAT 10002
70
71#if defined(__CYGWIN__) || defined(__arm__) || defined(__SH4__) || defined(__MIPS__) || defined(__MIPSEL__) || defined(__powerpc__)
72# define CS_LOGFILE "/dev/tty"
73#endif
74
75#if defined(__AIX__) || defined(__SGI__) || defined(__OSF__) || defined(__HPUX__) || defined(__SOLARIS__) || defined(__APPLE__)
76# define NEED_DAEMON
77#endif
78
79#if defined(__AIX__) || defined(__SGI__) || defined(__OSF__) || defined(__HPUX__) || defined(__SOLARIS__) || defined(__CYGWIN__)
80# define NO_ENDIAN_H
81#endif
82
83#if defined(__AIX__) || defined(__SGI__)
84# define socklen_t unsigned long
85#endif
86
87#if defined(__SOLARIS__) || defined(__FreeBSD__) || defined(__OpenBSD__)
88# define BSD_COMP
89#endif
90
91#if defined(__HPUX__)
92# define _XOPEN_SOURCE_EXTENDED
93#endif
94
95#if (defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)) && !defined(s6_addr32)
96#define s6_addr32 __u6_addr.__u6_addr32
97#endif
98
99#ifdef __ANDROID__
100#ifndef in_port_t
101#define in_port_t uint16_t
102#endif
103#define tcdrain(fd) ioctl(fd, TCSBRK, 1)
104#endif
105
106#ifdef __uClinux__
107#define fork() 0
108#endif
109
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
116#endif
117
118#include "cscrypt/aes.h"
119
120#ifdef IPV6SUPPORT
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
125#else
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
130#endif
131
132#ifndef NO_ENDIAN_H
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
143#else
144#include <endian.h>
145#include <byteswap.h>
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#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
220
221#ifdef WITH_DEBUG
222# define call(arg) \
223 if(arg) \
224 { \
225 cs_log_dbg(D_TRACE, "ERROR, function call %s returns error.",#arg); \
226 return ERROR; \
227 }
228#else
229# define call(arg) \
230 if(arg) \
231 { \
232 return ERROR; \
233 }
234#endif
235
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); }}
238
239#ifdef __CYGWIN__
240#define cs_recv(a,b,c,d) cygwin_recv(a,b,c,d)
241#else
242#define cs_recv(a,b,c,d) recv(a,b,c,d)
243#endif
244
245// safe wrappers to pthread functions
246#define fprintf_stderr(fmt, params...) fprintf(stderr, fmt, ##params)
247
248#define SAFE_PTHREAD_1ARG(a, b, c) { \
249 int32_t pter = a(b); \
250 if(pter != 0) \
251 { \
252 c("FATAL ERROR: %s() failed in %s with error %d %s\n", #a, __func__, pter, strerror(pter)); \
253 } }
254
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)
265
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)
272
273#define SAFE_PTHREAD_2ARG(a, b, c, d) { \
274 int32_t pter = a(b, c); \
275 if(pter != 0) \
276 { \
277 d("FATAL ERROR: %s() failed in %s with error %d %s\n", #a, __func__, pter, strerror(pter)); \
278 } }
279
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)
287
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)
292
293#define SAFE_PTHREAD_1ARG_R(a, b, c, d) { \
294 int32_t pter = a(b); \
295 if(pter != 0) \
296 { \
297 c("FATAL ERROR: %s() failed in %s (called from %s) with error %d %s\n", #a, __func__, d, pter, strerror(pter)); \
298 } }
299
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)
305
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)
309
310#define SAFE_PTHREAD_2ARG_R(a, b, c, d, e) { \
311 int32_t pter = a(b, c); \
312 if(pter != 0) \
313 { \
314 d("FATAL ERROR: %s() failed in %s (called from %s) with error %d %s\n", #a, __func__, e, pter, strerror(pter)); \
315 } }
316
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)
320
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)
324
325#define SAFE_COND_TIMEDWAIT(a, b, c) { \
326 int32_t pter; \
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) \
331 { \
332 cs_log("FATAL ERROR: pthread_cond_timedwait failed in %s with error %d %s\n", __func__, pter, strerror(pter)); \
333 } }
334
335#define SAFE_COND_TIMEDWAIT_R(a, b, c, d) { \
336 int32_t pter; \
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) \
341 { \
342 cs_log("FATAL ERROR: pthread_cond_timedwait failed in %s (called from %s) with error %d %s\n", __func__, d, pter, strerror(pter)); \
343 } }
344
345#define SAFE_ATTR_SETSTACKSIZE(a,b) { \
346 int32_t pter = pthread_attr_setstacksize(a, b); \
347 if(pter != 0) \
348 { \
349 cs_log("WARNING: pthread_attr_setstacksize() failed in %s with error %d %s\n", __func__, pter, strerror(pter)); \
350 } }
351
352#define SAFE_ATTR_SETSTACKSIZE_NOLOG(a,b) { \
353 int32_t pter = pthread_attr_setstacksize(a, b); \
354 if(pter != 0) \
355 { \
356 fprintf_stderr("WARNING: pthread_attr_setstacksize() failed in %s with error %d %s\n", __func__, pter, strerror(pter)); \
357 } }
358
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)
364#endif
365
366#define CHECK_BIT(var,pos) (((var) & (1<<(pos)))? 1 : 0)
367
368/* ===========================
369 * constants
370 * =========================== */
371#define CS_VERSION "1.20_svn"
372#ifndef CS_SVN_VERSION
373# define CS_SVN_VERSION "test"
374#endif
375#ifdef CS_CACHEEX
376#ifdef CS_CACHEEX_AIO
377#define CS_AIO_VERSION CS_SVN_VERSION
378#endif
379#endif
380#ifndef CS_TARGET
381# define CS_TARGET "unknown"
382#endif
383#ifndef CS_CONFDIR
384#define CS_CONFDIR "/usr/local/etc"
385#endif
386#ifndef CS_LOGFILE
387#define CS_LOGFILE "/var/log/oscam.log"
388#endif
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
394
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
400#define CS_DELAY 0
401#define CS_ECM_RINGBUFFER_MAX 0x10 // max size for ECM last responsetimes ringbuffer. Keep this set to power of 2 values!
402
403// Support for multiple CWs per channel and other encryption algos
404//#define WITH_EXTENDED_CW 1
405
406#if defined(READER_DRE) || defined(READER_DRECAS) || defined(READER_VIACCESS) || defined(WITH_EMU)
407#define MAX_ECM_SIZE 1024
408#define MAX_EMM_SIZE 1024
409#else
410#define MAX_ECM_SIZE 596
411#define MAX_EMM_SIZE 512
412#endif
413
414#define MAX_CMD_SIZE 0xff + 5 // maximum value from length byte + command header
415
416#ifdef WITH_EMU
417#define CS_EMMCACHESIZE 1024 // nr of EMMs that EMU reader will cache
418#else
419#define CS_EMMCACHESIZE 512 // nr of EMMs that each reader will cache
420#endif
421#define MSGLOGSIZE 64 // size of string buffer for a ecm to return messages
422
423#define D_TRACE 0x0001 // Generate very detailed error/trace messages per routine
424#define D_ATR 0x0002 // Debug ATR parsing, dump of ecm, cw
425#define D_READER 0x0004 // Debug Reader/Proxy Process
426#define D_CLIENT 0x0008 // Debug Client Process
427#define D_IFD 0x0010 // Debug IFD+protocol
428#define D_DEVICE 0x0020 // Debug Reader I/O
429#define D_EMM 0x0040 // Dumps EMM
430#define D_DVBAPI 0x0080 // Debug DVBAPI
431#define D_LB 0x0100 // Debug Loadbalancer/ECM handler
432#define D_CACHEEX 0x0200 // Debug CACHEEX
433#define D_CLIENTECM 0x0400 // Debug Client ECMs
434#define D_CSP 0x0800 // Debug CSP
435#define D_CWC 0x1000 // Debug CWC
436#ifdef CS_CACHEEX_AIO
437#define D_CW_CACHE 0x2000 // Debug CW Cache
438#endif
439#define D_ALL_DUMP 0xFFFF // dumps all
440
441#ifdef CS_CACHEEX_AIO
442#define MAX_DEBUG_LEVELS 14
443#else
444#define MAX_DEBUG_LEVELS 13
445#endif
446
447/////// phoenix readers which need baudrate setting and timings need to be guarded by OSCam: BEFORE R_MOUSE
448#define R_DB2COM1 0x1 // Reader Dbox2 @ com1
449#define R_DB2COM2 0x2 // Reader Dbox2 @ com1
450#define R_SC8in1 0x3 // Reader Sc8in1 or MCR
451#define R_MP35 0x4 // AD-Teknik Multiprogrammer 3.5 and 3.6 (only usb tested)
452#define R_MOUSE 0x5 // Reader smartcard mouse
453/////// internal readers (Dreambox, Coolstream, IPBox) are all R_INTERNAL, they are determined compile-time
454#define R_INTERNAL 0x6 // Reader smartcard intern
455/////// readers that do not reed baudrate setting and timings are guarded by reader itself (large buffer built in): AFTER R_SMART
456#define R_SMART 0x7 // Smartreader+
457#define R_PCSC 0x8 // PCSC
458#define R_DRECAS 0x9 // Reader DRECAS
459#define R_EMU 0x17 // Reader EMU
460/////// proxy readers after R_CS378X
461#define R_CAMD35 0x20 // Reader cascading camd 3.5x
462#define R_CAMD33 0x21 // Reader cascading camd 3.3x
463#define R_NEWCAMD 0x22 // Reader cascading newcamd
464#define R_RADEGAST 0x23 // Reader cascading radegast
465#define R_CS378X 0x24 // Reader cascading camd 3.5x TCP
466#define R_CONSTCW 0x25 // Reader for Constant CW
467#define R_CSP 0x26 // Cache CSP
468#define R_GHTTP 0x27 // Reader ghttp
469#define R_SCAM 0x28 // Reader cascading scam
470/////// peer to peer proxy readers after R_CCCAM
471#define R_GBOX 0x30 // Reader cascading gbox
472#define R_CCCAM 0x35 // Reader cascading cccam
473#define R_PANDORA 0x36 // Reader cascading pandora
474#define R_SERIAL 0x80 // Reader serial
475#define R_IS_NETWORK 0x60
476#define R_IS_CASCADING 0xE0
477
478#define is_network_reader(__X) (__X->typ & R_IS_NETWORK)
479#define is_cascading_reader(__X) (__X->typ & R_IS_CASCADING)
480#define is_smargo_reader(__X) (__X->crdr && strcmp(__X->crdr->desc, "smargo") == 0)
481
482// ECM rc codes:
483/////// all found
484#define E_FOUND 0
485#define E_CACHE1 1
486#define E_CACHE2 2
487#define E_CACHEEX 3
488/////// all notfound, some error or problem
489#define E_NOTFOUND 4 // for selection of found, use < E_NOTFOUND
490#define E_TIMEOUT 5
491#define E_SLEEPING 6
492#define E_FAKE 7
493#define E_INVALID 8
494#define E_CORRUPT 9
495#define E_NOCARD 10
496#define E_EXPDATE 11
497#define E_DISABLED 12
498#define E_STOPPED 13 // for selection of error, use <= E_STOPPED and exclude selection of found
499
500#define E_ALREADY_SENT 101
501#define E_WAITING 102
502#define E_99 99 // this code is undocumented
503#define E_UNHANDLED 100 // for selection of unhandled, use >= E_UNHANDLED
504
505#define CS_MAX_MOD 20
506#define MOD_CONN_TCP 1
507#define MOD_CONN_UDP 2
508#define MOD_CONN_NET 3
509#define MOD_CONN_SERIAL 4
510#define MOD_NO_CONN 8
511
512#define EMM_UNIQUE 1
513#define EMM_SHARED 2
514#define EMM_GLOBAL 4
515#define EMM_UNKNOWN 8
516
517// Listener Types
518#define LIS_CAMD33TCP 1
519#define LIS_CAMD35UDP 2
520#define LIS_CAMD35TCP 4
521#define LIS_NEWCAMD 8
522#define LIS_CCCAM 16
523#define LIS_GBOX 32
524#define LIS_RADEGAST 64
525#define LIS_DVBAPI 128
526#define LIS_CONSTCW 256
527#define LIS_SERIAL 1024
528#define LIS_CSPUDP 2048
529#define LIS_SCAM 4096
530
531// EMM types:
532#define UNKNOWN 0
533#define UNIQUE 1
534#define SHARED 2
535#define GLOBAL 3
536
537#define NCD_AUTO 0
538#define NCD_524 1
539#define NCD_525 2
540
541// moved from reader-common.h
542#define UNKNOWN 0
543#define CARD_NEED_INIT 1
544#define CARD_INSERTED 2
545#define CARD_FAILURE 3
546#define NO_CARD 4
547#define READER_DEVICE_ERROR 5
548
549// moved from stats
550#define DEFAULT_REOPEN_SECONDS 30
551#define DEFAULT_MIN_ECM_COUNT 5
552#define DEFAULT_MAX_ECM_COUNT 500
553#define DEFAULT_NBEST 1
554#define DEFAULT_NFB 1
555#define DEFAULT_RETRYLIMIT 0
556#define DEFAULT_LB_MODE 0
557#define DEFAULT_LB_STAT_CLEANUP 336
558#define DEFAULT_UPDATEINTERVAL 240
559#define DEFAULT_LB_AUTO_BETATUNNEL 1
560#define DEFAULT_LB_AUTO_BETATUNNEL_MODE 0
561#define DEFAULT_LB_AUTO_BETATUNNEL_PREFER_BETA 50
562
563#define DEFAULT_MAX_CACHE_TIME 15
564#define DEFAULT_MAX_HITCACHE_TIME 15
565
566#define DEFAULT_LB_AUTO_TIMEOUT 0
567#define DEFAULT_LB_AUTO_TIMEOUT_P 30
568#define DEFAULT_LB_AUTO_TIMEOUT_T 300
569
570enum {E1_GLOBAL = 0, E1_USER, E1_READER, E1_SERVER, E1_LSERVER};
571
572// LB blocking events:
573enum {E2_GLOBAL = 0, E2_GROUP, E2_CAID, E2_IDENT, E2_CLASS, E2_CHID, E2_QUEUE, E2_OFFLINE,
574 E2_SID, E2_CCCAM_NOCARD,
575 // From here only LB nonblocking events:
576 E2_CCCAM_NOK1, E2_CCCAM_NOK2, E2_CCCAM_LOOP, E2_WRONG_CHKSUM, E2_RATELIMIT
577 };
578
579#define LB_NONBLOCK_E2_FIRST E2_CCCAM_NOK1
580
581#define CTA_RES_LEN 512
582
583#define MAX_ATR_LEN 33 // max. ATR length
584#define MAX_HIST 15 // max. number of historical characters
585
586#define MAX_SIDBITS 64 // max services
587#define SIDTABBITS uint64_t // 64bit type for services, if a system does not support this type,
588// please use a define and define it as uint32_t / MAX_SIDBITS 32
589
590#define BAN_UNKNOWN 1 // Failban mask for anonymous/ unknown contact
591#define BAN_DISABLED 2 // Failban mask for Disabled user
592#define BAN_SLEEPING 4 // Failban mask for sleeping user
593#define BAN_DUPLICATE 8 // Failban mask for duplicate user
594
595#define MAX_HTTP_DYNDNS 3 // maximum allowed Dyndns addresses for webif access
596
597#define CHECK_WAKEUP 1
598#define CHECK_ANTICASCADER 2
599#define CHECK_ECMCACHE 3
600
601#define AVAIL_CHECK_CONNECTED 0
602#define AVAIL_CHECK_LOADBALANCE 1
603
604#define ECM_FMT_LEN 109 // 64
605#define CXM_FMT_LEN 209 // 160
606
607#define LB_MAX_STAT_TIME 10
608
609#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
610#define OSCAM_SIGNAL_WAKEUP SIGCONT
611#else
612#define OSCAM_SIGNAL_WAKEUP SIGRTMAX-2
613#endif
614
615#define READER_ACTIVE 0x01
616#define READER_FALLBACK 0x02
617#define READER_LOCAL 0x04
618#define READER_CACHEEX 0x08
619
620#define REQUEST_SENT 0x10
621#define REQUEST_ANSWERED 0x20
622
623#define CW_MODE_ONE_CW 0
624#define CW_MODE_MULTIPLE_CW 1
625#define CW_TYPE_VIDEO 0
626#define CW_TYPE_AUDIO 1
627#define CW_TYPE_DATA 2
628#define CW_ALGO_CSA 0
629#define CW_ALGO_DES 1
630#define CW_ALGO_AES128 2
631#define CW_ALGO_MODE_ECB 0
632#define CW_ALGO_MODE_CBC 1
633
634#define SIZE_SHORTDAY 8
635#define MAXALLOWEDTF 1001 // 10 allowed time frame slots for everyday + all [(3 + 1 + 10*(12) + 1)*8]
636extern const char *shortDay[SIZE_SHORTDAY];
637extern const char *weekdstr;
638
639/* ===========================
640 * Default Values
641 * =========================== */
642#define DEFAULT_INACTIVITYTIMEOUT 0
643#define DEFAULT_TCP_RECONNECT_TIMEOUT 30
644#define DEFAULT_NCD_KEEPALIVE 0
645
646#define DEFAULT_CC_MAXHOPS 10
647#define DEFAULT_CC_RESHARE -1 // Use global cfg
648#define DEFAULT_CC_IGNRSHR -1 // Use global cfg
649#define DEFAULT_CC_STEALTH -1 // Use global cfg
650#define DEFAULT_CC_KEEPALIVE 0
651#define DEFAULT_CC_RECONNECT 12000
652#define DEFAULT_CC_RECV_TIMEOUT 2000
653
654#define DEFAULT_AC_USERS -1 // Use global cfg
655#define DEFAULT_AC_PENALTY -1 // Use global cfg
656
657// Return MPEG section length
658#define SCT_LEN(sct) (3+((sct[1]&0x0f)<<8)+sct[2])
659// Used by readers
660#define MAX_LEN 256
661
662#define NO_CAID_VALUE 0xfffe
663#define NO_PROVID_VALUE 0xfffffe
664#define NO_SRVID_VALUE 0xfffe
665
666// If NULL return empty string
667#define ESTR(x) ((x) ? (x) : "")
668
669#ifndef MAX
670#define MAX(a,b) ((a) > (b) ? (a) : (b))
671#endif
672
673#ifndef MIN
674#define MIN(a,b) ((a) < (b) ? (a) : (b))
675#endif
676
677/*
678 See: http://stackoverflow.com/questions/10269685/kernels-container-of-any-way-to-make-it-iso-conforming
679 http://www.kroah.com/log/linux/container_of.html
680*/
681#define container_of(ptr, type, member) \
682 ((type *) ((char *) (ptr) - offsetof(type, member) + \
683 (&((type *) 0)->member == (ptr)) * 0))
684
685/* ===========================
686 * global structures
687 * =========================== */
688struct timeb
689{
690 time_t time;
691 int64_t millitm;
692};
693
694typedef struct cs_mutexlock
695{
696 int32_t timeout;
697 pthread_mutex_t lock;
698 pthread_cond_t writecond, readcond;
699 const char *name;
700 int8_t flag;
701 int16_t writelock, readlock;
702} CS_MUTEX_LOCK;
703
704#include "oscam-llist.h"
705
706typedef struct s_caidvaluetab_data
707{
708 uint16_t caid;
709 uint16_t value;
710} CAIDVALUETAB_DATA;
711
712typedef struct s_caidvaluetab
713{
714 int32_t cvnum;
715 CAIDVALUETAB_DATA *cvdata;
716} CAIDVALUETAB;
717
718typedef struct s_classtab
719{
720 uint8_t an;
721 uint8_t bn;
722 uint8_t *aclass;
723 uint8_t *bclass;
724} CLASSTAB;
725
726typedef struct s_caidtab_data
727{
728 uint16_t caid;
729 uint16_t mask;
730 uint16_t cmap;
731} CAIDTAB_DATA;
732
733typedef struct s_caidtab
734{
735 int32_t ctnum;
736 CAIDTAB_DATA *ctdata;
737} CAIDTAB;
738
739typedef struct s_tuntab_data
740{
741 uint16_t bt_caidfrom;
742 uint16_t bt_caidto;
743 uint16_t bt_srvid;
744} TUNTAB_DATA;
745
746typedef struct s_tuntab
747{
748 int32_t ttnum;
749 TUNTAB_DATA *ttdata;
750} TUNTAB;
751
752typedef struct s_sidtab
753{
754 char label[64];
755#ifdef CS_CACHEEX_AIO
756 uint8_t disablecrccws_only_for_exception;
757 uint8_t no_wait_time;
758 uint8_t lg_only_exception;
759#endif
760 uint16_t num_caid;
761 uint16_t num_provid;
762 uint16_t num_srvid;
763 uint16_t *caid;
764 uint32_t *provid;
765 uint16_t *srvid;
766 struct s_sidtab *next;
767} SIDTAB;
768
769typedef struct s_filter
770{
771 uint16_t caid;
772 uint8_t nprids;
773 uint32_t prids[CS_MAXPROV];
774} FILTER;
775
776typedef struct s_ftab
777{
778 int32_t nfilts;
779 FILTER *filts;
780} FTAB;
781
782typedef struct s_ncd_ftab
783{
784 int32_t nfilts;
785 FILTER filts[16];
786} NCD_FTAB;
787
788struct ncd_port
789{
790 bool ncd_key_is_set;
791 uint8_t ncd_key[14];
792 NCD_FTAB ncd_ftab;
793};
794
795typedef struct s_port
796{
797 int32_t fd;
798 int32_t s_port;
799 struct ncd_port *ncd; // newcamd specific settings
800} PORT;
801
802typedef struct s_ptab
803{
804 int32_t nports;
805 PORT ports[CS_MAXPORTS];
806} PTAB;
807
808typedef struct aes_entry
809{
810 uint16_t keyid;
811 uint16_t caid;
812 uint32_t ident;
813 uint8_t plainkey[16];
814 AES_KEY key;
815 struct aes_entry *next;
816} AES_ENTRY;
817
818struct aes_keys
819{
820 AES_KEY aeskey_encrypt; // encryption key needed by monitor and used by camd33, camd35
821 AES_KEY aeskey_decrypt; // decryption key needed by monitor and used by camd33, camd35
822};
823
824struct s_ecm
825{
826 uint8_t ecmd5[CS_ECMSTORESIZE];
827 uint8_t cw[16];
828 uint16_t caid;
829 uint64_t grp;
830 struct s_reader *reader;
831 int32_t rc;
832 time_t time;
833};
834
835struct s_emmstat
836{
837 uint8_t emmd5[CS_EMMSTORESIZE];
838 uint8_t type;
839 int32_t count;
840 struct timeb firstwritten;
841 struct timeb lastwritten;
842};
843
844struct s_emmcache
845{
846 uint8_t emmd5[CS_EMMSTORESIZE];
847 uint8_t type;
848 uint16_t len;
849 uint8_t emm[MAX_EMM_SIZE];
850 struct timeb firstseen;
851 struct timeb lastseen;
852};
853
854struct s_csystem_emm_filter
855{
856 uint8_t type;
857 uint8_t enabled;
858 uint8_t filter[16];
859 uint8_t mask[16];
860};
861
862typedef struct v_ban // Failban listmember
863{
864 int32_t v_count;
865 IN_ADDR_T v_ip;
866 int32_t v_port;
867 struct timeb v_time;
868 bool acosc_entry;
869 int32_t acosc_penalty_dur;
870 char *info;
871} V_BAN;
872
873typedef struct s_cacheex_stat_entry // Cacheex stats listmember
874{
875 int32_t cache_count;
876 time_t cache_last;
877 uint16_t cache_caid;
878 uint16_t cache_srvid;
879 uint32_t cache_prid;
880 int8_t cache_direction; // 0 = push / 1 = got
881#ifdef CS_CACHEEX_AIO
882 int32_t cache_count_lg;
883#endif
884} S_CACHEEX_STAT_ENTRY;
885
886typedef struct s_entitlement // contains entitlement Info
887{
888 uint64_t id; // the element ID
889 uint32_t type; // enumerator for tier,chid whatever
890 // 0="", 1="Package", 2="PPV-Event", 3="chid", 4="tier", 5 = "class", 6 = "PBM". 7 = "seca-admin"
891 uint16_t caid; // the caid of element
892 uint32_t provid; // the provid of element
893 uint32_t class; // the class needed for some systems
894 time_t start; // startdate
895 time_t end; // enddate
896#ifdef WITH_EMU
897 bool isKey;
898 bool isData;
899 char name[8];
900 uint8_t *key;
901 uint32_t keyLength;
902#endif
903} S_ENTITLEMENT;
904
905struct s_client;
906struct ecm_request_t;
907struct emm_packet_t;
908struct cmd_packet_t;
909struct s_ecm_answer;
910struct demux_s;
911
912#define DEFAULT_MODULE_BUFSIZE 1024
913
914struct s_module
915{
916 const char *desc;
917 int8_t type;
918 int8_t large_ecm_support;
919 int16_t listenertype;
920 //int32_t s_port;
921 IN_ADDR_T s_ip;
922 uint16_t bufsize;
923 void *(*s_handler)(struct s_client *, uint8_t *, int32_t);
924 void (*s_init)(struct s_client *);
925 int32_t (*recv)(struct s_client *, uint8_t *, int32_t);
926 void (*send_dcw)(struct s_client *, struct ecm_request_t *);
927 void (*cleanup)(struct s_client *);
928 int32_t (*c_recv_chk)(struct s_client *, uint8_t *, int32_t *, uint8_t *, int32_t);
929 int32_t (*c_init)(struct s_client *);
930 int32_t (*c_send_ecm)(struct s_client *, struct ecm_request_t *);
931 int32_t (*c_send_emm)(struct emm_packet_t *);
932 int32_t (*c_available)(struct s_reader *, int32_t, struct ecm_request_t *); // Schlocke: available check for load-balancing,
933 // params:
934 // rdr (reader to check)
935 // int32_t checktype (0=return connected, 1=return loadbalance-avail) return int
936 void (*c_idle)(void); // Schlocke: called when reader is idle
937 void (*s_idle)(struct s_client *);
938 void (*s_peer_idle)(struct s_client *);
939 void (*c_card_info)(void); // Schlocke: request card infos
940
941 int32_t (*c_capmt)(struct s_client *, struct demux_s *);
942
943#ifdef CS_CACHEEX
944 int32_t (*c_cache_push)(struct s_client *, struct ecm_request_t *); // Cache push
945 int32_t (*c_cache_push_chk)(struct s_client *, struct ecm_request_t *); // Cache push Node Check, 0=no push
946#endif
947 int32_t c_port;
948 PTAB ptab;
949 int32_t num;
950};
951
952struct s_ATR;
953
954struct s_cardreader_settings
955{
956 uint32_t ETU;
957 uint32_t EGT;
958 uint8_t P;
959 uint32_t I;
960 uint32_t F;
961 uint32_t Fi;
962 uint8_t Di;
963 uint8_t Ni;
964 uint32_t WWT;
965 uint32_t BGT;
966 uint8_t D;
967};
968
969struct s_cardreader
970{
971 const char *desc;
972 int32_t (*reader_init)(struct s_reader *);
973 int32_t (*get_status)(struct s_reader *, int *);
974 int32_t (*activate)(struct s_reader *, struct s_ATR *);
975 int32_t (*transmit)(struct s_reader *, uint8_t *sent, uint32_t size, uint32_t expectedlen, uint32_t delay, uint32_t timeout);
976 int32_t (*receive)(struct s_reader *, uint8_t *data, uint32_t size, uint32_t delay, uint32_t timeout);
977 int32_t (*lock_init)(struct s_reader *);
978 void (*lock)(struct s_reader *);
979 void (*unlock)(struct s_reader *);
980 int32_t (*close)(struct s_reader *);
981 int32_t (*set_parity)(struct s_reader *, uint8_t parity);
982 int32_t (*write_settings)(struct s_reader *, struct s_cardreader_settings *s);
983 int32_t (*set_protocol)(struct s_reader *, uint8_t *params, uint32_t *length, uint32_t len_request);
984 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
985 int32_t (*card_write)(struct s_reader *pcsc_reader, const uint8_t *buf, uint8_t *cta_res, uint16_t *cta_lr, int32_t l);
986 void (*display_msg)(struct s_reader *, char *msg);
987
988 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 *));
989
990 bool (*set_DTS_RTS)(struct s_reader *, int32_t *dtr, int32_t *rts);
991
992 int32_t typ; // fixme: workaround, remove when all old code is converted
993
994 int8_t max_clock_speed; // 1 for reader->typ > R_MOUSE
995 int8_t need_inverse; // 0 = reader does inversing; 1 = inversing done by oscam
996 //io_serial config
997 int8_t flush;
998 int8_t read_written; // 1 = written bytes has to read from device
999 bool skip_extra_atr_parsing;
1000 bool skip_t1_command_retries;
1001 bool skip_setting_ifsc;
1002};
1003
1004struct s_cardsystem
1005{
1006 const char *desc;
1007 const uint16_t *caids;
1008 int32_t (*card_init)(struct s_reader *reader, struct s_ATR *);
1009 void (*card_done)(struct s_reader *reader);
1010 int32_t (*card_info)(struct s_reader *);
1011 void (*poll_status)(struct s_reader *);
1012 int32_t (*do_ecm)(struct s_reader *, const struct ecm_request_t *, struct s_ecm_answer *);
1013 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
1014 int32_t (*do_emm)(struct s_reader *, struct emm_packet_t *);
1015 int32_t (*do_rawcmd)(struct s_reader *, struct cmd_packet_t *);
1016 void (*post_process)(struct s_reader *);
1017 int32_t (*get_emm_type)(struct emm_packet_t *, struct s_reader *);
1018 int32_t (*get_emm_filter)(struct s_reader *, struct s_csystem_emm_filter **, uint32_t *);
1019 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);
1020 int32_t (*get_tunemm_filter)(struct s_reader *, struct s_csystem_emm_filter **, uint32_t *);
1021};
1022
1023typedef struct cw_extendted_t
1024{
1025#ifdef WITH_EXTENDED_CW
1026 uint8_t mode;
1027 uint8_t audio[4][16]; // 4 x odd/even pairs of 8 byte CWs
1028 uint8_t data[16]; // odd/even pair of 8 byte CW or 16 byte IV
1029 uint8_t session_word[32]; // odd/even pair of 16 byte CW
1030 uint8_t algo; // CSA, DES or AES128
1031 uint8_t algo_mode; // ECB or CBC
1032#else
1033 uint8_t disabled;
1034#endif
1035} EXTENDED_CW;
1036
1037typedef struct ecm_request_t
1038{
1039 uint8_t ecm[MAX_ECM_SIZE];
1040 uint8_t cw[16];
1041 EXTENDED_CW cw_ex;
1042 uint8_t ecmd5[CS_ECMSTORESIZE];
1043 int16_t ecmlen;
1044 uint16_t caid;
1045 uint16_t ocaid; // original caid, used for betatunneling
1046 uint16_t srvid;
1047 uint16_t onid;
1048 uint16_t tsid;
1049 uint16_t pmtpid;
1050 uint32_t ens; // enigma namespace
1051 uint32_t vpid; // videopid
1052 uint16_t chid;
1053 uint16_t pid;
1054 uint16_t idx;
1055 uint32_t prid;
1056 struct s_reader *selected_reader;
1057 struct s_ecm_answer *matching_rdr; // list of matching readers
1058 const struct s_reader *fallback; // fallback is the first fallback reader in the list matching_rdr
1059 struct s_client *client; // contains pointer to 'c' client while running in 'r' client
1060 uint64_t grp;
1061 int32_t msgid; // client pending table index
1062 uint8_t stage; // processing stage in server module
1063 int8_t rc;
1064 uint8_t rcEx;
1065 struct timeb tps; // incoming time stamp
1066 int8_t btun; // mark er as betatunneled
1067 uint16_t reader_avail; // count of available readers for ecm
1068 uint16_t readers; // count of available used readers for ecm
1069 uint16_t reader_requested; // count of real requested readers
1070 uint16_t localreader_count; // count of selected local readers
1071 uint16_t cacheex_reader_count; // count of selected cacheex mode-1 readers
1072 uint16_t fallback_reader_count; // count of selected fb readers
1073 uint16_t reader_count; // count of selected not fb readers
1074 int8_t preferlocalcards;
1075 int8_t checked; // for doublecheck
1076 uint8_t cw_checked[16]; // for doublecheck
1077 int8_t readers_timeout_check; // set to 1 after ctimeout occurs and readers not answered are checked
1078 struct s_reader *origin_reader;
1079
1080#if defined MODULE_CCCAM
1081 void *origin_card; // CCcam preferred card!
1082#endif
1083
1084#if defined MODULE_GBOX
1085 uint32_t gbox_crc; // rcrc for gbox, used to identify ECM task in peer responses
1086 uint16_t gbox_cw_src_peer;
1087 uint16_t gbox_ecm_src_peer;
1088 uint8_t gbox_ecm_dist;
1089 uint8_t gbox_ecm_status;
1090 LLIST *gbox_cards_pending; // type gbox_card_pending
1091#endif
1092
1093 void *src_data;
1094 uint32_t csp_hash; // csp has its own hash
1095
1096 struct s_client *cacheex_src; // Cacheex origin
1097#ifdef CS_CACHEEX
1098 int8_t cacheex_pushed; // to avoid duplicate pushs
1099 uint8_t csp_answered; // =1 if er get answer by csp
1100 LLIST *csp_lastnodes; // last 10 Cacheex nodes atm cc-proto-only
1101 uint32_t cacheex_wait_time; // cacheex wait time in ms
1102 uint8_t cacheex_wait_time_expired; // =1 if cacheex wait_time expires
1103 uint16_t cacheex_mode1_delay; // cacheex mode 1 delay
1104 uint8_t cacheex_hitcache; // =1 if wait_time due hitcache
1105 void *cw_cache; // pointer to cw stored in cache
1106#endif
1107#ifdef CS_CACHEEX_AIO
1108 int32_t ecm_time; // ecm-time in ms
1109 uint8_t localgenerated; // flag for local generated CW
1110#endif
1111 uint32_t cw_count;
1112 uint8_t from_csp; // =1 if er from csp cache
1113 uint8_t from_cacheex; // =1 if er from cacheex client pushing cache
1114 uint8_t from_cacheex1_client; // =1 if er from cacheex-1 client
1115 char msglog[MSGLOGSIZE];
1116 uint8_t cwc_cycletime;
1117 uint8_t cwc_next_cw_cycle;
1118#ifdef CW_CYCLE_CHECK
1119 char cwc_msg_log[MSGLOGSIZE];
1120#endif
1121#ifdef WITH_STAPI5
1122 char dev_name[20];
1123#endif
1124 struct ecm_request_t *parent;
1125 struct ecm_request_t *next;
1126#ifdef HAVE_DVBAPI
1127 uint8_t adapter_index;
1128#endif
1129} ECM_REQUEST;
1130
1131
1132struct s_ecm_answer
1133{
1134 uint8_t status;
1135 struct s_reader *reader;
1136 ECM_REQUEST *er;
1137 int8_t rc;
1138 uint8_t rcEx;
1139 uint8_t cw[16];
1140 EXTENDED_CW cw_ex;
1141 char msglog[MSGLOGSIZE];
1142 struct timeb time_request_sent; // using for evaluate ecm_time
1143 int32_t ecm_time;
1144 uint16_t tier; // only filled by local videoguard reader atm
1145#ifdef WITH_LB
1146 int32_t value;
1147 int32_t time;
1148#endif
1149 struct s_ecm_answer *next;
1150 CS_MUTEX_LOCK ecmanswer_lock;
1151 struct s_ecm_answer *pending;
1152 struct s_ecm_answer *pending_next;
1153 bool is_pending;
1154};
1155
1156struct s_acasc_shm
1157{
1158 uint16_t ac_count : 15;
1159 uint16_t ac_deny : 1;
1160};
1161
1162struct s_acasc
1163{
1164 uint16_t stat[10];
1165 uint8_t idx; // current active index in stat[]
1166};
1167
1168struct s_cwresponse
1169{
1170 int32_t duration;
1171 time_t timestamp;
1172 int32_t rc;
1173};
1174
1175struct s_cascadeuser
1176{
1177 uint16_t caid;
1178 uint32_t prid;
1179 uint16_t srvid;
1180 time_t time;
1181 int8_t cwrate;
1182};
1183
1184typedef struct sidtabs
1185{
1186 SIDTABBITS ok; // positive services
1187 SIDTABBITS no; // negative services
1188} SIDTABS;
1189
1190struct s_zap_list
1191{
1192 uint16_t caid;
1193 uint32_t provid;
1194 uint16_t chid;
1195 uint16_t sid;
1196 int8_t request_stage;
1197 time_t lasttime;
1198};
1199
1200// EMM reassemply
1201struct emm_rass
1202{
1203 int16_t emmlen;
1204 int32_t provid;
1205 uint8_t emm[MAX_EMM_SIZE];
1206};
1207
1208struct s_client
1209{
1210 uint32_t tid;
1211 int8_t init_done;
1212 pthread_mutex_t thread_lock;
1213 int8_t thread_active;
1214 int8_t kill;
1215 int8_t kill_started;
1216 LLIST *joblist;
1217 IN_ADDR_T ip;
1218 in_port_t port;
1219 time_t login; // connection
1220 time_t logout; // disconnection
1221 time_t last;
1222 time_t lastswitch;
1223 time_t lastemm;
1224 time_t lastecm;
1225 time_t expirationdate;
1226 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
1227 uint8_t allowedtimeframe_set; // flag for internal use to mention if allowed time frame is used
1228 int8_t c35_suppresscmd08;
1229 uint8_t c35_sleepsend;
1230 int8_t ncd_keepalive;
1231 int8_t disabled;
1232 uint64_t grp;
1233 int8_t crypted;
1234 int8_t dup;
1235 LLIST *aureader_list;
1236 int8_t autoau;
1237 LLIST *ra_buf; // EMM reassembly buffer for viaccess
1238 struct emm_rass *cw_rass; // EMM reassembly buffer for cryptoworks
1239 int8_t monlvl;
1240 CAIDTAB ctab;
1241 TUNTAB ttab;
1242 SIDTABS sidtabs;
1243 SIDTABS lb_sidtabs;
1244 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
1245 uint8_t module_idx;
1246 uint16_t last_srvid;
1247 uint32_t last_provid;
1248 uint16_t last_caid;
1249 struct s_provid *last_providptr;
1250 struct s_srvid *last_srvidptr;
1251 uint32_t last_srvidptr_search_provid;
1252 int32_t tosleep;
1253 struct s_auth *account;
1254 int32_t udp_fd;
1255 struct SOCKADDR udp_sa;
1256 socklen_t udp_sa_len;
1257 int8_t tcp_nodelay;
1258 int8_t log;
1259 int32_t logcounter;
1260 int32_t cwfound; // count found ECMs per client
1261 int32_t cwcache; // count ECMs from cache1/2 per client
1262 int32_t cwnot; // count not found ECMs per client
1263 int32_t cwtun; // count betatunneled ECMs per client
1264 int32_t cwignored; // count ignored ECMs per client
1265 int32_t cwtout; // count timeouted ECMs per client
1266 int32_t cwlastresptime; // last Responsetime (ms)
1267#ifdef CW_CYCLE_CHECK
1268 int32_t cwcycledchecked; // count checked cwcycles per client
1269 int32_t cwcycledok; // count pos checked cwcycles per client
1270 int32_t cwcyclednok; // count neg checked cwcycles per client
1271 int32_t cwcycledign; // count ign cwcycles per client
1272#endif
1273 int32_t emmok; // count EMM ok
1274 int32_t emmnok; // count EMM nok
1275 int8_t pending; // number of ECMs pending
1276#ifdef CS_CACHEEX
1277 int32_t cwcacheexpush; // count pushed ecms/cws
1278 int32_t cwcacheexgot; // count got ecms/cws
1279 int32_t cwcacheexhit; // count hit ecms/cws
1280 LLIST *ll_cacheex_stats; // list for Cacheex statistics
1281 int8_t cacheex_maxhop;
1282 int32_t cwcacheexerr; // cw=00 or chksum wrong
1283 int32_t cwcacheexerrcw; // same Hex, different CW
1284 int16_t cwcacheexping; // peer ping in ms, only used by csp
1285 int32_t cwc_info; // count of in/out comming cacheex ecms with CWCinfo
1286#ifdef CS_CACHEEX_AIO
1287 int32_t cwcacheexgotlg; // count got localgenerated-flagged CWs
1288 int32_t cwcacheexpushlg; // count pushed localgenerated-flagged CWs
1289#endif
1290 uint8_t cacheex_needfilter; // flag for cachex mode 3 used with camd35
1291#ifdef CS_CACHEEX_AIO
1292 uint8_t cacheex_aio_checked; // flag for cacheex aio detection done
1293#endif
1294#endif
1295#ifdef CS_ANTICASC
1296 struct s_zap_list client_zap_list[15]; // 15 last zappings from client used for ACoSC
1297#endif
1298#ifdef WEBIF
1299 struct s_cwresponse cwlastresptimes[CS_ECM_RINGBUFFER_MAX]; // ringbuffer for last 20 times
1300 int32_t cwlastresptimes_last; // ringbuffer pointer
1301 int8_t wihidden; // hidden in webinterface status
1302 char lastreader[64]; // last cw got from this reader
1303#endif
1304
1305 uint8_t ucrc[4]; // needed by monitor and used by camd35
1306 uint32_t pcrc; // password crc
1307 struct aes_keys *aes_keys; // used by camd33 and camd35
1308 uint16_t ncd_msgid;
1309 uint16_t ncd_client_id;
1310 uint8_t ncd_skey[16]; // Also used for camd35 Cacheex to store remote node id
1311
1312#ifdef MODULE_CCCAM
1313 void *cc;
1314#endif
1315
1316#ifdef CS_CACHEEX_AIO
1317#if defined(MODULE_CAMD35) || defined(MODULE_CAMD35_TCP)
1318 uint8_t c35_extmode;
1319#endif
1320#endif
1321
1322#ifdef MODULE_GBOX
1323 void *gbox;
1324 uint16_t gbox_peer_id;
1325#endif
1326
1327#ifdef MODULE_GHTTP
1328 void *ghttp;
1329#endif
1330
1331 int32_t port_idx; // index in server ptab
1332 int32_t ncd_server; // newcamd server
1333
1334#ifdef CS_ANTICASC
1335 int32_t ac_fakedelay; // When this is -1, the global ac_fakedelay is used
1336 uint16_t ac_limit;
1337 int8_t ac_penalty;
1338 struct s_acasc_shm acasc;
1339#endif
1340
1341 FTAB fchid;
1342 FTAB ftab; // user [caid] and ident filter
1343 CLASSTAB cltab;
1344
1345 int32_t pfd; // Primary FD, must be closed on exit
1346 struct s_reader *reader; // points to s_reader when cl->typ='r'
1347
1348 ECM_REQUEST *ecmtask;
1349
1350 pthread_t thread;
1351
1352#ifdef MODULE_SERIAL
1353 struct s_serial_client *serialdata;
1354#endif
1355 // reader common
1356 int32_t last_idx;
1357 uint16_t idx;
1358
1359 int8_t ncd_proto;
1360 uint8_t ncd_header[12];
1361
1362 // camd35
1363 uint8_t upwd[64];
1364 int8_t is_udp;
1365 int8_t stopped;
1366 uint16_t lastcaid;
1367 uint16_t lastsrvid;
1368 int32_t lastpid;
1369 int8_t disable_counter;
1370 uint8_t lastserial[8];
1371
1372 // Failban value set bitwise - compared with BAN_
1373 int32_t failban;
1374
1375 LLIST *cascadeusers; // s_cascadeuser
1376
1377 int32_t n_request[2]; // count for number of request per minute by client
1378
1379 void *work_mbuf; // Points to local data allocated in work_thread when the thread is running
1380 void *work_job_data; // Points to current job_data when work_thread is running
1381
1382#ifdef MODULE_PANDORA
1383 int32_t pand_autodelay;
1384 uint8_t pand_send_ecm;
1385 uint8_t pand_ignore_ecm;
1386 uint8_t pand_md5_key[16];
1387#endif
1388
1389#ifdef MODULE_SCAM
1390 void *scam;
1391#endif
1392 void *module_data; // private module data
1393
1394 struct s_client *next; // make client a linked list
1395 struct s_client *nexthashed;
1396
1397 int8_t start_hidecards;
1398};
1399
1400typedef struct s_ecm_whitelist_data
1401{
1402 uint16_t len;
1403 uint16_t caid;
1404 uint32_t ident;
1405} ECM_WHITELIST_DATA;
1406
1407typedef struct s_ecm_whitelist
1408{
1409 int32_t ewnum;
1410 ECM_WHITELIST_DATA *ewdata;
1411} ECM_WHITELIST;
1412
1413typedef struct s_ecm_hdr_whitelist_data
1414{
1415 uint16_t len;
1416 uint16_t caid;
1417 uint32_t provid;
1418 uint8_t header[20];
1419} ECM_HDR_WHITELIST_DATA;
1420
1421typedef struct s_ecm_hdr_whitelist
1422{
1423 int32_t ehnum;
1424 ECM_HDR_WHITELIST_DATA *ehdata;
1425} ECM_HDR_WHITELIST;
1426
1427// ratelimit
1428struct ecmrl
1429{
1430 struct timeb last;
1431 uint8_t kindecm;
1432 bool once;
1433 uint8_t ecmd5[CS_ECMSTORESIZE];
1434 uint16_t caid;
1435 uint32_t provid;
1436 uint16_t srvid;
1437 uint16_t chid;
1438 int32_t ratelimitecm;
1439 int32_t ratelimittime;
1440 int32_t srvidholdtime;
1441};
1442#define MAXECMRATELIMIT 20
1443
1444#ifdef MODULE_SERIAL
1445struct ecmtw
1446{
1447 uint16_t caid;
1448 uint32_t provid;
1449 uint16_t srvid;
1450 uint16_t deg;
1451 uint16_t freq;
1452};
1453#endif
1454
1455typedef struct ce_csp_tab_data
1456{
1457 int32_t caid;
1458 int32_t cmask;
1459 int32_t prid;
1460 int32_t srvid;
1461 int16_t awtime;
1462 int16_t dwtime;
1463} CECSPVALUETAB_DATA;
1464
1465typedef struct ce_csp_tab
1466{
1467 int32_t cevnum;
1468 CECSPVALUETAB_DATA *cevdata;
1469} CECSPVALUETAB;
1470
1471typedef struct cacheex_check_cw_tab_data
1472{
1473 int32_t caid;
1474 int32_t cmask;
1475 int32_t prid;
1476 int32_t srvid;
1477 int8_t mode;
1478 uint32_t counter;
1479} CWCHECKTAB_DATA;
1480
1481typedef struct cacheex_check_cw_tab
1482{
1483 int32_t cwchecknum;
1484 CWCHECKTAB_DATA *cwcheckdata;
1485
1486} CWCHECKTAB;
1487
1488typedef struct cacheex_check_cw
1489{
1490 int8_t mode;
1491 uint32_t counter;
1492} CWCHECK;
1493
1494typedef struct ce_csp_t
1495{
1496 int8_t mode;
1497 int8_t maxhop;
1498#ifdef CS_CACHEEX_AIO
1499 int8_t maxhop_lg;
1500#endif
1501 CECSPVALUETAB filter_caidtab;
1502 uint8_t allow_request;
1503 uint8_t allow_reforward;
1504 uint8_t drop_csp;
1505 uint8_t allow_filter;
1506#ifdef CS_CACHEEX_AIO
1507 uint8_t allow_maxhop;
1508#endif
1509 uint8_t block_fakecws;
1510#ifdef CS_CACHEEX_AIO
1511 uint8_t cw_check_for_push;
1512 uint8_t localgenerated_only;
1513 CAIDTAB localgenerated_only_caidtab;
1514 FTAB lg_only_tab;
1515 uint8_t localgenerated_only_in;
1516 CAIDTAB localgenerated_only_in_caidtab;
1517 FTAB lg_only_in_tab;
1518 uint8_t lg_only_in_aio_only;
1519 uint8_t lg_only_remote_settings;
1520 int32_t feature_bitfield;
1521 CAIDVALUETAB cacheex_nopushafter_tab;
1522 char aio_version[12];
1523#endif
1524} CECSP;
1525
1526struct s_emmlen_range
1527{
1528 int16_t min;
1529 int16_t max;
1530};
1531
1532typedef struct emm_packet_t
1533{
1534 uint8_t emm[MAX_EMM_SIZE];
1535 int16_t emmlen;
1536 uint8_t caid[2];
1537 uint8_t provid[4];
1538 uint8_t hexserial[8]; // contains hexserial or SA of EMM
1539 uint8_t type;
1540 uint8_t skip_filter_check;
1541 struct s_client *client;
1542} EMM_PACKET;
1543
1544typedef struct cmd_packet_t
1545{
1546 uint8_t cmd[MAX_CMD_SIZE];
1547 int16_t cmdlen;
1548 struct s_client *client;
1549} CMD_PACKET;
1550
1551struct s_reader // contains device info, reader info and card info
1552{
1553 uint8_t keepalive;
1554 uint8_t changes_since_shareupdate;
1555 int32_t resetcycle; // ECM until reset
1556 int32_t resetcounter; // actual count
1557 uint32_t auprovid; // AU only for this provid
1558 int8_t audisabled; // exclude reader from auto AU
1559 int8_t needsemmfirst; // 0: reader descrambles without emm first, 1: reader needs emms before it can descramble
1560 struct timeb emm_last; // time of last successfully written emm
1561 int8_t smargopatch;
1562 int8_t autospeed; // 1 clockspeed set according to atr f max
1563 struct s_client *client; // pointer to 'r'client this reader is running in
1564 LLIST *ll_entitlements; // entitlements
1565 int8_t enable;
1566 int8_t active;
1567 int8_t dropbadcws; // Schlocke: 1=drops cw if checksum is wrong. 0=fix checksum (default)
1568 int8_t disablecrccws; // 1=disable cw checksum test. 0=enable checksum check
1569 uint64_t grp;
1570 int8_t fallback;
1571 FTAB fallback_percaid;
1572 FTAB localcards;
1573 FTAB disablecrccws_only_for; // ignore checksum for selected caid provid
1574#ifdef READER_CRYPTOWORKS
1575 int8_t needsglobalfirst; // 0:Write one Global EMM for SHARED EMM disabled 1:Write one Global EMM for SHARED EMM enabled
1576#endif
1577#if defined(READER_NAGRA_MERLIN) || defined(READER_NAGRA)
1578 uint8_t nuid[4];
1579 uint8_t nuid_length;
1580 uint8_t cwekey[16];
1581 uint8_t cwekey_length;
1582#endif
1583#ifdef READER_NAGRA_MERLIN
1584 uint8_t irdid[4];
1585 uint8_t irdid_length;
1586 uint8_t public_exponent[3];
1587 uint8_t public_exponent_length;
1588 uint8_t mod1[112];
1589 uint8_t mod1_length;
1590 uint8_t data50[80];
1591 uint8_t data50_length;
1592 uint8_t mod50[80];
1593 uint8_t mod50_length;
1594 uint8_t key60[96];
1595 uint8_t key60_length;
1596 uint8_t exp60[96];
1597 uint8_t exp60_length;
1598 uint8_t kdt05_00[216];
1599 uint8_t kdt05_10[208];
1600 uint8_t cardid[8];
1601 uint8_t edata[255];
1602 uint8_t dt5num;
1603 uint8_t out[255];
1604 uint8_t ideakey1[16];
1605 uint8_t block3[8];
1606 uint8_t v[8];
1607 uint8_t iout[8];
1608 uint8_t data2[4];
1609 uint8_t data[0x80];
1610 uint8_t step1[0x60];
1611 uint8_t step2[0x68];
1612 uint8_t step3[0x6c];
1613 uint8_t encrypted[0x68];
1614 uint8_t result[104];
1615 uint8_t stillencrypted[0x50];
1616 uint8_t resultrsa[0x50];
1617 uint32_t cak7_restart;
1618 uint32_t cak7_seq;
1619 uint8_t cak7_camstate;
1620 uint8_t cak7_aes_key[32];
1621 uint8_t cak7_aes_iv[16];
1622 struct timeb last_refresh;
1623#endif
1624#ifdef CS_CACHEEX
1625 CECSP cacheex; // CacheEx Settings
1626#endif
1627 int32_t typ;
1628 char label[64];
1629#ifdef WEBIF
1630 char *description;
1631#endif
1632 char device[128];
1633 uint16_t slot; // in case of multiple slots like sc8in1; first slot = 1
1634 int32_t handle; // device handle
1635 int64_t handle_nr; // device handle_nr for mutiple readers same driver
1636 int32_t fdmc; // device handle for multicam
1637 int32_t detect;
1638 int32_t mhz; // actual clock rate of reader in 10khz steps
1639 int32_t cardmhz; // standard clock speed your card should have in 10khz steps; normally 357 but for Irdeto cards 600
1640 int32_t divider; // PLL divider for internal readers
1641 int32_t r_port;
1642 char r_usr[64];
1643 char r_pwd[64];
1644 int32_t l_port;
1645 CAIDTAB ctab;
1646 uint32_t boxid;
1647 int8_t nagra_read; // read nagra ncmed records: 0 Disabled (default), 1 read all records, 2 read valid records only
1648 int8_t detect_seca_nagra_tunneled_card;
1649 int8_t force_irdeto;
1650 uint8_t boxkey[16]; // n3 boxkey 8 bytes, seca sessionkey 16 bytes, viaccess camid 4 bytes
1651 uint8_t boxkey_length;
1652 uint8_t rsa_mod[120]; // rsa modulus for nagra cards.
1653 uint8_t rsa_mod_length;
1654 uint8_t des_key[128]; // 3des key for Viaccess 16 bytes, des key for Dre 128 bytes
1655 uint8_t des_key_length;
1656 uint8_t atr[64];
1657 uint8_t card_atr[64]; // ATR readed from card
1658 int8_t card_atr_length; // length of ATR
1659 int8_t seca_nagra_card; // seca nagra card
1660 int32_t atrlen;
1661 SIDTABS sidtabs;
1662 SIDTABS lb_sidtabs;
1663 uint8_t hexserial[8];
1664 int32_t nprov;
1665 uint8_t prid[CS_MAXPROV][8];
1666 uint8_t sa[CS_MAXPROV][4]; // viaccess & seca
1667 uint8_t read_old_classes; // viaccess
1668 uint8_t maturity; // viaccess & seca maturity level
1669 uint16_t caid;
1670 uint16_t b_nano;
1671 uint16_t s_nano;
1672 int8_t ecmcommand; // used for filtering nagra bad ecm commands
1673 uint8_t ecmcommandcache[5]; // cachebuff for ecm commands
1674 int32_t blockemm;
1675 int32_t saveemm;
1676 LLIST *blockemmbylen;
1677 char *emmfile;
1678 char pincode[5];
1679 int8_t logemm;
1680 int8_t cachemm;
1681 int16_t rewritemm;
1682 int16_t deviceemm; // catch device specific emms (so far only used for viaccess)
1683 int8_t card_status;
1684 int8_t deprecated; // if 0 ATR obeyed, if 1 default speed (9600) is chosen; for devices that cannot switch baudrate
1685 struct s_module ph;
1686 const struct s_cardreader *crdr;
1687 void *crdr_data; // Private card reader data
1688 bool crdr_flush; // sci readers may disable flush per reader
1689 const struct s_cardsystem *csystem;
1690 void *csystem_data; // Private card system data
1691 bool csystem_active;
1692 uint8_t ncd_key[14];
1693 uint8_t ncd_skey[16];
1694 int8_t ncd_connect_on_init;
1695 int8_t ncd_disable_server_filt;
1696 int8_t ncd_proto;
1697 int8_t currenthops; // number of hops (cccam & gbox)
1698 int8_t sh4_stb; // to set sh4 type box used to identify sci type.
1699#ifdef MODULE_CCCAM
1700 char cc_version[7]; // cccam version
1701 char cc_build[7]; // cccam build number
1702 int8_t cc_maxhops; // cccam max distance
1703 int8_t cc_mindown; // cccam min downhops
1704 int8_t cc_want_emu; // Schlocke: Client want to have EMUs, 0 - NO; 1 - YES
1705 uint32_t cc_id;
1706 int8_t cc_keepalive;
1707 int8_t cc_hop; // For non-cccam reader: hop for virtual cards
1708 int8_t cc_reshare;
1709 int32_t cc_reconnect; // reconnect on ecm-request timeout
1710#endif
1711 int8_t tcp_connected;
1712 int32_t tcp_ito; // inactivity timeout
1713 int32_t tcp_rto; // reconnect timeout
1714 int32_t tcp_reconnect_delay; // max tcp connection block delay
1715
1716 struct timeb tcp_block_connect_till; // time tcp connect ist blocked
1717 int32_t tcp_block_delay; // incrementing block time
1718 time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect )
1719 time_t last_s; // send
1720 time_t last_check; // last checked
1721 time_t last_poll; // last poll
1722 FTAB fchid;
1723 FTAB ftab;
1724 CLASSTAB cltab;
1725 ECM_WHITELIST ecm_whitelist;
1726 ECM_HDR_WHITELIST ecm_hdr_whitelist;
1727 int32_t brk_pos;
1728 int32_t msg_idx;
1729 int32_t secatype; // 0=not determined, 2=seca2, 3=nagra(~seca3) this is only valid for localreaders!
1730 uint32_t maxreadtimeout; // in us
1731 uint32_t minreadtimeout; // in us
1732 uint32_t maxwritetimeout; // in us
1733 uint32_t minwritetimeout; // in us
1734#if defined(WEBIF) || defined(LCDSUPPORT)
1735 int32_t emmwritten[4]; // count written EMM
1736 int32_t emmskipped[4]; // count skipped EMM
1737 int32_t emmerror[4]; // count error EMM
1738 int32_t emmblocked[4]; // count blocked EMM
1739 int32_t webif_emmwritten[4]; // count written EMM for webif reader info
1740 int32_t webif_emmskipped[4]; // count skipped EMM for webif reader info
1741 int32_t webif_emmerror[4]; // count error EMM for reader webif info
1742 int32_t webif_emmblocked[4]; // count blocked EMM for reader webif info
1743 int32_t lbvalue; // loadbalance Value
1744#endif
1745#ifdef WITH_AZBOX
1746 int32_t azbox_mode;
1747#endif
1748 int32_t use_gpio; // Should this reader use GPIO functions
1749 int gpio_outen; // fd of opened /dev/gpio/outen
1750 int gpio_out; // fd of opened /dev/gpio/out
1751 int gpio_in; // fd of opened /dev/gpio/in
1752 uint32_t gpio; // gpio addr
1753#ifdef WITH_CARDREADER
1754 // variables from icc_async.h start
1755 int32_t convention; // Convention of this ICC
1756 uint8_t protocol_type; // Type of protocol
1757 uint32_t current_baudrate; // (for overclocking uncorrected) baudrate to prevent unnecessary conversions from/to termios structure
1758 double worketu; // in us for internal and external readers calculated (1/D)*(F/cardclock)*1000000
1759 uint32_t read_timeout; // Max timeout (ETU) to receive characters
1760 uint32_t char_delay; // Delay (ETU) after transmiting each successive char
1761 uint32_t block_delay; // Delay (ms) after starting to transmit
1762 uint32_t BWT, CWT; // (for overclocking uncorrected) block waiting time, character waiting time, in ETU
1763 // variables from io_serial.h
1764 int32_t written; // keep score of how much bytes are written to serial port, since they are echoed back they have to be read
1765 // variables from protocol_t1.h
1766 uint16_t ifsc; // Information field size for the ICC
1767 uint8_t ns; // Send sequence number
1768 int16_t smartdev_found;
1769 int16_t smart_type;
1770 uint16_t statuscnt;
1771 uint16_t modemstat;
1772#endif
1773#ifdef READER_CRYPTOWORKS
1774 EMM_PACKET *last_g_emm; // last global EMM
1775 bool last_g_emm_valid; // status of last global EMM
1776#endif
1777 uint8_t rom[15];
1778 uint8_t irdId[4];
1779 uint8_t payload4C[15];
1780 uint16_t VgCredit;
1781 uint16_t VgPin;
1782 uint8_t VgFuse;
1783 uint8_t VgCountryC[3];
1784 uint8_t VgRegionC[8];
1785 uint8_t VgLastPayload[6];
1786#ifdef WITH_LB
1787 int32_t lb_weight; // loadbalance weight factor, if unset, weight=100. The higher the value, the higher the usage-possibility
1788 int8_t lb_force_fallback; // force this reader as fallback if fallback or fallback_percaid paramters set
1789 int32_t lb_usagelevel; // usagelevel for loadbalancer
1790 int32_t lb_usagelevel_ecmcount;
1791 struct timeb lb_usagelevel_time; // time for counting ecms, this creates usagelevel
1792 struct timeb lb_last; // time for oldest reader
1793 LLIST *lb_stat; // loadbalancer reader statistics
1794 CS_MUTEX_LOCK lb_stat_lock;
1795 int32_t lb_stat_busy; // do not add while saving
1796#endif
1797
1798 AES_ENTRY *aes_list; // multi AES linked list
1799 int8_t ndsversion; // 0 auto (default), 1 NDS1, 12 NDS1+, 2 NDS2
1800 time_t card_valid_to;
1801 // ratelimit
1802 int32_t ratelimitecm;
1803 int32_t ratelimittime; // ratelimit time in ms (everything below 60 ms is converted to ms by applying *1000)
1804 int8_t ecmunique; // check for matching ecm hash in ratelimitslot
1805 int32_t srvidholdtime; // time in ms to keep srvid in ratelimitslot (during this time not checked for ecmunique!)
1806 // (everything below 60 ms is converted to ms by applying *1000)
1807 struct timeb lastdvbapirateoverride;
1808 uint32_t ecmsok;
1809#ifdef CS_CACHEEX_AIO
1810 uint32_t ecmsoklg;
1811#endif
1812 uint32_t webif_ecmsok;
1813 uint32_t ecmsnok;
1814 uint32_t webif_ecmsnok;
1815 uint32_t ecmstout;
1816 uint32_t webif_ecmstout;
1817 uint32_t ecmnotfoundlimit; // config setting. restart reader if ecmsnok >= ecmnotfoundlimit
1818 int32_t ecmsfilteredhead; // count filtered ECM's by ECM Headerwhitelist
1819 int32_t ecmsfilteredlen; // count filtered ECM's by ECM Whitelist
1820 int32_t webif_ecmsfilteredhead; // count filtered ECM's by ECM Headerwhitelist to readers ecminfo
1821 int32_t webif_ecmsfilteredlen; // count filtered ECM's by ECM Whitelist to readers ecm info
1822 float ecmshealthok;
1823#ifdef CS_CACHEEX_AIO
1824 float ecmshealthoklg;
1825#endif
1826 float ecmshealthnok;
1827 float ecmshealthtout;
1828 int32_t cooldown[2];
1829 int8_t cooldownstate;
1830 struct timeb cooldowntime;
1831 struct ecmrl rlecmh[MAXECMRATELIMIT];
1832 int8_t fix_07;
1833 int8_t fix_9993;
1834 int8_t readtiers; // method to get videoguard tiers
1835 uint8_t ins7E[0x1A + 1];
1836 uint8_t ins7E11[0x01 + 1];
1837 uint8_t ins42[0x25 + 1];
1838 uint8_t ins2e06[0x04 + 1];
1839 int8_t ins7e11_fast_reset;
1840 uint8_t k1_generic[0x10 + 1]; // k1 for generic pairing mode
1841 uint8_t k1_unique[0x10 + 1]; // k1 for unique pairing mode
1842 uint8_t sc8in1_dtrrts_patch; // fix for kernel commit 6a1a82df91fa0eb1cc76069a9efe5714d087eccd
1843
1844#ifdef READER_VIACCESS
1845 uint8_t initCA28; // To set when CA28 succeed
1846 uint32_t key_schedule1[32];
1847 uint32_t key_schedule2[32];
1848#endif
1849
1850#if defined(READER_DRE) || defined(READER_DRECAS)
1851 char *userscript;
1852 uint32_t force_ua;
1853#endif
1854
1855#ifdef READER_DRECAS
1856 char *stmkeys;
1857#endif
1858
1859#ifdef MODULE_GBOX
1860 uint8_t gbox_maxdist;
1861 uint8_t gbox_maxecmsend;
1862 uint8_t gbox_reshare;
1863 int8_t gbox_cccam_reshare;
1864 char last_gsms[128];
1865 uint16_t gbox_remm_peer;
1866 uint16_t gbox_gsms_peer;
1867 uint8_t gbox_force_remm;
1868 uint16_t gbox_cw_src_peer;
1869 uint8_t gbox_crd_slot_lev;
1870 FTAB ccc_gbx_reshare_ident;
1871 uint8_t send_offline_cmd;
1872 uint16_t nb_send_crds;
1873#endif
1874
1875#ifdef MODULE_PANDORA
1876 uint8_t pand_send_ecm;
1877#endif
1878#ifdef MODULE_GHTTP
1879 uint8_t ghttp_use_ssl;
1880#endif
1881#ifdef WITH_EMU
1882 FTAB emu_auproviders; // AU providers for Emu reader
1883 int8_t emu_datecodedenabled; // date-coded keys for BISS
1884#endif
1885 uint8_t cnxlastecm; // == 0 - last ecm has not been paired ecm, > 0 last ecm has been paired ecm
1886 LLIST *emmstat; // emm stats
1887 CS_MUTEX_LOCK emmstat_lock;
1888 struct s_reader *next;
1889};
1890
1891struct s_cpmap
1892{
1893 uint16_t caid;
1894 uint32_t provid;
1895 uint16_t sid;
1896 uint16_t chid;
1897 uint16_t dwtime;
1898 struct s_cpmap *next;
1899};
1900
1901struct s_auth
1902{
1903 char usr[64];
1904 char *pwd;
1905#ifdef WEBIF
1906 char *description;
1907#endif
1908 int8_t uniq;
1909#ifdef CS_CACHEEX
1910 CECSP cacheex; // CacheEx Settings
1911 uint8_t no_wait_time;
1912 uint8_t disablecrccacheex;
1913 FTAB disablecrccacheex_only_for;
1914#endif
1915 int16_t allowedprotocols;
1916 LLIST *aureader_list;
1917 int8_t autoau;
1918 uint8_t emm_reassembly; // 0 = OFF; 1 = OFF / DVBAPI = ON; 2 = ON (default)
1919 int8_t monlvl;
1920 uint64_t grp;
1921 int32_t tosleep;
1922 int32_t umaxidle;
1923 CAIDTAB ctab;
1924 SIDTABS sidtabs;
1925 FTAB fchid;
1926 FTAB ftab; // user [caid] and ident filter
1927 CLASSTAB cltab;
1928 TUNTAB ttab;
1929 int8_t preferlocalcards;
1930 uint32_t max_connections;
1931#ifdef CS_ANTICASC
1932 int32_t ac_fakedelay; // When this is -1, the global ac_fakedelay is used
1933 int32_t ac_users; // 0 - unlimited
1934 int8_t ac_penalty; // 0 - log, >0 - fake dw
1935 struct s_acasc ac_stat;
1936 int8_t acosc_max_ecms_per_minute; // user value 0 - unlimited
1937 int8_t acosc_max_active_sids; // user value 0 - unlimited
1938 int8_t acosc_zap_limit; // user value 0 - unlimited
1939 int8_t acosc_penalty; // user value penalty
1940 int32_t acosc_penalty_duration; // user value how long is penalty activ in sek.
1941 time_t acosc_penalty_until;
1942 int8_t acosc_penalty_active; // 0-deaktiv 1-max_active_sids 2-zap_limit 3-max_ecms_per_minute 4-penaly_duration
1943 int32_t acosc_delay; // user value
1944 int8_t acosc_user_zap_count;
1945 time_t acosc_user_zap_count_start_time;
1946#endif
1947#ifdef WITH_LB
1948 int32_t lb_nbest_readers; // When this is -1, the global lb_nbest_readers is used
1949 int32_t lb_nfb_readers; // When this is -1, the global lb_nfb_readers is used
1950 CAIDVALUETAB lb_nbest_readers_tab; // like nbest_readers, but for special caids
1951#endif
1952 IN_ADDR_T dynip;
1953 char *dyndns;
1954 time_t expirationdate;
1955 time_t firstlogin;
1956 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
1957 uint8_t allowedtimeframe_set; // flag for internal use to mention if allowed time frame is used
1958 int8_t c35_suppresscmd08;
1959 uint8_t c35_sleepsend;
1960 int8_t ncd_keepalive;
1961#ifdef MODULE_CCCAM
1962 int32_t cccmaxhops;
1963 int8_t cccreshare;
1964 int8_t cccignorereshare;
1965 int8_t cccstealth;
1966#endif
1967 int8_t disabled;
1968 int32_t failban;
1969
1970 int32_t cwfound;
1971 int32_t cwcache;
1972 int32_t cwnot;
1973 int32_t cwtun;
1974 int32_t cwignored;
1975 int32_t cwtout;
1976#ifdef CW_CYCLE_CHECK
1977 int32_t cwcycledchecked; // count checked cwcycles per client
1978 int32_t cwcycledok; // count pos checked cwcycles per client
1979 int32_t cwcyclednok; // count neg checked cwcycles per client
1980 int32_t cwcycledign; // count ign cwcycles per client
1981 int8_t cwc_disable; // disable cwc checking for this Client
1982#endif
1983 int32_t emmok;
1984 int32_t emmnok;
1985#ifdef CS_CACHEEX
1986 int32_t cwcacheexpush; // count pushed ecms/cws
1987 int32_t cwcacheexgot; // count got ecms/cws
1988 int32_t cwcacheexhit; // count hit ecms/cws
1989 int32_t cwcacheexerr; // cw=00 or chksum wrong
1990 int32_t cwcacheexerrcw; // Same Hex, different CW
1991 int32_t cwc_info; // count of in/out comming cacheex ecms with CWCinfo
1992#ifdef CS_CACHEEX_AIO
1993 int32_t cwcacheexgotlg; // count got localgenerated-flagged CWs
1994 int32_t cwcacheexpushlg; // count pushed localgenerated-flagged CWs
1995#endif
1996#endif
1997 struct s_auth *next;
1998};
1999
2000
2001struct s_srvid_caid
2002{
2003 uint16_t caid;
2004 uint16_t nprovid;
2005 uint32_t *provid;
2006};
2007
2008struct s_srvid
2009{
2010 uint16_t srvid;
2011 int8_t ncaid;
2012 struct s_srvid_caid *caid;
2013 char *data;
2014 const char *prov;
2015 const char *name;
2016 const char *type;
2017 const char *desc;
2018 struct s_srvid *next;
2019};
2020
2021struct s_rlimit
2022{
2023 struct ecmrl rl;
2024 struct s_rlimit *next;
2025};
2026
2027struct s_cw
2028{
2029 uint8_t cw[16];
2030};
2031
2032struct s_fakecws
2033{
2034 uint32_t count;
2035 struct s_cw *data;
2036};
2037
2038#ifdef MODULE_SERIAL
2039struct s_twin
2040{
2041 struct ecmtw tw;
2042 struct s_twin *next;
2043};
2044#endif
2045
2046struct s_tierid
2047{
2048 uint16_t tierid;
2049 int8_t ncaid;
2050 uint16_t caid[10];
2051 char name[33];
2052 struct s_tierid *next;
2053};
2054
2055struct s_provid
2056{
2057 uint16_t caid;
2058 uint16_t nprovid;
2059 uint32_t *provid;
2060 char prov[33];
2061 char sat[33];
2062 char lang[33];
2063 struct s_provid *next;
2064};
2065
2066struct s_ip
2067{
2068 IN_ADDR_T ip[2];
2069 struct s_ip *next;
2070};
2071
2072struct s_global_whitelist
2073{
2074 uint32_t line; // linenr of oscam.whitelist file, starting with 1
2075 char type; // w or i or l
2076 uint16_t caid;
2077 uint32_t provid;
2078 uint16_t srvid;
2079 uint16_t chid;
2080 uint16_t pid;
2081 uint16_t ecmlen;
2082 uint16_t mapcaid;
2083 uint32_t mapprovid;
2084 struct s_global_whitelist *next;
2085};
2086
2087struct s_cacheex_matcher
2088{
2089 uint32_t line; // linenr of oscam.Cacheex file, starting with 1
2090 char type; // m
2091 uint16_t caid;
2092 uint32_t provid;
2093 uint16_t srvid;
2094 uint16_t chid;
2095 uint16_t pid;
2096 uint16_t ecmlen;
2097
2098 uint16_t to_caid;
2099 uint32_t to_provid;
2100 uint16_t to_srvid;
2101 uint16_t to_chid;
2102 uint16_t to_pid;
2103 uint16_t to_ecmlen;
2104
2105 int32_t valid_from;
2106 int32_t valid_to;
2107
2108 struct s_cacheex_matcher *next;
2109};
2110
2111struct s_config
2112{
2113 int32_t nice;
2114 uint32_t netprio;
2115 uint32_t ctimeout;
2116 uint32_t ftimeout;
2117 CAIDVALUETAB ftimeouttab;
2118 uint32_t cmaxidle;
2119 int32_t ulparent;
2120 uint32_t delay;
2121 int32_t bindwait;
2122 int32_t tosleep;
2123 IN_ADDR_T srvip;
2124 char *usrfile;
2125 char *cwlogdir;
2126 char *emmlogdir;
2127 char *logfile;
2128 char *mailfile;
2129 int8_t disablecrccws; // 1=disable cw checksum test. 0=enable checksum check
2130 FTAB disablecrccws_only_for; // ignore checksum for selected caid provid
2131 uint8_t logtostdout;
2132 uint8_t logtosyslog;
2133 int8_t logduplicatelines;
2134 int32_t initial_debuglevel;
2135 char *sysloghost;
2136 int32_t syslogport;
2137#if defined(WEBIF) || defined(MODULE_MONITOR)
2138 uint32_t loghistorylines;
2139#endif
2140 int8_t disablelog;
2141 int8_t disablemail;
2142 int8_t disableuserfile;
2143 int8_t usrfileflag;
2144 struct s_auth *account;
2145 struct s_srvid *srvid[16];
2146 struct s_tierid *tierid;
2147 struct s_provid *provid;
2148 struct s_sidtab *sidtab;
2149#ifdef MODULE_MONITOR
2150 int32_t mon_port;
2151 IN_ADDR_T mon_srvip;
2152 struct s_ip *mon_allowed;
2153 uint8_t mon_level;
2154#endif
2155 int32_t aulow;
2156 int32_t hideclient_to;
2157#ifdef WEBIF
2158 int32_t http_port;
2159 IN_ADDR_T http_srvip;
2160 char *http_user;
2161 char *http_pwd;
2162 char *http_css;
2163 int8_t http_prepend_embedded_css;
2164 char *http_jscript;
2165 char *http_tpl;
2166 char *http_piconpath;
2167 char *http_script;
2168#ifndef WEBIF_JQUERY
2169 char *http_extern_jquery;
2170#endif
2171 int32_t http_refresh;
2172 int32_t poll_refresh;
2173 int8_t http_hide_idle_clients;
2174 char *http_hide_type;
2175 int8_t http_showpicons;
2176 int8_t http_picon_size;
2177 int8_t http_status_log;
2178 int8_t http_showmeminfo;
2179 int8_t http_showecminfo;
2180 int8_t http_showloadinfo;
2181 int8_t http_showuserinfo;
2182 int8_t http_showreaderinfo;
2183 int8_t http_showcacheexinfo;
2184 struct s_ip *http_allowed;
2185 int8_t http_readonly;
2186 IN_ADDR_T http_dynip[MAX_HTTP_DYNDNS];
2187 uint8_t http_dyndns[MAX_HTTP_DYNDNS][64];
2188 int8_t http_use_ssl;
2189 int8_t https_force_secure_mode;
2190 char *http_cert;
2191 char *http_help_lang;
2192 char *http_locale;
2193 char *http_oscam_label;
2194 int32_t http_emmu_clean;
2195 int32_t http_emms_clean;
2196 int32_t http_emmg_clean;
2197#endif
2198 int8_t http_full_cfg;
2199 int8_t http_overwrite_bak_file;
2200 int32_t failbantime;
2201 int32_t failbancount;
2202 LLIST *v_list; // Failban list
2203#ifdef MODULE_CAMD33
2204 int32_t c33_port;
2205 IN_ADDR_T c33_srvip;
2206 uint8_t c33_key[16];
2207 int32_t c33_crypted;
2208 int32_t c33_passive;
2209 struct s_ip *c33_plain;
2210#endif
2211#if defined(MODULE_CAMD35) || defined(MODULE_CAMD35_TCP)
2212 int32_t c35_port;
2213 IN_ADDR_T c35_srvip;
2214 int8_t c35_tcp_suppresscmd08;
2215 int8_t c35_udp_suppresscmd08;
2216 PTAB c35_tcp_ptab;
2217 IN_ADDR_T c35_tcp_srvip;
2218#endif
2219 int8_t c35_suppresscmd08; // used in cccam module
2220 int8_t getblockemmauprovid;
2221 int32_t umaxidle; //User max Idle
2222#ifdef MODULE_NEWCAMD
2223 PTAB ncd_ptab;
2224 IN_ADDR_T ncd_srvip;
2225 uint8_t ncd_key[14];
2226 int8_t ncd_keepalive;
2227 int8_t ncd_mgclient;
2228 struct s_ip *ncd_allowed;
2229#endif
2230#ifdef MODULE_RADEGAST
2231 int32_t rad_port;
2232 IN_ADDR_T rad_srvip;
2233 struct s_ip *rad_allowed;
2234 char *rad_usr;
2235#endif
2236#ifdef MODULE_CCCAM
2237 uint16_t cc_port[CS_MAXPORTS];
2238 int8_t cc_reshare;
2239 int8_t cc_ignore_reshare;
2240 int32_t cc_update_interval;
2241 IN_ADDR_T cc_srvip;
2242 char cc_version[7];
2243 int8_t cc_minimize_cards;
2244 int8_t cc_keep_connected;
2245 int8_t cc_stealth;
2246 int8_t cc_reshare_services;
2247 int8_t cc_forward_origin_card;
2248 uint8_t cc_fixed_nodeid[8];
2249 uint32_t cc_recv_timeout; // The poll() timeout parameter in ms. Default: DEFAULT_CC_RECV_TIMEOUT (2000 ms).
2250#endif
2251#ifdef MODULE_GBOX
2252 #define GBOX_MY_VERS_DEF 0x2A
2253 #define GBOX_MY_CPU_API_DEF 0x61
2254 #define GBOX_MAX_PROXY_CARDS 32
2255 #define GBOX_MAX_IGNORED_PEERS 16
2256 #define GBOX_MAX_BLOCKED_ECM 16
2257 #define GBOX_MAX_REMM_PEERS 8
2258 #define GBOX_MAX_DEST_PEERS 16
2259 #define GBOX_MAX_MSG_TXT 127
2260 uint16_t gbox_port[CS_MAXPORTS];
2261 char *gbox_hostname;
2262 uint32_t gbox_reconnect;
2263 uint32_t gbox_password;
2264 unsigned long gbox_proxy_card[GBOX_MAX_PROXY_CARDS];
2265 int8_t gbox_proxy_cards_num;
2266 uint32_t gbox_my_vers;
2267 uint8_t gbox_my_cpu_api;
2268 uint8_t gsms_dis;
2269 uint8_t log_hello;
2270 uint8_t dis_attack_txt;
2271 char *gbox_tmp_dir;
2272 uint8_t cc_gbx_reshare_en;
2273 uint16_t gbox_ignored_peer[GBOX_MAX_IGNORED_PEERS];
2274 uint8_t gbox_ignored_peer_num;
2275 uint16_t accept_remm_peer[GBOX_MAX_REMM_PEERS];
2276 uint8_t accept_remm_peer_num;
2277 uint16_t gbox_block_ecm[GBOX_MAX_BLOCKED_ECM];
2278 uint8_t gbox_block_ecm_num;
2279 uint8_t gbox_save_gsms;
2280 uint8_t gbox_msg_type;
2281 uint16_t gbox_dest_peers[GBOX_MAX_DEST_PEERS];
2282 uint8_t gbox_dest_peers_num;
2283 char gbox_msg_txt[GBOX_MAX_MSG_TXT+1];
2284#endif
2285#ifdef MODULE_SERIAL
2286 char *ser_device;
2287#endif
2288 int32_t max_log_size;
2289 int8_t waitforcards;
2290 int32_t waitforcards_extra_delay;
2291 int8_t preferlocalcards;
2292 int32_t reader_restart_seconds; // schlocke: reader restart auf x seconds, disable = 0
2293 int8_t dropdups; // drop duplicate logins
2294
2295
2296 // Loadbalancer-Config:
2297 int32_t lb_mode; // schlocke: reader loadbalancing mode
2298 int32_t lb_auto_betatunnel; // automatic selection of betatunnel convertion based on learned data
2299 int32_t lb_auto_betatunnel_mode; // automatic selection of betatunnel direction
2300#ifdef WITH_LB
2301 int32_t lb_save; // schlocke: load/save statistics to file, save every x ecms
2302 int32_t lb_nbest_readers; // count of best readers
2303 int32_t lb_nfb_readers; // count of fallback readers
2304 int32_t lb_min_ecmcount; // minimal ecm count to evaluate lbvalues
2305 int32_t lb_max_ecmcount; // maximum ecm count before reseting lbvalues
2306 int32_t lb_reopen_seconds; // time between retrying failed readers/caids/prov/srv
2307 int8_t lb_reopen_invalid; // default=1; if 0, rc=E_INVALID will be blocked until stats cleaned
2308 int8_t lb_force_reopen_always; // force reopening immediately all failing readers if no matching reader found
2309 int32_t lb_retrylimit; // reopen only happens if reader response time > retrylimit
2310 CAIDVALUETAB lb_retrylimittab;
2311 CAIDVALUETAB lb_nbest_readers_tab; // like nbest_readers, but for special caids
2312 CAIDTAB lb_noproviderforcaid; // do not store loadbalancer stats with providers for this caid
2313 char *lb_savepath; // path where the stat file is save. Empty=default=/tmp/.oscam/stat
2314 int32_t lb_stat_cleanup; // duration in hours for cleaning old statistics
2315 int32_t lb_max_readers; // limit the amount of readers during learning
2316 int32_t lb_auto_betatunnel_prefer_beta; // prefer-beta-over-nagra factor
2317 int32_t lb_auto_timeout; // Automatic timeout by loadbalancer statistics
2318 int32_t lb_auto_timeout_p; // percent added to avg time as timeout time
2319 int32_t lb_auto_timeout_t; // minimal time added to avg time as timeout time
2320#endif
2321 int32_t resolve_gethostbyname;
2322 int8_t double_check; // schlocke: Double checks each ecm+dcw from two (or more) readers
2323 FTAB double_check_caid; // do not store loadbalancer stats with providers for this caid
2324
2325#ifdef HAVE_DVBAPI
2326 int8_t dvbapi_enabled;
2327 int8_t dvbapi_au;
2328 char *dvbapi_usr;
2329 int8_t dvbapi_boxtype;
2330 int8_t dvbapi_pmtmode;
2331 int8_t dvbapi_requestmode;
2332 int32_t dvbapi_listenport; // TCP port to listen instead of camd.socket (network mode, default=0 -> disabled)
2333 SIDTABS dvbapi_sidtabs;
2334 int32_t dvbapi_delayer; // delayer ms, minimum time to write cw
2335 int8_t dvbapi_ecminfo_file; // Enable or disable ecm.info file creation
2336 int8_t dvbapi_ecminfo_type;
2337 int8_t dvbapi_read_sdt;
2338 int8_t dvbapi_write_sdt_prov;
2339 int8_t dvbapi_extended_cw_api;
2340#endif
2341
2342#ifdef CS_ANTICASC
2343 int8_t ac_enabled;
2344 int32_t ac_users; // num of users for account (0 - default)
2345 int32_t ac_stime; // time to collect AC statistics (3 min - default)
2346 int32_t ac_samples; // qty of samples
2347 int8_t ac_penalty; // 0 - write to log
2348 int32_t ac_fakedelay; // 100-1000 ms
2349 int32_t ac_denysamples;
2350 char *ac_logfile;
2351 struct s_cpmap *cpmap;
2352 int8_t acosc_enabled;
2353 int8_t acosc_max_ecms_per_minute; // global value 0 - unlimited
2354 int8_t acosc_max_active_sids; // global value 0 - unlimited
2355 int8_t acosc_zap_limit; // global value 0 - unlimited
2356 int32_t acosc_penalty_duration; // global value how long is penalty activ in sek.
2357 int8_t acosc_penalty; // global value
2358 int32_t acosc_delay; // global value
2359#endif
2360
2361#ifdef LEDSUPPORT
2362 int8_t enableled; // 0=disabled led, 1=enable led for routers, 2=enable qboxhd led
2363#endif
2364
2365#ifdef LCDSUPPORT
2366 int8_t enablelcd;
2367 char *lcd_output_path;
2368 int32_t lcd_hide_idle;
2369 int32_t lcd_write_intervall;
2370#endif
2371
2372#ifdef MODULE_PANDORA
2373 int8_t pand_skip_send_dw;
2374 struct s_ip *pand_allowed;
2375 char *pand_usr;
2376 char *pand_pass;
2377 int8_t pand_ecm;
2378 int32_t pand_port;
2379 IN_ADDR_T pand_srvip;
2380#endif
2381
2382#ifdef MODULE_SCAM
2383 int32_t scam_port;
2384 IN_ADDR_T scam_srvip;
2385 struct s_ip *scam_allowed;
2386#endif
2387
2388#ifdef WITH_EMU
2389 char *emu_stream_source_host;
2390 int32_t emu_stream_source_port;
2391 char *emu_stream_source_auth_user;
2392 char *emu_stream_source_auth_password;
2393 int32_t emu_stream_relay_port;
2394 uint32_t emu_stream_ecm_delay;
2395 int8_t emu_stream_relay_enabled;
2396 int8_t emu_stream_emm_enabled;
2397 CAIDTAB emu_stream_relay_ctab; // use the stream server for these caids
2398#endif
2399
2400 int32_t max_cache_time; // seconds ecms are stored in ecmcwcache
2401 int32_t max_hitcache_time; // seconds hits are stored in cspec_hitcache (to detect dyn wait_time)
2402
2403 int8_t reload_useraccounts;
2404 int8_t reload_readers;
2405 int8_t reload_provid;
2406 int8_t reload_services_ids;
2407 int8_t reload_tier_ids;
2408 int8_t reload_fakecws;
2409 int8_t reload_ac_stat;
2410 int8_t reload_log;
2411
2412 int8_t block_same_ip; // 0=allow all, 1=block client requests to reader with same ip (default=1)
2413 int8_t block_same_name; // 0=allow all, 1=block client requests to reader with same name (default=1)
2414
2415#ifdef CS_CACHEEX
2416#ifdef CS_CACHEEX_AIO
2417 uint32_t cw_cache_size;
2418 uint32_t cw_cache_memory;
2419 CWCHECKTAB cw_cache_settings;
2420
2421 uint32_t ecm_cache_size;
2422 uint32_t ecm_cache_memory;
2423 int32_t ecm_cache_droptime;
2424#endif
2425 uint8_t wait_until_ctimeout;
2426 CWCHECKTAB cacheex_cwcheck_tab;
2427 IN_ADDR_T csp_srvip;
2428 int32_t csp_port;
2429 CECSPVALUETAB cacheex_wait_timetab;
2430 CAIDVALUETAB cacheex_mode1_delay_tab;
2431#ifdef CS_CACHEEX_AIO
2432 CAIDVALUETAB cacheex_nopushafter_tab;
2433 uint8_t waittime_block_start;
2434 uint16_t waittime_block_time;
2435#endif
2436 CECSP csp; // CSP Settings
2437 uint8_t cacheex_enable_stats; // enable stats
2438 struct s_cacheex_matcher *cacheex_matcher;
2439#ifdef CS_CACHEEX_AIO
2440 uint8_t cacheex_dropdiffs;
2441 uint8_t cacheex_lg_only_remote_settings;
2442 uint8_t cacheex_localgenerated_only;
2443 CAIDTAB cacheex_localgenerated_only_caidtab;
2444 FTAB cacheex_lg_only_tab;
2445 uint8_t cacheex_localgenerated_only_in;
2446 CAIDTAB cacheex_localgenerated_only_in_caidtab;
2447 FTAB cacheex_lg_only_in_tab;
2448 uint8_t cacheex_lg_only_in_aio_only;
2449 CECSPVALUETAB cacheex_filter_caidtab;
2450 CECSPVALUETAB cacheex_filter_caidtab_aio;
2451 uint64_t cacheex_push_lg_groups;
2452#endif
2453#endif
2454
2455#ifdef CW_CYCLE_CHECK
2456 int8_t cwcycle_check_enable; // on or off
2457 CAIDTAB cwcycle_check_caidtab; // Caid for CW Cycle Check
2458 int32_t keepcycletime; // how long stay the learned Cycletime in Memory
2459 int32_t maxcyclelist; // max size of cwcyclelist
2460 int8_t onbadcycle; // what to do on bad cwcycle
2461 int8_t cwcycle_dropold; // what to do on old ecmd5/cw
2462 int8_t cwcycle_sensitive;
2463 int8_t cwcycle_allowbadfromffb; // allow Bad cycles from Fixed Fallbackreader
2464 int8_t cwcycle_usecwcfromce; // Use CWC Info from Cacheex Sources for CWC Checking
2465#endif
2466
2467 // Global whitelist:
2468 struct s_global_whitelist *global_whitelist;
2469 int8_t global_whitelist_use_l;
2470 int8_t global_whitelist_use_m;
2471
2472 char *ecmfmt;
2473 char *pidfile;
2474
2475 int32_t max_pending;
2476
2477 // Ratelimit list
2478 struct s_rlimit *ratelimit_list;
2479
2480 // fake cws
2481 struct s_fakecws fakecws[0x100];
2482
2483#ifdef MODULE_SERIAL
2484 struct s_twin *twin_list;
2485#endif
2486};
2487
2488struct s_clientinit
2489{
2490 void *(*handler)(struct s_client *);
2491 struct s_client *client;
2492};
2493
2494struct s_clientmsg
2495{
2496 uint8_t msg[1024];
2497 int32_t len;
2498 int32_t cmd;
2499};
2500
2501typedef struct reader_stat_t
2502{
2503 int32_t rc;
2504 uint16_t caid;
2505 uint32_t prid;
2506 uint16_t srvid;
2507 uint32_t chid;
2508 int16_t ecmlen;
2509
2510 struct timeb last_received;
2511
2512 int32_t ecm_count;
2513 int32_t time_avg;
2514 int32_t time_stat[LB_MAX_STAT_TIME];
2515 int32_t time_idx;
2516
2517 int32_t fail_factor;
2518} READER_STAT;
2519
2520typedef struct cs_stat_query
2521{
2522 uint16_t caid;
2523 uint32_t prid;
2524 uint16_t srvid;
2525 uint32_t chid;
2526 int16_t ecmlen;
2527} STAT_QUERY;
2528
2529struct s_write_from_cache
2530{
2531 ECM_REQUEST *er_new;
2532 ECM_REQUEST *er_cache;
2533};
2534
2535/* ===========================
2536 * global variables
2537 * =========================== */
2538extern pthread_key_t getclient;
2539extern struct s_client *first_client;
2540extern CS_MUTEX_LOCK config_lock;
2541extern CS_MUTEX_LOCK clientlist_lock;
2542extern CS_MUTEX_LOCK readerlist_lock;
2543extern struct s_reader *first_active_reader; // points to list of _active_ readers (enable = 1, deleted = 0)
2544extern LLIST *configured_readers;
2545
2546// These are used pretty much everywhere
2547extern struct s_config cfg;
2548extern uint16_t cs_dblevel;
2549
2550#include "oscam-log.h"
2551#include "oscam-log-reader.h"
2552
2553// Add here *only* funcs that are implemented in oscam.c and are called in other places
2554void cs_exit(int32_t sig);
2555void cs_exit_oscam(void);
2556void cs_restart_oscam(void);
2557int32_t cs_get_restartmode(void);
2558
2559void set_thread_name(const char *thread_name);
2560int32_t start_thread(char *nameroutine, void *startroutine, void *arg, pthread_t *pthread, int8_t detach, int8_t modify_stacksize);
2561int32_t start_thread_nolog(char *nameroutine, void *startroutine, void *arg, pthread_t *pthread, int8_t detach, int8_t modify_stacksize);
2562void kill_thread(struct s_client *cl);
2563
2564struct s_module *get_module(struct s_client *cl);
2565void module_reader_set(struct s_reader *rdr);
2566
2567// Until we find a better place for these (they are implemented in oscam-simples.h)
2568char *get_servicename(struct s_client *cl, uint16_t srvid, uint32_t provid, uint16_t caid, char *buf, uint32_t buflen);
2569char *get_servicename_or_null(struct s_client *cl, uint16_t srvid, uint32_t provid, uint16_t caid, char *buf, uint32_t buflen);
2570char *get_picon_servicename_or_null(struct s_client *cl, uint16_t srvid, uint32_t provid, uint16_t caid, char *buf, uint32_t buflen);
2571int32_t picon_servicename_remve_hd(char *buf, uint32_t buflen);
2572char *get_tiername(uint16_t tierid, uint16_t caid, char *buf);
2573char *get_tiername_defaultid(uint16_t tierid, uint16_t caid, char *buf);
2574char *get_provider(uint32_t provid, uint16_t caid, char *buf, uint32_t buflen);
2575char *get_providername(uint32_t provid, uint16_t caid, char *buf, uint32_t buflen);
2576char *get_providername_or_null(uint32_t provid, uint16_t caid, char *buf, uint32_t buflen);
2577void add_provider(uint16_t caid, uint32_t provid, const char *name, const char *sat, const char *lang);
2578const char *get_cl_lastprovidername(struct s_client *cl);
2579bool boxtype_is(const char *boxtype);
2580bool boxname_is(const char *boxname);
2581const char *boxtype_get(void);
2582const char *boxname_get(void);
2583static inline bool caid_is_fake(uint16_t caid) { return caid == 0xffff; }
2584static inline bool caid_is_biss(uint16_t caid) { return caid >> 8 == 0x26; }
2585static inline bool caid_is_biss_fixed(uint16_t caid) { return caid == 0x2600 || caid == 0x2602; } // fixed cw, fake ecm
2586static inline bool caid_is_biss_dynamic(uint16_t caid) { return caid == 0x2610; } // dynamic cw, real ecm and emm
2587static inline bool caid_is_seca(uint16_t caid) { return caid >> 8 == 0x01; }
2588static inline bool caid_is_viaccess(uint16_t caid) { return caid >> 8 == 0x05; }
2589static inline bool caid_is_irdeto(uint16_t caid) { return caid >> 8 == 0x06; }
2590static inline bool caid_is_videoguard(uint16_t caid) { return caid >> 8 == 0x09; }
2591static inline bool caid_is_conax(uint16_t caid) { return caid >> 8 == 0x0B; }
2592static inline bool caid_is_cryptoworks(uint16_t caid) { return caid >> 8 == 0x0D; }
2593static inline bool caid_is_powervu(uint16_t caid) { return caid >> 8 == 0x0E; }
2594static inline bool caid_is_director(uint16_t caid) { return caid >> 8 == 0x10; }
2595static inline bool caid_is_betacrypt(uint16_t caid) { return caid >> 8 == 0x17; }
2596static inline bool caid_is_nagra(uint16_t caid) { return caid >> 8 == 0x18; }
2597static inline bool caid_is_bulcrypt(uint16_t caid) { return caid == 0x5581 || caid == 0x4AEE; }
2598static inline bool caid_is_dre(uint16_t caid) { return caid == 0x4AE0 || caid == 0x4AE1 || caid == 0x2710;}
2599const char *get_cardsystem_desc_by_caid(uint16_t caid);
2600
2601#ifdef WITH_EMU
2602FILTER *get_emu_prids_for_caid(struct s_reader *rdr, uint16_t caid);
2603#endif
2604
2605#endif
Note: See TracBrowser for help on using the repository browser.