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