1 | #define _GNU_SOURCE //prevents "implicit" warning for asprintf
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <assert.h>
|
---|
5 | #include <fcntl.h>
|
---|
6 | #include <sys/ioctl.h>
|
---|
7 | #include <sys/poll.h>
|
---|
8 | #include <ctype.h>
|
---|
9 | #include <sys/types.h>
|
---|
10 | #include <sys/stat.h>
|
---|
11 | #include <sys/shm.h>
|
---|
12 | #include <sys/wait.h>
|
---|
13 | #include <unistd.h>
|
---|
14 | #include <sys/mman.h>
|
---|
15 | #include <stdarg.h>
|
---|
16 | #include <time.h>
|
---|
17 | #include <sys/timeb.h>
|
---|
18 | #include <limits.h>
|
---|
19 | #include <pwd.h>
|
---|
20 | #include <netinet/tcp.h>
|
---|
21 |
|
---|
22 | #include <sys/socket.h>
|
---|
23 | #include <netinet/in.h>
|
---|
24 | #include <arpa/inet.h>
|
---|
25 | #include <netdb.h>
|
---|
26 | #include <string.h>
|
---|
27 | #include <signal.h>
|
---|
28 | #include <errno.h>
|
---|
29 |
|
---|
30 | #include <pthread.h>
|
---|
31 |
|
---|
32 | #include "module-datastruct-llist.h"
|
---|
33 |
|
---|
34 | //for reader-nagra variables in s_reader:
|
---|
35 | #include "cscrypt/idea.h"
|
---|
36 |
|
---|
37 | // Prevent use of unsafe functions (doesn't work for MacOSX)
|
---|
38 | #ifndef OS_MACOSX
|
---|
39 | #define strcpy(a,b) UNSAFE_STRCPY_USE_CS_STRNCPY_INSTEAD()
|
---|
40 | #define sprintf(a,...) UNSAFE_SPRINTF_USE_SNPRINTF_INSTEAD()
|
---|
41 | #define strtok(a,b,c) UNSAFE_STRTOK_USE_STRTOK_R_INSTEAD()
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | #ifndef CS_GLOBALS
|
---|
45 | #define CS_GLOBALS
|
---|
46 | #define CS_VERSION "1.00-unstable_svn"
|
---|
47 | #ifndef CS_SVN_VERSION
|
---|
48 | # define CS_SVN_VERSION "test"
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | #include "oscam-config.h"
|
---|
52 |
|
---|
53 | #ifdef UNUSED
|
---|
54 | #elif defined(__GNUC__)
|
---|
55 | # define UNUSED(x) UNUSED_ ## x __attribute__((unused))
|
---|
56 | #elif defined(__LCLINT__)
|
---|
57 | # define UNUSED(x) /*@unused@*/ x
|
---|
58 | #else
|
---|
59 | # define UNUSED(x) x
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | #ifdef WITH_DEBUG
|
---|
63 | # define call(arg) \
|
---|
64 | if (arg) { \
|
---|
65 | cs_debug_mask(D_TRACE, "ERROR, function call %s returns error.",#arg); \
|
---|
66 | return ERROR; \
|
---|
67 | }
|
---|
68 | # define D_USE(x) x
|
---|
69 | #else
|
---|
70 | # define call(arg) arg
|
---|
71 | # if defined(__GNUC__)
|
---|
72 | # define D_USE(x) D_USE_ ## x __attribute__((unused))
|
---|
73 | # elif defined(__LCLINT__)
|
---|
74 | # define D_USE(x) /*@debug use only@*/ x
|
---|
75 | # else
|
---|
76 | # define D_USE(x) x
|
---|
77 | # endif
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | #ifndef USE_CMAKE
|
---|
81 | # include "oscam-ostype.h"
|
---|
82 | #endif
|
---|
83 | #include "oscam-types.h"
|
---|
84 | #include "cscrypt/cscrypt.h"
|
---|
85 |
|
---|
86 | #ifdef HAVE_PCSC
|
---|
87 | #ifdef OS_CYGWIN32
|
---|
88 | #define __reserved
|
---|
89 | #define __nullnullterminated
|
---|
90 | #include <specstrings.h>
|
---|
91 | #include "cygwin/WinSCard.h"
|
---|
92 | #else
|
---|
93 | #include <PCSC/pcsclite.h>
|
---|
94 | #ifdef OS_MACOSX
|
---|
95 | #include <PCSC/wintypes.h>
|
---|
96 | #else
|
---|
97 | #include <PCSC/reader.h>
|
---|
98 | #endif
|
---|
99 | #endif
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | #if defined(LIBUSB)
|
---|
103 | #ifdef __FreeBSD__
|
---|
104 | #include <libusb.h>
|
---|
105 | #else
|
---|
106 | #include <libusb-1.0/libusb.h>
|
---|
107 | #endif
|
---|
108 | #include "csctapi/smartreader_types.h"
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | // DM500 and Dbox2 have toolchains which don't match their plattform. Therefore pthread_cleanup_push can't be used (binaries compile but only work on DM 7020)
|
---|
112 | #if defined(TUXBOX) && defined(PPC)
|
---|
113 | #define NO_PTHREAD_CLEANUP_PUSH
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | #ifndef CS_CONFDIR
|
---|
117 | #define CS_CONFDIR "/usr/local/etc"
|
---|
118 | #endif
|
---|
119 | #ifndef CS_LOGFILE
|
---|
120 | #define CS_LOGFILE "/var/log/oscam.log"
|
---|
121 | #endif
|
---|
122 | #define CS_QLEN 128 // size of request queue
|
---|
123 | #define CS_MAXCAIDTAB 32 // max. caid-defs/user
|
---|
124 | #define CS_MAXTUNTAB 20 // max. betatunnel mappings
|
---|
125 | #define CS_MAXPROV 32
|
---|
126 | #define CS_MAXPORTS 32 // max server ports
|
---|
127 | #define CS_MAXFILTERS 16
|
---|
128 | #define CS_MAX_CAIDVALUETAB 16
|
---|
129 |
|
---|
130 | #define CS_ECMSTORESIZE 16 // use MD5()
|
---|
131 | #define CS_EMMSTORESIZE 16 // use MD5()
|
---|
132 | #define CS_CLIENT_TIMEOUT 5000
|
---|
133 | #define CS_CLIENT_MAXIDLE 120
|
---|
134 | #define CS_BIND_TIMEOUT 120
|
---|
135 | #define CS_DELAY 0
|
---|
136 | #define CS_ECM_RINGBUFFER_MAX 20 // max size for ECM last responsetimes ringbuffer
|
---|
137 |
|
---|
138 | #define CS_CACHE_TIMEOUT 60
|
---|
139 | #ifndef PTHREAD_STACK_MIN
|
---|
140 | #define PTHREAD_STACK_MIN 64000
|
---|
141 | #endif
|
---|
142 |
|
---|
143 | #ifdef CS_EMBEDDED
|
---|
144 | #define CS_MAXPENDING 16
|
---|
145 | #define PTHREAD_STACK_SIZE PTHREAD_STACK_MIN+8000
|
---|
146 | #else
|
---|
147 | #define CS_MAXPENDING 32
|
---|
148 | #define PTHREAD_STACK_SIZE PTHREAD_STACK_MIN+10000
|
---|
149 | #endif
|
---|
150 |
|
---|
151 | #define CS_EMMCACHESIZE 64 //nr of EMMs that each client will cache; cache is per client, so memory-expensive...
|
---|
152 |
|
---|
153 | #define D_TRACE 1 // Generate very detailed error/trace messages per routine
|
---|
154 | #define D_ATR 2 // Debug ATR parsing, dump of ecm, cw
|
---|
155 | #define D_READER 4 // Debug Reader/Proxy Process
|
---|
156 | #define D_CLIENT 8 // Debug Client Process
|
---|
157 | #define D_IFD 16 // Debug IFD+protocol
|
---|
158 | #define D_DEVICE 32 // Debug Reader I/O
|
---|
159 | #define D_EMM 64 // Dumps EMM
|
---|
160 | #define D_DVBAPI 128 // Debug DVBAPI
|
---|
161 | #define D_ALL_DUMP 255 // dumps all
|
---|
162 |
|
---|
163 | #define R_DB2COM1 0x1 // Reader Dbox2 @ com1
|
---|
164 | #define R_DB2COM2 0x2 // Reader Dbox2 @ com1
|
---|
165 | #define R_SC8in1 0x3 // Reader Sc8in1 or MCR
|
---|
166 | #define R_MP35 0x4 // AD-Teknik Multiprogrammer 3.5 and 3.6 (only usb tested)
|
---|
167 | #define R_MOUSE 0x5 // Reader smartcard mouse
|
---|
168 | /////////////////// phoenix readers which need baudrate setting and timings need to be guarded by OSCam: BEFORE R_MOUSE
|
---|
169 | #define R_INTERNAL 0x6 // Reader smartcard intern
|
---|
170 | /////////////////// internal readers (Dreambox, Coolstream, IPBox) are all R_INTERNAL, they are determined compile-time
|
---|
171 | /////////////////// readers that do not reed baudrate setting and timings are guarded by reader itself (large buffer built in): AFTER R_SMART
|
---|
172 | #define R_SMART 0x7 // Smartreader+
|
---|
173 | #define R_PCSC 0x8 // PCSC
|
---|
174 | /////////////////// proxy readers after R_CS378X
|
---|
175 | #define R_CAMD35 0x20 // Reader cascading camd 3.5x
|
---|
176 | #define R_CAMD33 0x21 // Reader cascading camd 3.3x
|
---|
177 | #define R_NEWCAMD 0x22 // Reader cascading newcamd
|
---|
178 | #define R_RADEGAST 0x23 // Reader cascading radegast
|
---|
179 | #define R_CS378X 0x24 // Reader cascading camd 3.5x TCP
|
---|
180 | #define R_CONSTCW 0x25 // Reader for Constant CW
|
---|
181 | /////////////////// peer to peer proxy readers after R_CCCAM
|
---|
182 | #define R_GBOX 0x30 // Reader cascading gbox
|
---|
183 | #define R_CCCAM 0x35 // Reader cascading cccam
|
---|
184 | #define R_SERIAL 0x80 // Reader serial
|
---|
185 | #define R_IS_NETWORK 0x60
|
---|
186 | #define R_IS_CASCADING 0xE0
|
---|
187 |
|
---|
188 | //ECM rc codes, reader only:
|
---|
189 | #define E_RDR_NOTFOUND 0
|
---|
190 | #define E_RDR_FOUND 1
|
---|
191 | //ECM rc codes:
|
---|
192 | #define E_FOUND 0
|
---|
193 | #define E_CACHE1 1
|
---|
194 | #define E_CACHE2 2
|
---|
195 | #define E_EMU 3
|
---|
196 | ///////above is all found
|
---|
197 | #define E_NOTFOUND 4 //for selection of found, use < E_NOTFOUND
|
---|
198 | #define E_TIMEOUT 5
|
---|
199 | #define E_SLEEPING 6
|
---|
200 | #define E_FAKE 7
|
---|
201 | #define E_INVALID 8
|
---|
202 | #define E_CORRUPT 9
|
---|
203 | #define E_NOCARD 10
|
---|
204 | #define E_EXPDATE 11
|
---|
205 | #define E_DISABLED 12
|
---|
206 | #define E_STOPPED 13 //for selection of error, use <= E_STOPPED and exclude selection of found
|
---|
207 | ///////above is all notfound, some error or problem
|
---|
208 | #define E_99 99 //this code is undocumented
|
---|
209 | #define E_UNHANDLED 100 //for selection of unhandled, use >= E_UNHANDLED
|
---|
210 |
|
---|
211 | #define CS_MAX_MOD 20
|
---|
212 | #define MOD_CONN_TCP 1
|
---|
213 | #define MOD_CONN_UDP 2
|
---|
214 | #define MOD_CONN_NET 3
|
---|
215 | #define MOD_CONN_SERIAL 4
|
---|
216 | #define MOD_NO_CONN 8
|
---|
217 |
|
---|
218 | #define MOD_CARDSYSTEM 16
|
---|
219 | #define MOD_ADDON 32
|
---|
220 |
|
---|
221 |
|
---|
222 | #ifdef HAVE_DVBAPI
|
---|
223 | #define BOXTYPE_DREAMBOX 1
|
---|
224 | #define BOXTYPE_DUCKBOX 2
|
---|
225 | #define BOXTYPE_UFS910 3
|
---|
226 | #define BOXTYPE_DBOX2 4
|
---|
227 | #define BOXTYPE_IPBOX 5
|
---|
228 | #define BOXTYPE_IPBOX_PMT 6
|
---|
229 | #define BOXTYPE_DM7000 7
|
---|
230 | #define BOXTYPE_QBOXHD 8
|
---|
231 | #define BOXTYPE_COOLSTREAM 9
|
---|
232 | #define BOXTYPE_NEUMO 10
|
---|
233 | #define BOXTYPES 10
|
---|
234 | extern const char *boxdesc[];
|
---|
235 | #endif
|
---|
236 |
|
---|
237 | #define EMM_UNIQUE 1
|
---|
238 | #define EMM_SHARED 2
|
---|
239 | #define EMM_GLOBAL 4
|
---|
240 | #define EMM_UNKNOWN 8
|
---|
241 |
|
---|
242 | #ifdef CS_CORE
|
---|
243 | char *PIP_ID_TXT[] = { "ECM", "EMM", "CIN", "KCL", "UDP", NULL };
|
---|
244 | char *RDR_CD_TXT[] = { "cd", "dsr", "cts", "ring", "none",
|
---|
245 | #ifdef USE_GPIO
|
---|
246 | "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", //felix: changed so that gpio can be used
|
---|
247 | #endif
|
---|
248 | NULL };
|
---|
249 | #else
|
---|
250 | extern char *PIP_ID_TXT[];
|
---|
251 | extern char *RDR_CD_TXT[];
|
---|
252 | #endif
|
---|
253 |
|
---|
254 | #define PIP_ID_ECM 0
|
---|
255 | #define PIP_ID_EMM 1
|
---|
256 | #define PIP_ID_CIN 2 // CARD_INFO
|
---|
257 | #define PIP_ID_KCL 3 // Schlocke: Kill all Clients (no param)
|
---|
258 | #define PIP_ID_UDP 4
|
---|
259 | #define PIP_ID_MAX PIP_ID_UDP
|
---|
260 |
|
---|
261 |
|
---|
262 | #define PIP_ID_ERR (-1)
|
---|
263 | #define PIP_ID_DIR (-2)
|
---|
264 | #define PIP_ID_NUL (-3)
|
---|
265 |
|
---|
266 | #define cdiff *c_start
|
---|
267 |
|
---|
268 | #define NCD_AUTO 0
|
---|
269 | #define NCD_524 1
|
---|
270 | #define NCD_525 2
|
---|
271 |
|
---|
272 | // moved from reader-common.h
|
---|
273 | #define UNKNOWN 0
|
---|
274 | #define CARD_NEED_INIT 1
|
---|
275 | #define CARD_INSERTED 2
|
---|
276 | #define CARD_FAILURE 3
|
---|
277 | #define NO_CARD 4
|
---|
278 |
|
---|
279 | // moved from stats
|
---|
280 | #define DEFAULT_REOPEN_SECONDS 900
|
---|
281 | #define DEFAULT_MIN_ECM_COUNT 5
|
---|
282 | #define DEFAULT_MAX_ECM_COUNT 500
|
---|
283 | #define DEFAULT_NBEST 1
|
---|
284 | #define DEFAULT_NFB 1
|
---|
285 | #define DEFAULT_RETRYLIMIT 800
|
---|
286 | #define DEFAULT_LB_MODE 0
|
---|
287 | #define DEFAULT_LB_STAT_CLEANUP 336
|
---|
288 | #define DEFAULT_LB_USE_LOCKING 0
|
---|
289 | #define DEFAULT_LB_REOPEN_MODE 0
|
---|
290 | #define DEFAULT_UPDATEINTERVAL 240
|
---|
291 | #define DEFAULT_LB_AUTO_BETATUNNEL 1
|
---|
292 |
|
---|
293 | enum {E1_GLOBAL=0, E1_USER, E1_READER, E1_SERVER, E1_LSERVER};
|
---|
294 | enum {E2_GLOBAL=0, E2_GROUP, E2_CAID, E2_IDENT, E2_CLASS, E2_CHID, E2_QUEUE,
|
---|
295 | E2_EA_LEN, E2_F0_LEN, E2_OFFLINE, E2_SID,
|
---|
296 | E2_CCCAM_NOCARD=0x27, E2_CCCAM_NOK1=0x28, E2_CCCAM_NOK2=0x29, E2_CCCAM_LOOP=0x30};
|
---|
297 |
|
---|
298 | pid_t server_pid; //alno: PID of server - set while startup
|
---|
299 |
|
---|
300 | // constants
|
---|
301 | #define CTA_RES_LEN 512
|
---|
302 |
|
---|
303 | #ifdef CS_LED
|
---|
304 | #define LED1A 0
|
---|
305 | #define LED1B 1
|
---|
306 | #define LED2 2
|
---|
307 | #define LED3 3
|
---|
308 | #define LED_OFF 0
|
---|
309 | #define LED_ON 1
|
---|
310 | #define LED_BLINK_ON 2
|
---|
311 | #define LED_BLINK_OFF 3
|
---|
312 | #define LED_DEFAULT 10
|
---|
313 | extern void cs_switch_led(int32_t led, int32_t action);
|
---|
314 | #endif
|
---|
315 |
|
---|
316 | #ifdef QBOXHD_LED
|
---|
317 | typedef struct {
|
---|
318 | uint16_t H; // range 0-359
|
---|
319 | unsigned char S; // range 0-99
|
---|
320 | unsigned char V; // range 0-99
|
---|
321 | } qboxhd_led_color_struct;
|
---|
322 | typedef struct {
|
---|
323 | unsigned char red; // first 5 bit used (&0x1F)
|
---|
324 | unsigned char green; // first 5 bit used (&0x1F)
|
---|
325 | unsigned char blue; // first 5 bit used (&0x1F)
|
---|
326 | } qboxhdmini_led_color_struct;
|
---|
327 |
|
---|
328 | extern void qboxhd_led_blink(int32_t color, int32_t duration);
|
---|
329 |
|
---|
330 | #define QBOXHD_LED_DEVICE "/dev/sw0"
|
---|
331 | #define QBOXHD_SET_LED_ALL_PANEL_COLOR _IO(0xBC, 13) // payload = 3byte [H][S][V]
|
---|
332 | #define QBOXHD_LED_COLOR_RED 359 // only H value, S and V values are always == 99
|
---|
333 | #define QBOXHD_LED_COLOR_GREEN 120
|
---|
334 | #define QBOXHD_LED_COLOR_BLUE 230
|
---|
335 | #define QBOXHD_LED_COLOR_YELLOW 55
|
---|
336 | #define QBOXHD_LED_COLOR_MAGENTA 290
|
---|
337 |
|
---|
338 | #define QBOXHDMINI_LED_DEVICE "/dev/lpc_0"
|
---|
339 | #define QBOXHDMINI_IOSET_RGB _IOWR('L', 6, qboxhdmini_led_color_struct)
|
---|
340 | #define QBOXHDMINI_LED_COLOR_RED 0x1F0000 // 3 bytes RGB , 5 bit used for each color
|
---|
341 | #define QBOXHDMINI_LED_COLOR_GREEN 0x001F00
|
---|
342 | #define QBOXHDMINI_LED_COLOR_BLUE 0x00001F
|
---|
343 | #define QBOXHDMINI_LED_COLOR_YELLOW 0x1F1F00
|
---|
344 | #define QBOXHDMINI_LED_COLOR_MAGENTA 0x1F001F
|
---|
345 |
|
---|
346 | #define QBOXHD_LED_COLOR_OFF -1 // all colors H,S,V and/or R,G,B == 0,0,0
|
---|
347 |
|
---|
348 | #define QBOXHD_LED_BLINK_FAST 100 // blink milliseconds
|
---|
349 | #define QBOXHD_LED_BLINK_MEDIUM 200
|
---|
350 | #define QBOXHD_LED_BLINK_SLOW 400
|
---|
351 |
|
---|
352 | #endif //QBOXHD_LED
|
---|
353 |
|
---|
354 | #define MAX_ATR_LEN 33 // max. ATR length
|
---|
355 | #define MAX_HIST 15 // max. number of historical characters
|
---|
356 |
|
---|
357 | #define MAX_SIDBITS 64 // max services
|
---|
358 | #define SIDTABBITS uint64_t // 64bit type for services, if a system does not support this type,
|
---|
359 | // please use a define and define it as uint32_t / MAX_SIDBITS 32
|
---|
360 |
|
---|
361 | #define BAN_UNKNOWN 1 //failban mask for anonymous/ unknown contact
|
---|
362 | #define BAN_DISABLED 2 //failban mask for disabled user
|
---|
363 | #define BAN_SLEEPING 4 //failban mask for sleeping user
|
---|
364 | #define BAN_DUPLICATE 8 //failban mask for duplicate user
|
---|
365 |
|
---|
366 | //checking if (X) free(X) unneccessary since freeing a null pointer doesnt do anything
|
---|
367 | #define NULLFREE(X) {if (X) {void *tmpX=X; X=NULL; free(tmpX); }}
|
---|
368 |
|
---|
369 | typedef struct s_caidvaluetab
|
---|
370 | {
|
---|
371 | uint16_t n;
|
---|
372 | uint16_t caid[CS_MAX_CAIDVALUETAB];
|
---|
373 | uint16_t value[CS_MAX_CAIDVALUETAB];
|
---|
374 | } CAIDVALUETAB;
|
---|
375 |
|
---|
376 | typedef struct s_classtab
|
---|
377 | {
|
---|
378 | uchar an;
|
---|
379 | uchar bn;
|
---|
380 | uchar aclass[31];
|
---|
381 | uchar bclass[31];
|
---|
382 | } CLASSTAB;
|
---|
383 |
|
---|
384 | typedef struct s_caidtab
|
---|
385 | {
|
---|
386 | uint16_t caid[CS_MAXCAIDTAB];
|
---|
387 | uint16_t mask[CS_MAXCAIDTAB];
|
---|
388 | uint16_t cmap[CS_MAXCAIDTAB];
|
---|
389 | } CAIDTAB;
|
---|
390 |
|
---|
391 | typedef struct s_tuntab
|
---|
392 | {
|
---|
393 | uint16_t n;
|
---|
394 | uint16_t bt_caidfrom[CS_MAXTUNTAB];
|
---|
395 | uint16_t bt_caidto[CS_MAXTUNTAB];
|
---|
396 | uint16_t bt_srvid[CS_MAXTUNTAB];
|
---|
397 | } TUNTAB;
|
---|
398 |
|
---|
399 | typedef struct s_sidtab
|
---|
400 | {
|
---|
401 | char label[64];
|
---|
402 | uint16_t num_caid;
|
---|
403 | uint16_t num_provid;
|
---|
404 | uint16_t num_srvid;
|
---|
405 | uint16_t *caid;
|
---|
406 | uint32_t *provid;
|
---|
407 | uint16_t *srvid;
|
---|
408 | struct s_sidtab *next;
|
---|
409 | } SIDTAB;
|
---|
410 |
|
---|
411 |
|
---|
412 | typedef struct s_filter
|
---|
413 | {
|
---|
414 | uint16_t caid;
|
---|
415 | uchar nprids;
|
---|
416 | uint32_t prids[CS_MAXPROV];
|
---|
417 | } FILTER;
|
---|
418 |
|
---|
419 | typedef struct s_ftab
|
---|
420 | {
|
---|
421 | int32_t nfilts;
|
---|
422 | FILTER filts[CS_MAXFILTERS];
|
---|
423 | } FTAB;
|
---|
424 |
|
---|
425 | typedef struct s_port
|
---|
426 | {
|
---|
427 | int32_t fd;
|
---|
428 | int32_t s_port;
|
---|
429 | int32_t ncd_key_is_set; //0 or 1
|
---|
430 | uchar ncd_key[16];
|
---|
431 | FTAB ftab;
|
---|
432 | } PORT;
|
---|
433 |
|
---|
434 | typedef struct s_ptab
|
---|
435 | {
|
---|
436 | int32_t nports;
|
---|
437 | PORT ports[CS_MAXPORTS];
|
---|
438 | } PTAB;
|
---|
439 |
|
---|
440 | typedef struct aes_entry {
|
---|
441 | uint16_t keyid;
|
---|
442 | uint16_t caid;
|
---|
443 | uint32_t ident;
|
---|
444 | uchar plainkey[16];
|
---|
445 | AES_KEY key;
|
---|
446 | struct aes_entry *next;
|
---|
447 | } AES_ENTRY;
|
---|
448 |
|
---|
449 | struct s_ecm
|
---|
450 | {
|
---|
451 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
452 | uchar cw[16];
|
---|
453 | uint16_t caid;
|
---|
454 | uint64_t grp;
|
---|
455 | struct s_reader *reader;
|
---|
456 | int32_t rc;
|
---|
457 | time_t time;
|
---|
458 | };
|
---|
459 |
|
---|
460 | struct s_emm
|
---|
461 | {
|
---|
462 | uchar emmd5[CS_EMMSTORESIZE];
|
---|
463 | uchar type;
|
---|
464 | int32_t count;
|
---|
465 | };
|
---|
466 |
|
---|
467 | // failban listmember
|
---|
468 | typedef struct v_ban {
|
---|
469 | int32_t v_count;
|
---|
470 | uint32_t v_ip;
|
---|
471 | time_t v_time;
|
---|
472 | } V_BAN;
|
---|
473 |
|
---|
474 | #define AVAIL_CHECK_CONNECTED 0
|
---|
475 | #define AVAIL_CHECK_LOADBALANCE 1
|
---|
476 |
|
---|
477 | struct s_client ;
|
---|
478 | struct ecm_request_t ;
|
---|
479 | struct emm_packet_t ;
|
---|
480 |
|
---|
481 | struct s_module
|
---|
482 | {
|
---|
483 | int8_t active;
|
---|
484 | int8_t multi;
|
---|
485 | int8_t type;
|
---|
486 | int8_t watchdog;
|
---|
487 | char desc[16];
|
---|
488 | char *logtxt;
|
---|
489 | //int32_t s_port;
|
---|
490 | in_addr_t s_ip;
|
---|
491 | void *(*s_handler)();
|
---|
492 | int32_t (*recv)(struct s_client *, uchar *, int32_t);
|
---|
493 | void (*send_dcw)(struct s_client*, struct ecm_request_t *);
|
---|
494 | void (*cleanup)(struct s_client*);
|
---|
495 | int8_t c_multi;
|
---|
496 | int32_t (*c_recv_chk)(struct s_client*, uchar *, int32_t *, uchar *, int32_t);
|
---|
497 | int32_t (*c_init)(struct s_client*);
|
---|
498 | int32_t (*c_send_ecm)(struct s_client *, struct ecm_request_t *, uchar *);
|
---|
499 | int32_t (*c_send_emm)(struct emm_packet_t *);
|
---|
500 | int32_t (*c_init_log)(void);
|
---|
501 | int32_t (*c_recv_log)(uint16_t *, uint32_t *, uint16_t *);
|
---|
502 | int32_t (*c_available)(struct s_reader *, int32_t); //Schlocke: available check for load-balancing,
|
---|
503 | //params:
|
---|
504 | //rdr (reader to check)
|
---|
505 | //int32_t checktype (0=return connected, 1=return loadbalance-avail) return int
|
---|
506 | void (*c_idle)(void); //Schlocke: called when reader is idle
|
---|
507 | void (*c_card_info)(void); //Schlocke: request card infos
|
---|
508 | int32_t c_port;
|
---|
509 | PTAB *ptab;
|
---|
510 | int32_t num;
|
---|
511 | };
|
---|
512 |
|
---|
513 | struct s_ATR ;
|
---|
514 |
|
---|
515 | struct s_cardreader
|
---|
516 | {
|
---|
517 | int8_t active;
|
---|
518 | char desc[16];
|
---|
519 | int32_t (*reader_init)(struct s_reader*);
|
---|
520 | int32_t (*get_status)(struct s_reader*, int*);
|
---|
521 | int32_t (*activate)(struct s_reader*, struct s_ATR *);
|
---|
522 | int32_t (*transmit)(struct s_reader*, unsigned char *sent, uint32_t size);
|
---|
523 | int32_t (*receive)(struct s_reader*, unsigned char *data, uint32_t size);
|
---|
524 | int32_t (*close)(struct s_reader*);
|
---|
525 | int32_t (*set_parity)(struct s_reader*, uchar parity);
|
---|
526 | int32_t (*write_settings)(struct s_reader*, uint32_t ETU, uint32_t EGT, unsigned char P, unsigned char I, uint16_t Fi, unsigned char Di, unsigned char Ni);
|
---|
527 | int32_t (*set_protocol)(struct s_reader*, unsigned char * params, uint32_t *length, uint32_t len_request);
|
---|
528 | int32_t (*set_baudrate)(struct s_reader*, uint32_t baud); //set only for readers which need baudrate setting and timings need to be guarded by OSCam
|
---|
529 | int32_t typ; //fixme: workaround, remove when all old code is converted
|
---|
530 |
|
---|
531 | int8_t max_clock_speed; // 1 for reader->typ > R_MOUSE
|
---|
532 | int8_t need_inverse; //0 = reader does inversing; 1 = inversing done by oscam
|
---|
533 | //io_serial config
|
---|
534 | int8_t flush;
|
---|
535 | int8_t read_written; // 1 = written bytes has to read from device
|
---|
536 | };
|
---|
537 |
|
---|
538 | struct s_cardsystem
|
---|
539 | {
|
---|
540 | int8_t active;
|
---|
541 | char *desc;
|
---|
542 | int32_t (*card_init)();
|
---|
543 | int32_t (*card_info)();
|
---|
544 | int32_t (*do_ecm)();
|
---|
545 | int32_t (*do_emm)();
|
---|
546 | void (*post_process)();
|
---|
547 | int32_t (*get_emm_type)();
|
---|
548 | void (*get_emm_filter)();
|
---|
549 | uchar caids[2];
|
---|
550 | };
|
---|
551 |
|
---|
552 | #ifdef IRDETO_GUESSING
|
---|
553 | struct s_irdeto_quess
|
---|
554 | {
|
---|
555 | int32_t b47;
|
---|
556 | uint16_t caid;
|
---|
557 | uint16_t sid;
|
---|
558 | struct s_irdeto_quess *next;
|
---|
559 | };
|
---|
560 | #endif
|
---|
561 |
|
---|
562 | #define MSGLOGSIZE 64
|
---|
563 | typedef struct ecm_request_t
|
---|
564 | {
|
---|
565 | uchar ecm[256];
|
---|
566 | uchar cw[16];
|
---|
567 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
568 | // uchar l;
|
---|
569 | int16_t l;
|
---|
570 | uint16_t caid;
|
---|
571 | uint16_t ocaid; //original caid, used for betatunneling
|
---|
572 | uint16_t srvid;
|
---|
573 | uint16_t chid;
|
---|
574 | uint16_t pid;
|
---|
575 | uint16_t idx;
|
---|
576 | uint32_t prid;
|
---|
577 | struct s_reader *selected_reader;
|
---|
578 | LLIST *matching_rdr; //list of matching readers
|
---|
579 | LL_NODE *fallback; // in *matching_rdr, at position "fallback" the first fallback reader is in the list
|
---|
580 | struct s_client *client; //contains pointer to 'c' client while running in 'r' client
|
---|
581 | int32_t cpti; // client pending table index
|
---|
582 | int32_t stage; // processing stage in server module
|
---|
583 | int32_t level; // send-level in client module
|
---|
584 | int32_t rc;
|
---|
585 | uchar rcEx;
|
---|
586 | struct timeb tps; // incoming time stamp
|
---|
587 | uchar locals_done;
|
---|
588 | int32_t btun; // mark er as betatunneled
|
---|
589 | int32_t reader_avail; //count of available readers
|
---|
590 | int32_t reader_count; //count of contacted readers
|
---|
591 | #ifdef CS_WITH_DOUBLECHECK
|
---|
592 | int32_t checked;
|
---|
593 | uchar cw_checked[16];
|
---|
594 | #endif
|
---|
595 |
|
---|
596 | #ifdef MODULE_CCCAM
|
---|
597 | struct s_reader *origin_reader;
|
---|
598 | void * origin_card; //CCcam preferred card!
|
---|
599 | #endif
|
---|
600 |
|
---|
601 | void *src_data;
|
---|
602 |
|
---|
603 | struct s_ecm *ecmcacheptr; //Pointer to ecm-cw-rc-cache!
|
---|
604 |
|
---|
605 | char msglog[MSGLOGSIZE];
|
---|
606 | } ECM_REQUEST;
|
---|
607 |
|
---|
608 | #ifdef CS_ANTICASC
|
---|
609 | struct s_acasc_shm {
|
---|
610 | uint16_t ac_count : 15;
|
---|
611 | uint16_t ac_deny : 1;
|
---|
612 | };
|
---|
613 |
|
---|
614 | struct s_acasc {
|
---|
615 | uint16_t stat[10];
|
---|
616 | uchar idx; // current active index in stat[]
|
---|
617 | };
|
---|
618 | #endif
|
---|
619 |
|
---|
620 | struct s_client
|
---|
621 | {
|
---|
622 | in_addr_t ip;
|
---|
623 | in_port_t port;
|
---|
624 | time_t login;
|
---|
625 | time_t last;
|
---|
626 | time_t lastswitch;
|
---|
627 | time_t lastemm;
|
---|
628 | time_t lastecm;
|
---|
629 | time_t expirationdate;
|
---|
630 | int32_t allowedtimeframe[2];
|
---|
631 | int8_t c35_suppresscmd08;
|
---|
632 | uint8_t c35_sleepsend;
|
---|
633 | int8_t ncd_keepalive;
|
---|
634 | int8_t disabled;
|
---|
635 | uint64_t grp;
|
---|
636 | int8_t crypted;
|
---|
637 | int8_t dup;
|
---|
638 | LLIST *aureader_list;
|
---|
639 | int8_t autoau;
|
---|
640 | int8_t monlvl;
|
---|
641 | CAIDTAB ctab;
|
---|
642 | TUNTAB ttab;
|
---|
643 | SIDTABBITS sidtabok; // positiv services
|
---|
644 | SIDTABBITS sidtabno; // negative services
|
---|
645 | int32_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
|
---|
646 | int32_t ctyp;
|
---|
647 | int32_t stat;
|
---|
648 | int32_t last_srvid;
|
---|
649 | int32_t last_caid;
|
---|
650 | struct s_srvid *last_srvidptr;
|
---|
651 | int32_t tosleep;
|
---|
652 | struct s_auth *account;
|
---|
653 | int32_t udp_fd;
|
---|
654 | int32_t fd_m2c; //master writes to this fd
|
---|
655 | int32_t fd_m2c_c; //client reads from this fd
|
---|
656 | struct sockaddr_in udp_sa;
|
---|
657 | int32_t log;
|
---|
658 | int32_t logcounter;
|
---|
659 | int32_t cwfound; // count found ECMs per client
|
---|
660 | int32_t cwcache; // count ECMs from cache1/2 per client
|
---|
661 | int32_t cwnot; // count not found ECMs per client
|
---|
662 | int32_t cwtun; // count betatunneled ECMs per client
|
---|
663 | int32_t cwignored; // count ignored ECMs per client
|
---|
664 | int32_t cwtout; // count timeouted ECMs per client
|
---|
665 | int32_t cwlastresptime; //last Responsetime (ms)
|
---|
666 | int32_t cwlastresptimes[CS_ECM_RINGBUFFER_MAX]; //ringbuffer for last 20 times
|
---|
667 | int32_t cwlastresptimes_last; // ringbuffer pointer
|
---|
668 | int32_t emmok; // count EMM ok
|
---|
669 | int32_t emmnok; // count EMM nok
|
---|
670 | int32_t pending; // number of ECMs pending
|
---|
671 | #ifdef WEBIF
|
---|
672 | int8_t wihidden; // hidden in webinterface status
|
---|
673 | char lastreader[64]; // last cw got from this reader
|
---|
674 | #endif
|
---|
675 | uchar ucrc[4]; // needed by monitor and used by camd35
|
---|
676 | uint32_t pcrc; // pwd crc
|
---|
677 | AES_KEY aeskey; // encryption key needed by monitor and used by camd33, camd35
|
---|
678 | AES_KEY aeskey_decrypt; // decryption key needed by monitor and used by camd33, camd35
|
---|
679 | uint16_t ncd_msgid;
|
---|
680 | char ncd_client_id[5];
|
---|
681 | uchar ncd_skey[16];
|
---|
682 |
|
---|
683 | #ifdef MODULE_CCCAM
|
---|
684 | void *cc;
|
---|
685 | #endif
|
---|
686 | #ifdef MODULE_GBOX
|
---|
687 | void *gbox;
|
---|
688 | #endif
|
---|
689 | int32_t port_idx; // index in server ptab
|
---|
690 | int32_t ncd_server; // newcamd server
|
---|
691 | #ifdef CS_ANTICASC
|
---|
692 | uint16_t ac_limit;
|
---|
693 | struct s_acasc_shm acasc;
|
---|
694 | #endif
|
---|
695 | FTAB fchid;
|
---|
696 | FTAB ftab; // user [caid] and ident filter
|
---|
697 | CLASSTAB cltab;
|
---|
698 |
|
---|
699 |
|
---|
700 | int32_t pfd; // Primary FD, must be closed on exit
|
---|
701 | struct s_reader *reader; //points to s_reader when cl->typ='r'
|
---|
702 |
|
---|
703 | ECM_REQUEST *ecmtask;
|
---|
704 | struct s_emm *emmcache;
|
---|
705 |
|
---|
706 | pthread_t thread;
|
---|
707 | pthread_mutex_t **mutexstore;
|
---|
708 | uint16_t mutexstore_alloc;
|
---|
709 | uint16_t mutexstore_used;
|
---|
710 |
|
---|
711 | struct s_serial_client *serialdata;
|
---|
712 |
|
---|
713 | //reader common
|
---|
714 | int32_t last_idx;
|
---|
715 | uint16_t idx;
|
---|
716 | int32_t rotate;
|
---|
717 |
|
---|
718 | uchar *req;
|
---|
719 |
|
---|
720 | int32_t ncd_proto;
|
---|
721 |
|
---|
722 | //camd35
|
---|
723 | uchar upwd[64];
|
---|
724 | int8_t is_udp;
|
---|
725 | int8_t stopped;
|
---|
726 | int32_t lastcaid;
|
---|
727 | int32_t lastsrvid;
|
---|
728 | int32_t lastpid;
|
---|
729 | time_t emm_last;
|
---|
730 | int8_t disable_counter;
|
---|
731 | uchar lastserial[8];
|
---|
732 |
|
---|
733 | //monitor
|
---|
734 | int32_t auth;
|
---|
735 |
|
---|
736 | //cs_hexdump buffer
|
---|
737 | uchar dump[520];
|
---|
738 |
|
---|
739 | //oscam.c
|
---|
740 | struct timeval tv;
|
---|
741 |
|
---|
742 | //failban value set bitwise - compared with BAN_
|
---|
743 | int32_t failban;
|
---|
744 | int8_t cleaned;
|
---|
745 | struct s_client *next; //make client a linked list
|
---|
746 | };
|
---|
747 |
|
---|
748 |
|
---|
749 | //for viaccess var in s_reader:
|
---|
750 | struct geo_cache
|
---|
751 | {
|
---|
752 | uint32_t provid;
|
---|
753 | uchar geo[256];
|
---|
754 | uchar geo_len;
|
---|
755 | int32_t number_ecm;
|
---|
756 | };
|
---|
757 | // for videoguard in s_reader
|
---|
758 | struct s_CmdTabEntry {
|
---|
759 | unsigned char cla;
|
---|
760 | unsigned char cmd;
|
---|
761 | unsigned char len;
|
---|
762 | unsigned char mode;
|
---|
763 | };
|
---|
764 |
|
---|
765 | struct s_CmdTab {
|
---|
766 | unsigned char index;
|
---|
767 | unsigned char size;
|
---|
768 | unsigned char Nentries;
|
---|
769 | unsigned char dummy;
|
---|
770 | struct s_CmdTabEntry e[1];
|
---|
771 | };
|
---|
772 |
|
---|
773 | struct s_ecmWhitelist {
|
---|
774 | int16_t caid;
|
---|
775 | struct s_ecmWhitelistIdent *idents;
|
---|
776 | struct s_ecmWhitelist *next;
|
---|
777 | };
|
---|
778 |
|
---|
779 | struct s_ecmWhitelistIdent {
|
---|
780 | uint32_t ident;
|
---|
781 | struct s_ecmWhitelistLen *lengths;
|
---|
782 | struct s_ecmWhitelistIdent *next;
|
---|
783 | };
|
---|
784 |
|
---|
785 | struct s_ecmWhitelistLen {
|
---|
786 | int16_t len;
|
---|
787 | struct s_ecmWhitelistLen *next;
|
---|
788 | };
|
---|
789 |
|
---|
790 | //ratelimit
|
---|
791 | struct ecmrl {
|
---|
792 | uint16_t srvid;
|
---|
793 | time_t last;
|
---|
794 | };
|
---|
795 | #define MAXECMRATELIMIT 20
|
---|
796 |
|
---|
797 | struct s_reader //contains device info, reader info and card info
|
---|
798 | {
|
---|
799 | uint32_t auprovid; // AU only for this provid
|
---|
800 | int8_t audisabled; // exclude reader from auto AU
|
---|
801 | int8_t smargopatch;
|
---|
802 | struct s_client * client; //pointer to 'r'client this reader is running in
|
---|
803 | int8_t enable;
|
---|
804 | int8_t available; //Schlocke: New flag for loadbalancing. Only reader if reader supports ph.c_available function
|
---|
805 | int32_t fd_error;
|
---|
806 | int32_t fd;
|
---|
807 | uint64_t grp;
|
---|
808 | int32_t fallback;
|
---|
809 | int32_t typ;
|
---|
810 | char label[64];
|
---|
811 | char device[128];
|
---|
812 | void *spec_dev; //pointer to structure that contains specific device data
|
---|
813 | uint16_t slot; //in case of multiple slots like sc8in1; first slot = 1
|
---|
814 | int32_t handle; //device handle
|
---|
815 | int32_t fdmc; //device handle for multicam
|
---|
816 | #ifdef WITH_STAPI
|
---|
817 | uint32_t stsmart_handle; //device handle for stsmart driver
|
---|
818 | #endif
|
---|
819 | char pcsc_name[128];
|
---|
820 | int8_t pcsc_has_card;
|
---|
821 | int32_t detect;
|
---|
822 | int32_t mhz; //actual clock rate of reader in 10khz steps
|
---|
823 | int32_t cardmhz; //standard clock speed your card should have in 10khz steps; normally 357 but for Irdeto cards 600
|
---|
824 | int32_t r_port;
|
---|
825 | char r_usr[64];
|
---|
826 | char r_pwd[64];
|
---|
827 | char l_pwd[64];
|
---|
828 | int32_t l_port;
|
---|
829 | int32_t log_port;
|
---|
830 | CAIDTAB ctab;
|
---|
831 | uint32_t boxid;
|
---|
832 | int8_t nagra_read; // read nagra ncmed records: 0 disabled (default), 1 read all records, 2 read valid records only
|
---|
833 | uchar nagra_boxkey[16]; //n3 boxkey 8byte or tiger idea key 16byte
|
---|
834 | char country_code[3]; // irdeto country code.
|
---|
835 | int8_t force_irdeto;
|
---|
836 | uchar rsa_mod[120]; //rsa modulus for nagra cards.
|
---|
837 | uchar atr[64];
|
---|
838 | int32_t atrlen;
|
---|
839 | SIDTABBITS sidtabok; // positiv services
|
---|
840 | SIDTABBITS sidtabno; // negative services
|
---|
841 | uchar hexserial[8];
|
---|
842 | int32_t nprov;
|
---|
843 | uchar prid[CS_MAXPROV][8];
|
---|
844 | uchar availkeys[CS_MAXPROV][16]; // viaccess; misused in seca, if availkeys[PROV][0]=0 then expired, 1 then valid.
|
---|
845 | uchar sa[CS_MAXPROV][4]; // viaccess & seca
|
---|
846 | uint16_t acs; // irdeto
|
---|
847 | uint16_t caid;
|
---|
848 | uint16_t b_nano;
|
---|
849 | uint16_t s_nano;
|
---|
850 | int32_t blockemm;
|
---|
851 | char * emmfile;
|
---|
852 | char pincode[5];
|
---|
853 | int32_t ucpk_valid;
|
---|
854 | int32_t logemm;
|
---|
855 | int32_t cachemm;
|
---|
856 | int32_t rewritemm;
|
---|
857 | int8_t card_status;
|
---|
858 | int8_t deprecated; //if 0 ATR obeyed, if 1 default speed (9600) is chosen; for devices that cannot switch baudrate
|
---|
859 | struct s_module ph;
|
---|
860 | struct s_cardreader crdr;
|
---|
861 | struct s_cardsystem csystem;
|
---|
862 | uchar ncd_key[16];
|
---|
863 | uchar ncd_skey[16];
|
---|
864 | int8_t ncd_disable_server_filt;
|
---|
865 | uint16_t ncd_msgid;
|
---|
866 | int32_t ncd_proto;
|
---|
867 | #ifdef MODULE_CCCAM
|
---|
868 | char cc_version[7]; // cccam version
|
---|
869 | char cc_build[7]; // cccam build number
|
---|
870 | int8_t cc_maxhop; // cccam max distance
|
---|
871 | int8_t cc_mindown; // cccam min downhops
|
---|
872 | int8_t cc_currenthops; // number of hops for CCCam
|
---|
873 | int8_t cc_want_emu; //Schlocke: Client want to have EMUs, 0 - NO; 1 - YES
|
---|
874 | uint32_t cc_id;
|
---|
875 | int8_t cc_keepalive;
|
---|
876 | int8_t cc_hop; //For non-cccam reader: hop for virtual cards
|
---|
877 | #endif
|
---|
878 | uchar tcp_connected;
|
---|
879 | int32_t tcp_ito; // inactivity timeout
|
---|
880 | int32_t tcp_rto; // reconnect timeout
|
---|
881 | struct timeb tcp_block_connect_till; //time tcp connect ist blocked
|
---|
882 | int32_t tcp_block_delay; //incrementing block time
|
---|
883 | time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect )
|
---|
884 | time_t last_s; // send
|
---|
885 | uchar show_cls; // number of classes subscription showed on kill -31
|
---|
886 | FTAB fchid;
|
---|
887 | FTAB ftab;
|
---|
888 | CLASSTAB cltab;
|
---|
889 | struct s_ecmWhitelist *ecmWhitelist;
|
---|
890 | char *init_history;
|
---|
891 | int32_t init_history_pos;
|
---|
892 | int32_t brk_pos;
|
---|
893 | int32_t msg_idx;
|
---|
894 | #ifdef WEBIF
|
---|
895 | int32_t emmwritten[4]; //count written EMM
|
---|
896 | int32_t emmskipped[4]; //count skipped EMM
|
---|
897 | int32_t emmerror[4]; //count error EMM
|
---|
898 | int32_t emmblocked[4]; //count blocked EMM
|
---|
899 | int32_t lbvalue; //loadbalance Value
|
---|
900 | #endif
|
---|
901 | #ifdef HAVE_PCSC
|
---|
902 | SCARDCONTEXT hContext;
|
---|
903 | SCARDHANDLE hCard;
|
---|
904 | DWORD dwActiveProtocol;
|
---|
905 | #endif
|
---|
906 | #ifdef LIBUSB
|
---|
907 | uint8_t device_endpoint; // usb endpoint32_t for Infinity USB Smart in smartreader mode.
|
---|
908 | struct s_sr_config *sr_config;
|
---|
909 | #endif
|
---|
910 | #ifdef AZBOX
|
---|
911 | int32_t mode;
|
---|
912 | #endif
|
---|
913 | ////variables from icc_async.h start
|
---|
914 | int32_t convention; //Convention of this ICC
|
---|
915 | unsigned char protocol_type; // Type of protocol
|
---|
916 | uint16_t BWT,CWT; // (for overclocking uncorrected) block waiting time, character waiting time, in ETU
|
---|
917 | uint32_t current_baudrate; // (for overclocking uncorrected) baudrate to prevent unnecessary conversions from/to termios structure
|
---|
918 | uint32_t read_timeout; // Max timeout (ms) to receive characters
|
---|
919 | uint32_t block_delay; // Delay (ms) after starting to transmit
|
---|
920 | uint32_t char_delay; // Delay (ms) after transmiting each sucesive char
|
---|
921 | ////variables from io_serial.h
|
---|
922 | int32_t written; //keep score of how much bytes are written to serial port, since they are echoed back they have to be read
|
---|
923 | ////variables from protocol_t1.h
|
---|
924 | uint16_t ifsc; /* Information field size for the ICC */
|
---|
925 | unsigned char ns; /* Send sequence number */
|
---|
926 | ////variables from reader-dre.c
|
---|
927 | unsigned char provider;
|
---|
928 | ////variables from reader-nagra.c
|
---|
929 | IDEA_KEY_SCHEDULE ksSession;
|
---|
930 | int8_t is_pure_nagra;
|
---|
931 | int8_t is_tiger;
|
---|
932 | int8_t is_n3_na;
|
---|
933 | int8_t has_dt08;
|
---|
934 | int8_t swapCW;
|
---|
935 | uint8_t ExpiryDate[2];
|
---|
936 | uint8_t ActivationDate[2];
|
---|
937 | unsigned char rom[15];
|
---|
938 | unsigned char plainDT08RSA[64];
|
---|
939 | unsigned char IdeaCamKey[16];
|
---|
940 | unsigned char irdId[4];
|
---|
941 | unsigned char sessi[16];
|
---|
942 | unsigned char signature[8];
|
---|
943 | unsigned char cam_state[3];
|
---|
944 | ////variables from reader-irdeto.c
|
---|
945 | int32_t acs57; // A flag for the ACS57 ITA DVB-T
|
---|
946 | ////variables from reader-cryptoworks.c
|
---|
947 | BIGNUM exp;
|
---|
948 | BIGNUM ucpk;
|
---|
949 | ////variables from reader-viaccess.c
|
---|
950 | struct geo_cache last_geo;
|
---|
951 | #ifdef MODULE_CCCAM
|
---|
952 | int32_t cc_reshare;
|
---|
953 | #endif
|
---|
954 | #ifdef WITH_LB
|
---|
955 | int32_t lb_weight; //loadbalance weight factor, if unset, weight=100. The higher the value, the higher the usage-possibility
|
---|
956 | int32_t lb_usagelevel; //usagelevel for loadbalancer
|
---|
957 | int32_t lb_usagelevel_ecmcount;
|
---|
958 | time_t lb_usagelevel_time; //time for counting ecms, this creates usagelevel
|
---|
959 | struct timeb lb_last; //time for oldest reader
|
---|
960 | LLIST *lb_stat; //loadbalancer reader statistics
|
---|
961 | #endif
|
---|
962 | // multi AES linked list
|
---|
963 | AES_ENTRY *aes_list;
|
---|
964 | // variables from reader-videoguard*
|
---|
965 | int8_t ndsversion; // 0 auto (default), 1 NDS1, 12 NDS1+, 2 NDS2
|
---|
966 | const char * card_desc;
|
---|
967 | int32_t card_baseyear;
|
---|
968 | int32_t card_tierstart;
|
---|
969 | int32_t card_system_version;
|
---|
970 | struct s_CmdTab *cmd_table;
|
---|
971 | uint16_t cardkeys[3][32];
|
---|
972 | unsigned char stateD3A[16];
|
---|
973 | AES_KEY ekey;
|
---|
974 | AES_KEY astrokey;
|
---|
975 | //ratelimit
|
---|
976 | int32_t ratelimitecm;
|
---|
977 | int32_t ratelimitseconds;
|
---|
978 | struct ecmrl rlecmh[MAXECMRATELIMIT];
|
---|
979 | int8_t fix_9993;
|
---|
980 | struct s_reader *next;
|
---|
981 | };
|
---|
982 |
|
---|
983 | #ifdef CS_ANTICASC
|
---|
984 | struct s_cpmap
|
---|
985 | {
|
---|
986 | uint16_t caid;
|
---|
987 | uint32_t provid;
|
---|
988 | uint16_t sid;
|
---|
989 | uint16_t chid;
|
---|
990 | uint16_t dwtime;
|
---|
991 | struct s_cpmap *next;
|
---|
992 | };
|
---|
993 | #endif
|
---|
994 |
|
---|
995 | struct s_auth
|
---|
996 | {
|
---|
997 | char usr[64];
|
---|
998 | char pwd[64];
|
---|
999 | #ifdef WEBIF
|
---|
1000 | char description[64];
|
---|
1001 | #endif
|
---|
1002 | int8_t uniq;
|
---|
1003 | LLIST *aureader_list;
|
---|
1004 | int8_t autoau;
|
---|
1005 | int8_t monlvl;
|
---|
1006 | uint64_t grp;
|
---|
1007 | int32_t tosleep;
|
---|
1008 | CAIDTAB ctab;
|
---|
1009 | SIDTABBITS sidtabok; // positiv services
|
---|
1010 | SIDTABBITS sidtabno; // negative services
|
---|
1011 | FTAB fchid;
|
---|
1012 | FTAB ftab; // user [caid] and ident filter
|
---|
1013 | CLASSTAB cltab;
|
---|
1014 | TUNTAB ttab;
|
---|
1015 | #ifdef CS_ANTICASC
|
---|
1016 | int32_t ac_users; // 0 - unlimited
|
---|
1017 | uchar ac_penalty; // 0 - log, >0 - fake dw
|
---|
1018 | struct s_acasc ac_stat;
|
---|
1019 | #endif
|
---|
1020 | in_addr_t dynip;
|
---|
1021 | uchar dyndns[64];
|
---|
1022 | time_t expirationdate;
|
---|
1023 | time_t firstlogin;
|
---|
1024 | int32_t allowedtimeframe[2];
|
---|
1025 | int8_t c35_suppresscmd08;
|
---|
1026 | uint8_t c35_sleepsend;
|
---|
1027 | int8_t ncd_keepalive;
|
---|
1028 | int32_t cccmaxhops;
|
---|
1029 | int32_t cccreshare;
|
---|
1030 | int8_t cccignorereshare;
|
---|
1031 | int8_t cccstealth;
|
---|
1032 | int8_t disabled;
|
---|
1033 | int32_t failban;
|
---|
1034 |
|
---|
1035 | int32_t cwfound;
|
---|
1036 | int32_t cwcache;
|
---|
1037 | int32_t cwnot;
|
---|
1038 | int32_t cwtun;
|
---|
1039 | int32_t cwignored;
|
---|
1040 | int32_t cwtout;
|
---|
1041 | int32_t emmok;
|
---|
1042 | int32_t emmnok;
|
---|
1043 |
|
---|
1044 | struct s_auth *next;
|
---|
1045 | };
|
---|
1046 |
|
---|
1047 | struct s_srvid
|
---|
1048 | {
|
---|
1049 | int32_t srvid;
|
---|
1050 | int32_t ncaid;
|
---|
1051 | int32_t caid[10];
|
---|
1052 | char *data;
|
---|
1053 | char *prov;
|
---|
1054 | char *name;
|
---|
1055 | char *type;
|
---|
1056 | char *desc;
|
---|
1057 | struct s_srvid *next;
|
---|
1058 | };
|
---|
1059 |
|
---|
1060 | struct s_tierid
|
---|
1061 | {
|
---|
1062 | int32_t tierid;
|
---|
1063 | int32_t ncaid;
|
---|
1064 | int32_t caid[10];
|
---|
1065 | char name[33];
|
---|
1066 | struct s_tierid *next;
|
---|
1067 | };
|
---|
1068 |
|
---|
1069 | //Todo #ifdef CCCAM
|
---|
1070 | struct s_provid
|
---|
1071 | {
|
---|
1072 | int32_t caid;
|
---|
1073 | uint32_t provid;
|
---|
1074 | char prov[33];
|
---|
1075 | char sat[33];
|
---|
1076 | char lang[33];
|
---|
1077 | struct s_provid *next;
|
---|
1078 | };
|
---|
1079 |
|
---|
1080 | struct s_ip
|
---|
1081 | {
|
---|
1082 | in_addr_t ip[2];
|
---|
1083 | struct s_ip *next;
|
---|
1084 | };
|
---|
1085 |
|
---|
1086 | struct s_config
|
---|
1087 | {
|
---|
1088 | int32_t nice;
|
---|
1089 | uint32_t netprio;
|
---|
1090 | uint32_t ctimeout;
|
---|
1091 | uint32_t ftimeout;
|
---|
1092 | uint32_t cmaxidle;
|
---|
1093 | int32_t ulparent;
|
---|
1094 | uint32_t delay;
|
---|
1095 | int32_t bindwait;
|
---|
1096 | int32_t tosleep;
|
---|
1097 | in_addr_t srvip;
|
---|
1098 | char *usrfile;
|
---|
1099 | char *cwlogdir;
|
---|
1100 | char *emmlogdir;
|
---|
1101 | char *logfile;
|
---|
1102 | uint8_t logtostdout;
|
---|
1103 | uint8_t logtosyslog;
|
---|
1104 | uint32_t loghistorysize;
|
---|
1105 | int8_t disablelog;
|
---|
1106 | int8_t disableuserfile;
|
---|
1107 | int8_t usrfileflag;
|
---|
1108 | struct s_auth *account;
|
---|
1109 | struct s_srvid *srvid[16];
|
---|
1110 | struct s_tierid *tierid;
|
---|
1111 | //Todo #ifdef CCCAM
|
---|
1112 | struct s_provid *provid;
|
---|
1113 | struct s_sidtab *sidtab;
|
---|
1114 | int32_t mon_port;
|
---|
1115 | in_addr_t mon_srvip;
|
---|
1116 | struct s_ip *mon_allowed;
|
---|
1117 | int32_t mon_aulow;
|
---|
1118 | int32_t mon_hideclient_to;
|
---|
1119 | int32_t mon_level;
|
---|
1120 | int32_t mon_appendchaninfo;
|
---|
1121 | #ifdef WEBIF
|
---|
1122 | int32_t http_port;
|
---|
1123 | char http_user[65];
|
---|
1124 | char http_pwd[65];
|
---|
1125 | char http_css[128];
|
---|
1126 | char http_jscript[128];
|
---|
1127 | char http_tpl[128];
|
---|
1128 | char http_script[128];
|
---|
1129 | int32_t http_refresh;
|
---|
1130 | int8_t http_hide_idle_clients;
|
---|
1131 | struct s_ip *http_allowed;
|
---|
1132 | int8_t http_readonly;
|
---|
1133 | in_addr_t http_dynip;
|
---|
1134 | uchar http_dyndns[64];
|
---|
1135 | int8_t http_use_ssl;
|
---|
1136 | char http_cert[128];
|
---|
1137 | char http_help_lang[3];
|
---|
1138 | #endif
|
---|
1139 | int8_t http_full_cfg;
|
---|
1140 | int32_t failbantime;
|
---|
1141 | int32_t failbancount;
|
---|
1142 | LLIST *v_list; //failban list
|
---|
1143 | int32_t c33_port;
|
---|
1144 | in_addr_t c33_srvip;
|
---|
1145 | uchar c33_key[16];
|
---|
1146 | int32_t c33_crypted;
|
---|
1147 | int32_t c33_passive;
|
---|
1148 | struct s_ip *c33_plain;
|
---|
1149 | int32_t c35_port;
|
---|
1150 | in_addr_t c35_srvip;
|
---|
1151 | int8_t c35_suppresscmd08;
|
---|
1152 | int8_t c35_tcp_suppresscmd08;
|
---|
1153 | int8_t c35_udp_suppresscmd08;
|
---|
1154 | PTAB c35_tcp_ptab;
|
---|
1155 | in_addr_t c35_tcp_srvip;
|
---|
1156 | PTAB ncd_ptab;
|
---|
1157 | in_addr_t ncd_srvip;
|
---|
1158 | uchar ncd_key[16];
|
---|
1159 | int32_t ncd_keepalive;
|
---|
1160 | int8_t ncd_mgclient;
|
---|
1161 | struct s_ip *ncd_allowed;
|
---|
1162 | int32_t rad_port;
|
---|
1163 | in_addr_t rad_srvip;
|
---|
1164 | #ifdef MODULE_CCCAM
|
---|
1165 | PTAB cc_ptab;
|
---|
1166 | uint16_t cc_port[CS_MAXPORTS];
|
---|
1167 | int8_t cc_reshare;
|
---|
1168 | int8_t cc_ignore_reshare;
|
---|
1169 | int32_t cc_update_interval;
|
---|
1170 | in_addr_t cc_srvip;
|
---|
1171 | char cc_version[7];
|
---|
1172 | int8_t cc_minimize_cards;
|
---|
1173 | int8_t cc_keep_connected;
|
---|
1174 | int8_t cc_stealth;
|
---|
1175 | int8_t cc_reshare_services;
|
---|
1176 | int8_t cc_forward_origin_card;
|
---|
1177 | int8_t cc_use_fixed_nodeid;
|
---|
1178 | uint8_t cc_fixed_nodeid[8];
|
---|
1179 | #endif
|
---|
1180 | char gbox_hostname[128];
|
---|
1181 | char gbox_key[9];
|
---|
1182 | char gbox_gsms_path[200];
|
---|
1183 | int32_t gbox_port;
|
---|
1184 | struct s_ip *rad_allowed;
|
---|
1185 | char rad_usr[32];
|
---|
1186 | char ser_device[512];
|
---|
1187 | uint32_t srtimeout; // SerialReaderTimeount in millisec
|
---|
1188 | int32_t max_log_size;
|
---|
1189 | int8_t waitforcards;
|
---|
1190 | int32_t waitforcards_extra_delay;
|
---|
1191 | int8_t preferlocalcards;
|
---|
1192 | int8_t saveinithistory;
|
---|
1193 | int32_t reader_restart_seconds; //schlocke: reader restart auf x seconds, disable = 0
|
---|
1194 | int8_t dropdups; //drop duplicate logins
|
---|
1195 |
|
---|
1196 |
|
---|
1197 | //Loadbalancer-Config:
|
---|
1198 | #ifdef WITH_LB
|
---|
1199 | int32_t lb_mode; //schlocke: reader loadbalancing mode
|
---|
1200 | int32_t lb_save; //schlocke: load/save statistics to file, save every x ecms
|
---|
1201 | int32_t lb_nbest_readers; // count of best readers
|
---|
1202 | int32_t lb_nfb_readers; // count of fallback readers
|
---|
1203 | int32_t lb_min_ecmcount; // minimal ecm count to evaluate lbvalues
|
---|
1204 | int32_t lb_max_ecmcount; // maximum ecm count before reseting lbvalues
|
---|
1205 | int32_t lb_reopen_seconds; //time between retrying failed readers/caids/prov/srv
|
---|
1206 | int32_t lb_retrylimit; //reopen only happens if reader response time > retrylimit
|
---|
1207 | CAIDVALUETAB lb_retrylimittab;
|
---|
1208 | CAIDVALUETAB lb_nbest_readers_tab; //like nbest_readers, but for special caids
|
---|
1209 | CAIDTAB lb_noproviderforcaid; //do not store loadbalancer stats with providers for this caid
|
---|
1210 | char *lb_savepath; //path where the stat file is save. Empty=default=/tmp/.oscam/stat
|
---|
1211 | int32_t lb_stat_cleanup; //duration in hours for cleaning old statistics
|
---|
1212 | int32_t lb_use_locking; //use a mutex lock while searching for readers (get_cw())
|
---|
1213 | int32_t lb_reopen_mode; //reopen readers mode
|
---|
1214 | int32_t lb_max_readers; //limit the amount of readers during learning
|
---|
1215 | int32_t lb_auto_betatunnel; //automatic selection of betatunnel convertion based on learned data
|
---|
1216 | #endif
|
---|
1217 | int32_t resolve_gethostbyname;
|
---|
1218 |
|
---|
1219 | #ifdef CS_WITH_DOUBLECHECK
|
---|
1220 | int8_t double_check; //schlocke: Double checks each ecm+dcw from two (or more) readers
|
---|
1221 | #endif
|
---|
1222 |
|
---|
1223 | #ifdef IRDETO_GUESSING
|
---|
1224 | struct s_irdeto_quess *itab[0xff];
|
---|
1225 | #endif
|
---|
1226 |
|
---|
1227 | #ifdef HAVE_DVBAPI
|
---|
1228 | int8_t dvbapi_enabled;
|
---|
1229 | int8_t dvbapi_au;
|
---|
1230 | char dvbapi_usr[64];
|
---|
1231 | int8_t dvbapi_boxtype;
|
---|
1232 | int8_t dvbapi_pmtmode;
|
---|
1233 | int8_t dvbapi_requestmode;
|
---|
1234 | SIDTABBITS dvbapi_sidtabok; // positiv services
|
---|
1235 | SIDTABBITS dvbapi_sidtabno; // negative services
|
---|
1236 | #endif
|
---|
1237 |
|
---|
1238 | #ifdef CS_ANTICASC
|
---|
1239 | char ac_enabled;
|
---|
1240 | int32_t ac_users; // num of users for account (0 - default)
|
---|
1241 | int32_t ac_stime; // time to collect AC statistics (3 min - default)
|
---|
1242 | int32_t ac_samples; // qty of samples
|
---|
1243 | int32_t ac_penalty; // 0 - write to log
|
---|
1244 | int32_t ac_fakedelay; // 100-1000 ms
|
---|
1245 | int32_t ac_denysamples;
|
---|
1246 | char ac_logfile[128];
|
---|
1247 | struct s_cpmap *cpmap;
|
---|
1248 | #endif
|
---|
1249 |
|
---|
1250 | #ifdef QBOXHD_LED
|
---|
1251 | int8_t disableqboxhdled; // disable qboxhd led , default = 0
|
---|
1252 | #endif
|
---|
1253 | };
|
---|
1254 |
|
---|
1255 | struct s_clientinit
|
---|
1256 | {
|
---|
1257 | void *(*handler)(struct s_client*);
|
---|
1258 | struct s_client * client;
|
---|
1259 | };
|
---|
1260 |
|
---|
1261 | //Loadbalance constants:
|
---|
1262 | #define LB_NONE 0
|
---|
1263 | #define LB_FASTEST_READER_FIRST 1
|
---|
1264 | #define LB_OLDEST_READER_FIRST 2
|
---|
1265 | #define LB_LOWEST_USAGELEVEL 3
|
---|
1266 | #define LB_LOG_ONLY 10
|
---|
1267 |
|
---|
1268 | #define LB_MAX_STAT_TIME 10
|
---|
1269 |
|
---|
1270 | typedef struct reader_stat_t
|
---|
1271 | {
|
---|
1272 | int32_t rc;
|
---|
1273 | uint16_t caid;
|
---|
1274 | uint32_t prid;
|
---|
1275 | uint16_t srvid;
|
---|
1276 | int16_t ecmlen;
|
---|
1277 |
|
---|
1278 | time_t last_received;
|
---|
1279 |
|
---|
1280 | int32_t ecm_count;
|
---|
1281 | int32_t time_avg;
|
---|
1282 | int32_t time_stat[LB_MAX_STAT_TIME];
|
---|
1283 | int32_t time_idx;
|
---|
1284 |
|
---|
1285 | int32_t fail_factor;
|
---|
1286 | } READER_STAT;
|
---|
1287 |
|
---|
1288 | typedef struct emm_packet_t
|
---|
1289 | {
|
---|
1290 | uchar emm[258];
|
---|
1291 | uchar l;
|
---|
1292 | uchar caid[2];
|
---|
1293 | uchar provid[4];
|
---|
1294 | uchar hexserial[8]; //contains hexserial or SA of EMM
|
---|
1295 | uchar type;
|
---|
1296 | struct s_client *client;
|
---|
1297 | } EMM_PACKET;
|
---|
1298 |
|
---|
1299 | //EMM types:
|
---|
1300 | #define UNKNOWN 0
|
---|
1301 | #define UNIQUE 1
|
---|
1302 | #define SHARED 2
|
---|
1303 | #define GLOBAL 3
|
---|
1304 |
|
---|
1305 | // oscam-simples
|
---|
1306 | extern char *remote_txt(void);
|
---|
1307 | extern char *trim(char *);
|
---|
1308 | extern char *strtolower(char *);
|
---|
1309 | extern int32_t gethexval(char);
|
---|
1310 | extern int32_t cs_atob(uchar *, char *, int32_t);
|
---|
1311 | extern uint32_t cs_atoi(char *, int32_t, int32_t);
|
---|
1312 | extern int32_t byte_atob(char *);
|
---|
1313 | extern int32_t word_atob(char *);
|
---|
1314 | extern int32_t dyn_word_atob(char *asc);
|
---|
1315 | extern int32_t key_atob_l(char *, uchar *, int32_t);
|
---|
1316 | extern char *key_btoa(char *, uchar *);
|
---|
1317 | extern char *cs_hexdump(int32_t, const uchar *, int32_t);
|
---|
1318 | extern char *cs_hexdump_buf(int32_t, const uchar *, int32_t, char *target, int32_t len);
|
---|
1319 | extern in_addr_t cs_inet_order(in_addr_t);
|
---|
1320 | extern char *cs_inet_ntoa(in_addr_t);
|
---|
1321 | extern in_addr_t cs_inet_addr(char *txt);
|
---|
1322 | extern uint32_t b2i(int32_t, uchar *);
|
---|
1323 | extern uint64_t b2ll(int32_t, uchar *);
|
---|
1324 | extern uchar *i2b_buf(int32_t n, uint32_t i, uchar *b);
|
---|
1325 |
|
---|
1326 | extern uint32_t a2i(char *, int32_t);
|
---|
1327 | extern int32_t boundary(int32_t, int32_t);
|
---|
1328 | extern void cs_ftime(struct timeb *);
|
---|
1329 | extern void cs_sleepms(uint32_t);
|
---|
1330 | extern void cs_sleepus(uint32_t);
|
---|
1331 | extern void cs_setpriority(int32_t);
|
---|
1332 | extern struct s_auth *find_user(char *);
|
---|
1333 | extern int32_t check_filled(uchar *value, int32_t length);
|
---|
1334 | extern void *cs_malloc(void *result, size_t size, int32_t quiterror);
|
---|
1335 | extern void *cs_realloc(void *result, size_t size, int32_t quiterror);
|
---|
1336 | #ifdef WEBIF
|
---|
1337 | extern char to_hex(char code);
|
---|
1338 | extern void char_to_hex(const unsigned char* p_array, uint32_t p_array_len, unsigned char *result);
|
---|
1339 | extern void create_rand_str(char *dst, int32_t size);
|
---|
1340 | #endif
|
---|
1341 | extern int32_t file_exists(const char * filename);
|
---|
1342 | extern void clear_sip(struct s_ip **sip);
|
---|
1343 | extern void clear_ptab(struct s_ptab *ptab);
|
---|
1344 | extern void clear_ftab(struct s_ftab *ftab);
|
---|
1345 | void clear_caidtab(struct s_caidtab *ctab);
|
---|
1346 | void clear_tuntab(struct s_tuntab *ttab);
|
---|
1347 | extern int32_t file_copy(char *srcfile, char *destfile);
|
---|
1348 | extern int32_t safe_overwrite_with_bak(char *destfile, char *tmpfile, char *bakfile, int32_t forceBakOverWrite);
|
---|
1349 | extern void fprintf_conf(FILE *f, int32_t varnameWidth, const char *varname, const char *fmtstring, ...);
|
---|
1350 | extern void cs_strncpy(char * destination, const char * source, size_t num);
|
---|
1351 | extern char *get_servicename(struct s_client *cl, int32_t srvid, int32_t caid, char *buf);
|
---|
1352 | extern char *get_tiername(int32_t tierid, int32_t caid, char *buf);
|
---|
1353 | extern char *get_provider(int32_t caid, uint32_t provid, char *buf);
|
---|
1354 | extern void make_non_blocking(int32_t fd);
|
---|
1355 | extern uchar fast_rnd(void);
|
---|
1356 | extern void init_rnd(void);
|
---|
1357 | extern int32_t hexserialset(struct s_reader *rdr);
|
---|
1358 | extern char *monitor_get_proto(struct s_client *);
|
---|
1359 | extern char *reader_get_type_desc(struct s_reader * rdr, int32_t extended);
|
---|
1360 | extern char *get_ncd_client_name(char *client_id);
|
---|
1361 | extern int32_t cs_strnicmp(const char * str1, const char * str2, size_t num);
|
---|
1362 | extern char *strnew(char *str);
|
---|
1363 | extern void hexserial_to_newcamd(uchar *source, uchar *dest, uint16_t caid);
|
---|
1364 | extern void newcamd_to_hexserial(uchar *source, uchar *dest, uint16_t caid);
|
---|
1365 | extern int32_t check_ip(struct s_ip *ip, in_addr_t n);
|
---|
1366 | extern int32_t cs_lock(pthread_mutex_t *mutex);
|
---|
1367 | extern int32_t cs_trylock(pthread_mutex_t *mutex);
|
---|
1368 | extern int32_t cs_unlock(pthread_mutex_t *mutex);
|
---|
1369 | extern void cs_cleanlocks();
|
---|
1370 |
|
---|
1371 | extern pthread_key_t getclient;
|
---|
1372 | extern struct s_client * cur_client(void);
|
---|
1373 | extern struct s_client *first_client;
|
---|
1374 | extern struct s_reader *first_active_reader; //points to list of _active_ readers (enable = 1, deleted = 0)
|
---|
1375 | extern LLIST *configured_readers;
|
---|
1376 |
|
---|
1377 | // oscam variables
|
---|
1378 |
|
---|
1379 | extern int32_t cs_dblevel;
|
---|
1380 |
|
---|
1381 | extern uint16_t len4caid[256];
|
---|
1382 |
|
---|
1383 | extern struct card_struct *Cards;
|
---|
1384 | //extern struct idstore_struct *idstore;
|
---|
1385 | extern uint32_t *IgnoreList;
|
---|
1386 |
|
---|
1387 | extern struct s_config cfg;
|
---|
1388 | extern char cs_confdir[];
|
---|
1389 | extern char *loghist, *loghistptr;
|
---|
1390 | extern struct s_module ph[CS_MAX_MOD];
|
---|
1391 | extern struct s_cardsystem cardsystem[CS_MAX_MOD];
|
---|
1392 | extern struct s_cardreader cardreader[CS_MAX_MOD];
|
---|
1393 | //extern ECM_REQUEST *ecmtask;
|
---|
1394 |
|
---|
1395 | #ifdef CS_ANTICASC
|
---|
1396 | extern FILE *fpa;
|
---|
1397 | #endif
|
---|
1398 | extern pthread_mutex_t gethostbyname_lock;
|
---|
1399 |
|
---|
1400 | // oscam
|
---|
1401 | #ifdef WEBIF
|
---|
1402 | extern void cs_exit_oscam();
|
---|
1403 | extern void cs_restart_oscam();
|
---|
1404 | extern int32_t cs_get_restartmode();
|
---|
1405 |
|
---|
1406 | //reset stats for webif:
|
---|
1407 | extern void clear_account_stats(struct s_auth *account);
|
---|
1408 | extern void clear_all_account_stats();
|
---|
1409 | extern void clear_system_stats();
|
---|
1410 |
|
---|
1411 | #endif
|
---|
1412 | extern void start_thread(void * startroutine, char * nameroutine);
|
---|
1413 | extern void cs_reload_config();
|
---|
1414 | extern int32_t recv_from_udpipe(uchar *);
|
---|
1415 | extern char* username(struct s_client *);
|
---|
1416 | extern struct s_client * get_client_by_tid(uint32_t);
|
---|
1417 | extern int32_t chk_bcaid(ECM_REQUEST *, CAIDTAB *);
|
---|
1418 | extern void cs_exit(int32_t sig);
|
---|
1419 | extern int32_t comp_timeb(struct timeb *tpa, struct timeb *tpb);
|
---|
1420 | extern struct s_client * create_client(in_addr_t);
|
---|
1421 | extern int32_t cs_auth_client(struct s_client *, struct s_auth *, const char*);
|
---|
1422 | extern void cs_disconnect_client(struct s_client *);
|
---|
1423 | extern int32_t check_cwcache2(ECM_REQUEST *, uint64_t grp);
|
---|
1424 | extern int32_t write_to_pipe(int32_t, int32_t, uchar *, int32_t);
|
---|
1425 | extern int32_t read_from_pipe(int32_t, uchar **);
|
---|
1426 | extern int32_t write_ecm_answer(struct s_reader *, ECM_REQUEST *);
|
---|
1427 | extern void log_emm_request(struct s_reader *);
|
---|
1428 | extern uint32_t chk_provid(uchar *, uint16_t);
|
---|
1429 | extern void convert_to_beta(struct s_client *cl, ECM_REQUEST *er, uint16_t caidto);
|
---|
1430 | #ifdef IRDETO_GUESSING
|
---|
1431 | extern void guess_irdeto(ECM_REQUEST *);
|
---|
1432 | #endif
|
---|
1433 | extern void get_cw(struct s_client *, ECM_REQUEST *);
|
---|
1434 | extern void do_emm(struct s_client *, EMM_PACKET *);
|
---|
1435 | extern ECM_REQUEST *get_ecmtask(void);
|
---|
1436 | extern void request_cw(ECM_REQUEST *, int32_t, int32_t);
|
---|
1437 | extern void send_reader_stat(struct s_reader *rdr, ECM_REQUEST *er, int32_t rc);
|
---|
1438 | extern int32_t send_dcw(struct s_client *, ECM_REQUEST *);
|
---|
1439 | extern int32_t process_input(uchar *, int32_t, int32_t);
|
---|
1440 | extern int32_t has_srvid(struct s_client *cl, ECM_REQUEST *er);
|
---|
1441 | extern int32_t chk_srvid(struct s_client *, ECM_REQUEST *);
|
---|
1442 | extern int32_t chk_srvid_match(ECM_REQUEST *, SIDTAB *);
|
---|
1443 | extern int32_t chk_sfilter(ECM_REQUEST *, PTAB*);
|
---|
1444 | extern int32_t chk_ufilters(ECM_REQUEST *);
|
---|
1445 | extern int32_t chk_rsfilter(struct s_reader * reader, ECM_REQUEST *);
|
---|
1446 | extern int32_t matching_reader(ECM_REQUEST *, struct s_reader *);
|
---|
1447 | extern int32_t emm_reader_match(struct s_reader *reader, uint16_t caid, uint32_t provid);
|
---|
1448 | extern void set_signal_handler(int32_t , int32_t , void (*));
|
---|
1449 | extern void cs_log_config(void);
|
---|
1450 | extern void cs_waitforcardinit(void);
|
---|
1451 | extern void cs_reinit_clients(struct s_auth *new_accounts);
|
---|
1452 | extern int32_t process_client_pipe(struct s_client *cl, uchar *buf, int32_t l);
|
---|
1453 | extern void update_reader_config(uchar *ptr);
|
---|
1454 | extern int32_t chk_ctab(uint16_t caid, CAIDTAB *ctab);
|
---|
1455 | extern int32_t chk_srvid_by_caid_prov(struct s_client *, uint16_t caid, uint32_t provid);
|
---|
1456 | extern void nullclose(int32_t *fd);
|
---|
1457 | extern void *clientthread_init(void * init);
|
---|
1458 | extern void cleanup_thread(void *var);
|
---|
1459 | extern void kill_thread(struct s_client *cl);
|
---|
1460 | extern int32_t get_threadnum(struct s_client *client);
|
---|
1461 | extern void cs_add_violation(uint32_t ip);
|
---|
1462 |
|
---|
1463 | extern void cs_card_info(void);
|
---|
1464 | extern void cs_debug_level(void);
|
---|
1465 |
|
---|
1466 | #ifdef CS_ANTICASC
|
---|
1467 | extern void init_ac(void);
|
---|
1468 | extern void ac_init_stat();
|
---|
1469 | extern void ac_clear();
|
---|
1470 | extern void ac_done_stat();
|
---|
1471 | extern int32_t ac_init_log();
|
---|
1472 | extern void ac_do_stat(void);
|
---|
1473 | extern void ac_init_client(struct s_client *, struct s_auth *);
|
---|
1474 | extern void ac_chk(struct s_client *,ECM_REQUEST*, int32_t);
|
---|
1475 | #endif
|
---|
1476 |
|
---|
1477 | // oscam-config
|
---|
1478 | extern int32_t init_config(void);
|
---|
1479 | extern int32_t init_free_userdb(struct s_auth *auth);
|
---|
1480 | extern struct s_auth *init_userdb();
|
---|
1481 | extern int32_t init_readerdb(void);
|
---|
1482 | extern void free_reader(struct s_reader *rdr);
|
---|
1483 | extern int32_t init_sidtab(void);
|
---|
1484 | extern void free_sidtab(struct s_sidtab *sidtab);
|
---|
1485 | extern void init_free_sidtab();
|
---|
1486 | extern int32_t init_srvid(void);
|
---|
1487 | extern int32_t init_tierid(void);
|
---|
1488 | extern int32_t search_boxkey(uint16_t, char *);
|
---|
1489 | extern void init_len4caid(void);
|
---|
1490 | #ifdef IRDETO_GUESSING
|
---|
1491 | extern int32_t init_irdeto_guess_tab(void);
|
---|
1492 | #endif
|
---|
1493 | extern void chk_caidtab(char *caidasc, CAIDTAB *ctab);
|
---|
1494 | extern void chk_tuntab(char *tunasc, TUNTAB *ttab);
|
---|
1495 | extern void chk_services(char *labels, SIDTABBITS *sidok, SIDTABBITS *sidno);
|
---|
1496 | extern void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName);
|
---|
1497 | extern void chk_cltab(char *classasc, CLASSTAB *clstab);
|
---|
1498 | extern void chk_iprange(char *value, struct s_ip **base);
|
---|
1499 | extern void chk_port_tab(char *portasc, PTAB *ptab);
|
---|
1500 | #ifdef CS_ANTICASC
|
---|
1501 | extern void chk_t_ac(char *token, char *value);
|
---|
1502 | #endif
|
---|
1503 | extern void chk_t_camd33(char *token, char *value);
|
---|
1504 | extern void chk_t_camd35(char *token, char *value);
|
---|
1505 | extern void chk_t_camd35_tcp(char *token, char *value);
|
---|
1506 | extern void chk_t_newcamd(char *token, char *value);
|
---|
1507 | extern void chk_t_radegast(char *token, char *value);
|
---|
1508 | extern void chk_t_serial(char *token, char *value);
|
---|
1509 | extern void chk_t_gbox(char *token, char *value);
|
---|
1510 | #ifdef MODULE_CCCAM
|
---|
1511 | extern void chk_t_cccam(char *token, char *value);
|
---|
1512 | #endif
|
---|
1513 | extern void chk_t_global(const char *token, char *value);
|
---|
1514 | extern void chk_t_monitor(char *token, char *value);
|
---|
1515 | extern void chk_reader(char *token, char *value, struct s_reader *rdr);
|
---|
1516 |
|
---|
1517 | #ifdef HAVE_DVBAPI
|
---|
1518 | extern void chk_t_dvbapi(char *token, char *value);
|
---|
1519 | void dvbapi_chk_caidtab(char *caidasc, char type);
|
---|
1520 | void dvbapi_read_priority();
|
---|
1521 | #endif
|
---|
1522 |
|
---|
1523 | #ifdef WEBIF
|
---|
1524 | extern void chk_t_webif(char *token, char *value);
|
---|
1525 | #endif
|
---|
1526 |
|
---|
1527 | extern void cs_accounts_chk(void);
|
---|
1528 | extern void chk_account(const char *token, char *value, struct s_auth *account);
|
---|
1529 | extern void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab);
|
---|
1530 | extern int32_t write_services();
|
---|
1531 | extern int32_t write_userdb(struct s_auth *authptr);
|
---|
1532 | extern int32_t write_config();
|
---|
1533 | extern int32_t write_server();
|
---|
1534 | extern void write_versionfile();
|
---|
1535 | extern char *mk_t_caidtab(CAIDTAB *ctab);
|
---|
1536 | extern char *mk_t_caidvaluetab(CAIDVALUETAB *tab);
|
---|
1537 | extern char *mk_t_tuntab(TUNTAB *ttab);
|
---|
1538 | extern char *mk_t_group(uint64_t grp);
|
---|
1539 | extern char *mk_t_ftab(FTAB *ftab);
|
---|
1540 | extern char *mk_t_camd35tcp_port();
|
---|
1541 | extern char *mk_t_cccam_port();
|
---|
1542 | extern char *mk_t_aeskeys(struct s_reader *rdr);
|
---|
1543 | extern char *mk_t_newcamd_port();
|
---|
1544 | extern char *mk_t_aureader(struct s_auth *account);
|
---|
1545 | extern char *mk_t_nano(struct s_reader *rdr, uchar flag);
|
---|
1546 | extern char *mk_t_service( uint64_t sidtabok, uint64_t sidtabno);
|
---|
1547 | extern char *mk_t_logfile();
|
---|
1548 | extern char *mk_t_iprange(struct s_ip *range);
|
---|
1549 | extern char *mk_t_ecmwhitelist(struct s_ecmWhitelist *whitelist);
|
---|
1550 | extern char *mk_t_cltab(CLASSTAB *clstab);
|
---|
1551 | extern void free_mk_t(char *value);
|
---|
1552 |
|
---|
1553 | //Todo #ifdef CCCAM
|
---|
1554 | extern int32_t init_provid();
|
---|
1555 | extern char * get_tmp_dir();
|
---|
1556 | extern void init_share();
|
---|
1557 | extern void done_share();
|
---|
1558 |
|
---|
1559 | // oscam-reader
|
---|
1560 | extern int32_t logfd;
|
---|
1561 | extern int32_t reader_cmd2icc(struct s_reader * reader, const uchar *buf, const int32_t l, uchar *response, uint16_t *response_length);
|
---|
1562 | extern int32_t card_write(struct s_reader * reader, const uchar *, const uchar *, uchar *, uint16_t *);
|
---|
1563 | extern int32_t check_sct_len(const unsigned char *data, int32_t off);
|
---|
1564 | extern void cs_ri_brk(struct s_reader * reader, int32_t);
|
---|
1565 | extern void cs_ri_log(struct s_reader * reader, char *,...);
|
---|
1566 | extern void * start_cardreader(void *);
|
---|
1567 | extern void reader_card_info(struct s_reader * reader);
|
---|
1568 | extern int32_t hostResolve(struct s_reader * reader);
|
---|
1569 | extern int32_t network_tcp_connection_open();
|
---|
1570 | extern void network_tcp_connection_close(struct s_client *, int32_t);
|
---|
1571 | extern int32_t casc_recv_timer(struct s_reader * reader, uchar *buf, int32_t l, int32_t msec);
|
---|
1572 | extern void clear_reader_pipe(struct s_reader * reader);
|
---|
1573 | extern void block_connect(struct s_reader *rdr);
|
---|
1574 | extern int32_t is_connect_blocked(struct s_reader *rdr);
|
---|
1575 |
|
---|
1576 | // oscam-log
|
---|
1577 | extern int32_t cs_init_log();
|
---|
1578 | extern void cs_reinit_loghist(uint32_t size);
|
---|
1579 | extern int32_t cs_open_logfiles();
|
---|
1580 | extern void cs_write_log(char *);
|
---|
1581 | extern void cs_log(const char *,...);
|
---|
1582 | #ifdef WITH_DEBUG
|
---|
1583 | extern void cs_debug_mask(uint16_t, const char *,...);
|
---|
1584 | extern void cs_ddump_mask(uint16_t, const uchar *, int32_t, char *, ...);
|
---|
1585 | #else
|
---|
1586 | #define nop() asm volatile("nop")
|
---|
1587 | #define cs_debug(...) nop()
|
---|
1588 | #define cs_debug_mask(...) nop()
|
---|
1589 | #define cs_ddump(...) nop()
|
---|
1590 | #define cs_ddump_mask(...) nop()
|
---|
1591 | #endif
|
---|
1592 | extern void cs_close_log(void);
|
---|
1593 | extern int32_t cs_init_statistics();
|
---|
1594 | extern void cs_dump(const uchar *, int32_t, char *, ...);
|
---|
1595 |
|
---|
1596 | // oscam-aes
|
---|
1597 | extern void aes_set_key(char *);
|
---|
1598 | extern void aes_encrypt_idx(struct s_client *, uchar *, int32_t);
|
---|
1599 | extern void aes_decrypt(uchar *, int32_t);
|
---|
1600 | extern int32_t aes_decrypt_from_list(AES_ENTRY *list, uint16_t caid, uint32_t provid,int32_t keyid, uchar *buf, int32_t n);
|
---|
1601 | extern int32_t aes_present(AES_ENTRY *list, uint16_t caid, uint32_t provid,int32_t keyid);
|
---|
1602 | extern void parse_aes_keys(struct s_reader *rdr,char *value);
|
---|
1603 |
|
---|
1604 | #define aes_encrypt(b, n) aes_encrypt_idx(cur_client(), b, n)
|
---|
1605 |
|
---|
1606 | // reader-common
|
---|
1607 | extern int32_t reader_device_init(struct s_reader * reader);
|
---|
1608 | extern int32_t reader_checkhealth(struct s_reader * reader);
|
---|
1609 | extern void reader_post_process(struct s_reader * reader);
|
---|
1610 | extern int32_t reader_ecm(struct s_reader * reader, ECM_REQUEST *);
|
---|
1611 | extern int32_t reader_emm(struct s_reader * reader, EMM_PACKET *);
|
---|
1612 | int32_t reader_get_emm_type(EMM_PACKET *ep, struct s_reader * reader);
|
---|
1613 | struct s_cardsystem *get_cardsystem_by_caid(uint16_t caid);
|
---|
1614 | extern void reader_device_close(struct s_reader * reader);
|
---|
1615 |
|
---|
1616 | #ifdef WITH_LB
|
---|
1617 | //module-stat
|
---|
1618 | extern void init_stat();
|
---|
1619 | extern int32_t get_best_reader(ECM_REQUEST *er);
|
---|
1620 | extern void clear_reader_stat(struct s_reader *reader);
|
---|
1621 | extern void add_stat(struct s_reader *rdr, ECM_REQUEST *er, int32_t ecm_time, int32_t rc);
|
---|
1622 | extern void load_stat_from_file();
|
---|
1623 | extern void save_stat_to_file(int32_t);
|
---|
1624 | extern void clear_all_stat();
|
---|
1625 | extern void housekeeping_stat(int32_t force);
|
---|
1626 | extern void sort_stat(struct s_reader *rdr, int32_t reverse);
|
---|
1627 | #endif
|
---|
1628 |
|
---|
1629 | #ifdef HAVE_PCSC
|
---|
1630 | // reader-pcsc
|
---|
1631 | extern void pcsc_close(struct s_reader *pcsc_reader);
|
---|
1632 | #endif
|
---|
1633 |
|
---|
1634 | void reader_nagra();
|
---|
1635 | void reader_irdeto();
|
---|
1636 | void reader_cryptoworks();
|
---|
1637 | void reader_viaccess();
|
---|
1638 | void reader_conax();
|
---|
1639 | void reader_seca();
|
---|
1640 | void reader_videoguard1();
|
---|
1641 | void reader_videoguard2();
|
---|
1642 | void reader_videoguard12();
|
---|
1643 | void reader_dre();
|
---|
1644 | void reader_tongfang();
|
---|
1645 |
|
---|
1646 | void cardreader_mouse(struct s_cardreader *crdr);
|
---|
1647 | void cardreader_smargo(struct s_cardreader *crdr);
|
---|
1648 | #ifdef WITH_STAPI
|
---|
1649 | void cardreader_stapi(struct s_cardreader *crdr);
|
---|
1650 | #endif
|
---|
1651 |
|
---|
1652 | // protocol modules
|
---|
1653 | extern int32_t monitor_send_idx(struct s_client *, char *);
|
---|
1654 | extern void module_monitor(struct s_module *);
|
---|
1655 | extern void module_camd35(struct s_module *);
|
---|
1656 | extern void module_camd35_tcp(struct s_module *);
|
---|
1657 | extern void module_camd33(struct s_module *);
|
---|
1658 | extern void module_newcamd(struct s_module *);
|
---|
1659 | extern void module_radegast(struct s_module *);
|
---|
1660 | extern void module_oscam_ser(struct s_module *);
|
---|
1661 | #ifdef MODULE_CCCAM
|
---|
1662 | extern void module_cccam(struct s_module *);
|
---|
1663 | #endif
|
---|
1664 | extern void module_gbox(struct s_module *);
|
---|
1665 | extern void module_constcw(struct s_module *);
|
---|
1666 | extern int32_t chk_pending(int32_t timeout);
|
---|
1667 | #ifdef HAVE_DVBAPI
|
---|
1668 | extern void module_dvbapi(struct s_module *);
|
---|
1669 | #endif
|
---|
1670 |
|
---|
1671 | #ifdef WEBIF
|
---|
1672 | // oscam-http
|
---|
1673 | extern void http_srv();
|
---|
1674 | #endif
|
---|
1675 |
|
---|
1676 | // oscam-garbage
|
---|
1677 | #ifdef WITH_DEBUG
|
---|
1678 | extern void add_garbage_debug(void *data, char *file, int32_t line);
|
---|
1679 | #define add_garbage(x) add_garbage_debug(x,__FILE__, __LINE__)
|
---|
1680 | #else
|
---|
1681 | extern void add_garbage(void *data);
|
---|
1682 | #endif
|
---|
1683 | extern void start_garbage_collector(int32_t);
|
---|
1684 | extern void stop_garbage_collector();
|
---|
1685 |
|
---|
1686 | #ifdef LCDSUPPORT
|
---|
1687 | // oscam-lcd
|
---|
1688 | extern void start_lcd_thread();
|
---|
1689 | extern void end_lcd_thread();
|
---|
1690 | #endif
|
---|
1691 |
|
---|
1692 | #endif // CS_GLOBALS
|
---|