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