source: trunk/globals.h@ 8456

Last change on this file since 8456 was 8456, checked in by gf, 9 years ago

Slim down struct s_port.

struct s_port contains filter array and couple of other fields that are
used only for newcamd and nothing else. They waste more than 2k in common
case.

To stop losing this much space, create private structure only for
newcamd fields and allocate it dynamically. This lowers struct s_port
size a lot and of course struct s_ptab even more because it contains
array of struct s_ports's.

New structure sizes (32-bit):

                  before  after
  struct s_port     2144     12
  struct s_ptab    68612    388
  struct s_config 141260   4812

Size report (32-bit):

    text     data      bss      dec    hex filename
  998222     1944   602344  1602510 1873ce before/oscam-1.20-unstable_svn8453-i486-slackware-linux
  998174     1944    61800  1061918 10341e  after/oscam-1.20-unstable_svn8453-i486-slackware-linux

bloat-o-meter report (32-bit):

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