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 | #include <sys/socket.h>
|
---|
22 | #include <netinet/in.h>
|
---|
23 | #include <arpa/inet.h>
|
---|
24 | #include <netdb.h>
|
---|
25 | #include <string.h>
|
---|
26 | #include <signal.h>
|
---|
27 | #include <errno.h>
|
---|
28 | #include <pthread.h>
|
---|
29 |
|
---|
30 | #include "module-datastruct-llist.h"
|
---|
31 |
|
---|
32 | //for reader-nagra variables in s_reader:
|
---|
33 | #include "cscrypt/idea.h"
|
---|
34 |
|
---|
35 | #include "oscam-config.h"
|
---|
36 |
|
---|
37 | #ifndef USE_CMAKE
|
---|
38 | # include "oscam-ostype.h"
|
---|
39 | #endif
|
---|
40 | #include "oscam-types.h"
|
---|
41 | #include "cscrypt/cscrypt.h"
|
---|
42 |
|
---|
43 | #ifdef HAVE_PCSC
|
---|
44 | #ifdef OS_CYGWIN32
|
---|
45 | #define __reserved
|
---|
46 | #define __nullnullterminated
|
---|
47 | #include <specstrings.h>
|
---|
48 | #include "cygwin/WinSCard.h"
|
---|
49 | #else
|
---|
50 | #include <PCSC/pcsclite.h>
|
---|
51 | #ifdef OS_MACOSX
|
---|
52 | #include <PCSC/wintypes.h>
|
---|
53 | #else
|
---|
54 | #include <PCSC/reader.h>
|
---|
55 | #endif
|
---|
56 | #endif
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | #if defined(LIBUSB)
|
---|
60 | #ifdef __FreeBSD__
|
---|
61 | #include <libusb.h>
|
---|
62 | #else
|
---|
63 | #include <libusb-1.0/libusb.h>
|
---|
64 | #endif
|
---|
65 | #include "csctapi/smartreader_types.h"
|
---|
66 | #endif
|
---|
67 |
|
---|
68 | /* ===========================
|
---|
69 | * macros
|
---|
70 | * =========================== */
|
---|
71 | // Prevent use of unsafe functions (doesn't work for MacOSX)
|
---|
72 | #ifndef OS_MACOSX
|
---|
73 | #define strcpy(a,b) UNSAFE_STRCPY_USE_CS_STRNCPY_INSTEAD()
|
---|
74 | #define sprintf(a,...) UNSAFE_SPRINTF_USE_SNPRINTF_INSTEAD()
|
---|
75 | #define strtok(a,b,c) UNSAFE_STRTOK_USE_STRTOK_R_INSTEAD()
|
---|
76 | #endif
|
---|
77 |
|
---|
78 | #ifdef UNUSED
|
---|
79 | #elif defined(__GNUC__)
|
---|
80 | # define UNUSED(x) UNUSED_ ## x __attribute__((unused))
|
---|
81 | #elif defined(__LCLINT__)
|
---|
82 | # define UNUSED(x) /*@unused@*/ x
|
---|
83 | #else
|
---|
84 | # define UNUSED(x) x
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | #ifdef WITH_DEBUG
|
---|
88 | # define call(arg) \
|
---|
89 | if (arg) { \
|
---|
90 | cs_debug_mask(D_TRACE, "ERROR, function call %s returns error.",#arg); \
|
---|
91 | }
|
---|
92 | # define D_USE(x) x
|
---|
93 | #else
|
---|
94 | # define call(arg) arg
|
---|
95 | # if defined(__GNUC__)
|
---|
96 | # define D_USE(x) D_USE_ ## x __attribute__((unused))
|
---|
97 | # elif defined(__LCLINT__)
|
---|
98 | # define D_USE(x) /*@debug use only@*/ x
|
---|
99 | # else
|
---|
100 | # define D_USE(x) x
|
---|
101 | # endif
|
---|
102 | #endif
|
---|
103 |
|
---|
104 | //checking if (X) free(X) unneccessary since freeing a null pointer doesnt do anything
|
---|
105 | #define NULLFREE(X) {if (X) {void *tmpX=X; X=NULL; free(tmpX); }}
|
---|
106 |
|
---|
107 | /* ===========================
|
---|
108 | * constants
|
---|
109 | * =========================== */
|
---|
110 | #ifndef CS_GLOBALS
|
---|
111 | #define CS_GLOBALS
|
---|
112 | #define CS_VERSION "1.00-unstable_svn"
|
---|
113 | #ifndef CS_SVN_VERSION
|
---|
114 | # define CS_SVN_VERSION "test"
|
---|
115 | #endif
|
---|
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 | #define PTHREAD_STACK_SIZE PTHREAD_STACK_MIN+32768
|
---|
143 |
|
---|
144 | #ifdef CS_EMBEDDED
|
---|
145 | #define CS_MAXPENDING 16
|
---|
146 | #else
|
---|
147 | #define CS_MAXPENDING 32
|
---|
148 | #endif
|
---|
149 |
|
---|
150 | #define CS_EMMCACHESIZE 64 //nr of EMMs that each client will cache; cache is per client, so memory-expensive...
|
---|
151 | #define MSGLOGSIZE 64 //size of string buffer for a ecm to return messages
|
---|
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 | #ifdef HAVE_DVBAPI
|
---|
222 | #define BOXTYPE_DREAMBOX 1
|
---|
223 | #define BOXTYPE_DUCKBOX 2
|
---|
224 | #define BOXTYPE_UFS910 3
|
---|
225 | #define BOXTYPE_DBOX2 4
|
---|
226 | #define BOXTYPE_IPBOX 5
|
---|
227 | #define BOXTYPE_IPBOX_PMT 6
|
---|
228 | #define BOXTYPE_DM7000 7
|
---|
229 | #define BOXTYPE_QBOXHD 8
|
---|
230 | #define BOXTYPE_COOLSTREAM 9
|
---|
231 | #define BOXTYPE_NEUMO 10
|
---|
232 | #define BOXTYPES 10
|
---|
233 | extern const char *boxdesc[];
|
---|
234 | #endif
|
---|
235 |
|
---|
236 | #define EMM_UNIQUE 1
|
---|
237 | #define EMM_SHARED 2
|
---|
238 | #define EMM_GLOBAL 4
|
---|
239 | #define EMM_UNKNOWN 8
|
---|
240 |
|
---|
241 | //EMM types:
|
---|
242 | #define UNKNOWN 0
|
---|
243 | #define UNIQUE 1
|
---|
244 | #define SHARED 2
|
---|
245 | #define GLOBAL 3
|
---|
246 |
|
---|
247 | #ifdef CS_CORE
|
---|
248 | char *PIP_ID_TXT[] = { "ECM", "EMM", "CIN", "KCL", "UDP", NULL };
|
---|
249 | char *RDR_CD_TXT[] = { "cd", "dsr", "cts", "ring", "none",
|
---|
250 | #ifdef USE_GPIO
|
---|
251 | "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", //felix: changed so that gpio can be used
|
---|
252 | #endif
|
---|
253 | NULL };
|
---|
254 | #else
|
---|
255 | extern char *PIP_ID_TXT[];
|
---|
256 | extern char *RDR_CD_TXT[];
|
---|
257 | #endif
|
---|
258 |
|
---|
259 | #define PIP_ID_ECM 0
|
---|
260 | #define PIP_ID_EMM 1
|
---|
261 | #define PIP_ID_CIN 2 // CARD_INFO
|
---|
262 | #define PIP_ID_KCL 3 // Schlocke: Kill all Clients (no param)
|
---|
263 | #define PIP_ID_UDP 4
|
---|
264 | #define PIP_ID_MAX PIP_ID_UDP
|
---|
265 | #define PIP_ID_ERR (-1)
|
---|
266 | #define PIP_ID_DIR (-2)
|
---|
267 | #define PIP_ID_NUL (-3)
|
---|
268 |
|
---|
269 | #define cdiff *c_start
|
---|
270 |
|
---|
271 | #define NCD_AUTO 0
|
---|
272 | #define NCD_524 1
|
---|
273 | #define NCD_525 2
|
---|
274 |
|
---|
275 | // moved from reader-common.h
|
---|
276 | #define UNKNOWN 0
|
---|
277 | #define CARD_NEED_INIT 1
|
---|
278 | #define CARD_INSERTED 2
|
---|
279 | #define CARD_FAILURE 3
|
---|
280 | #define NO_CARD 4
|
---|
281 |
|
---|
282 | // moved from stats
|
---|
283 | #define DEFAULT_REOPEN_SECONDS 900
|
---|
284 | #define DEFAULT_MIN_ECM_COUNT 5
|
---|
285 | #define DEFAULT_MAX_ECM_COUNT 500
|
---|
286 | #define DEFAULT_NBEST 1
|
---|
287 | #define DEFAULT_NFB 1
|
---|
288 | #define DEFAULT_RETRYLIMIT 800
|
---|
289 | #define DEFAULT_LB_MODE 0
|
---|
290 | #define DEFAULT_LB_STAT_CLEANUP 336
|
---|
291 | #define DEFAULT_LB_USE_LOCKING 0
|
---|
292 | #define DEFAULT_LB_REOPEN_MODE 0
|
---|
293 | #define DEFAULT_UPDATEINTERVAL 240
|
---|
294 | #define DEFAULT_LB_AUTO_BETATUNNEL 1
|
---|
295 |
|
---|
296 | enum {E1_GLOBAL=0, E1_USER, E1_READER, E1_SERVER, E1_LSERVER};
|
---|
297 | enum {E2_GLOBAL=0, E2_GROUP, E2_CAID, E2_IDENT, E2_CLASS, E2_CHID, E2_QUEUE,
|
---|
298 | E2_EA_LEN, E2_F0_LEN, E2_OFFLINE, E2_SID,
|
---|
299 | E2_CCCAM_NOCARD=0x27, E2_CCCAM_NOK1=0x28, E2_CCCAM_NOK2=0x29, E2_CCCAM_LOOP=0x30};
|
---|
300 |
|
---|
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 | #define QBOXHD_LED_DEVICE "/dev/sw0"
|
---|
318 | #define QBOXHD_SET_LED_ALL_PANEL_COLOR _IO(0xBC, 13) // payload = 3byte [H][S][V]
|
---|
319 | #define QBOXHD_LED_COLOR_RED 359 // only H value, S and V values are always == 99
|
---|
320 | #define QBOXHD_LED_COLOR_GREEN 120
|
---|
321 | #define QBOXHD_LED_COLOR_BLUE 230
|
---|
322 | #define QBOXHD_LED_COLOR_YELLOW 55
|
---|
323 | #define QBOXHD_LED_COLOR_MAGENTA 290
|
---|
324 |
|
---|
325 | #define QBOXHDMINI_LED_DEVICE "/dev/lpc_0"
|
---|
326 | #define QBOXHDMINI_IOSET_RGB _IOWR('L', 6, qboxhdmini_led_color_struct)
|
---|
327 | #define QBOXHDMINI_LED_COLOR_RED 0x1F0000 // 3 bytes RGB , 5 bit used for each color
|
---|
328 | #define QBOXHDMINI_LED_COLOR_GREEN 0x001F00
|
---|
329 | #define QBOXHDMINI_LED_COLOR_BLUE 0x00001F
|
---|
330 | #define QBOXHDMINI_LED_COLOR_YELLOW 0x1F1F00
|
---|
331 | #define QBOXHDMINI_LED_COLOR_MAGENTA 0x1F001F
|
---|
332 |
|
---|
333 | #define QBOXHD_LED_COLOR_OFF -1 // all colors H,S,V and/or R,G,B == 0,0,0
|
---|
334 |
|
---|
335 | #define QBOXHD_LED_BLINK_FAST 100 // blink milliseconds
|
---|
336 | #define QBOXHD_LED_BLINK_MEDIUM 200
|
---|
337 | #define QBOXHD_LED_BLINK_SLOW 400
|
---|
338 |
|
---|
339 | #endif //QBOXHD_LED
|
---|
340 |
|
---|
341 | #define MAX_ATR_LEN 33 // max. ATR length
|
---|
342 | #define MAX_HIST 15 // max. number of historical characters
|
---|
343 |
|
---|
344 | #define MAX_SIDBITS 64 // max services
|
---|
345 | #define SIDTABBITS uint64_t // 64bit type for services, if a system does not support this type,
|
---|
346 | // please use a define and define it as uint32_t / MAX_SIDBITS 32
|
---|
347 |
|
---|
348 | #define BAN_UNKNOWN 1 //failban mask for anonymous/ unknown contact
|
---|
349 | #define BAN_DISABLED 2 //failban mask for disabled user
|
---|
350 | #define BAN_SLEEPING 4 //failban mask for sleeping user
|
---|
351 | #define BAN_DUPLICATE 8 //failban mask for duplicate user
|
---|
352 |
|
---|
353 | #define ACTION_READER_IDLE 1
|
---|
354 | #define ACTION_READER_REMOTE 2
|
---|
355 | #define ACTION_READER_REMOTELOG 3
|
---|
356 | #define ACTION_READER_RESET 4
|
---|
357 | #define ACTION_READER_ECM_REQUEST 5
|
---|
358 | #define ACTION_READER_EMM 6
|
---|
359 | #define ACTION_READER_CARDINFO 7
|
---|
360 | #define ACTION_READER_INIT 8
|
---|
361 |
|
---|
362 | #define ACTION_CLIENT_TCP_CONNECT 21
|
---|
363 | #define ACTION_CLIENT_UDP 22
|
---|
364 | #define ACTION_CLIENT_TCP 23
|
---|
365 | #define ACTION_CLIENT_ECM_ANSWER 24
|
---|
366 | #define ACTION_CLIENT_KILL 25
|
---|
367 | #define ACTION_CLIENT_INIT 26
|
---|
368 |
|
---|
369 | #define AVAIL_CHECK_CONNECTED 0
|
---|
370 | #define AVAIL_CHECK_LOADBALANCE 1
|
---|
371 |
|
---|
372 | #define LB_MAX_STAT_TIME 10
|
---|
373 |
|
---|
374 | /* ===========================
|
---|
375 | * global structures
|
---|
376 | * =========================== */
|
---|
377 | typedef struct s_caidvaluetab
|
---|
378 | {
|
---|
379 | uint16_t n;
|
---|
380 | uint16_t caid[CS_MAX_CAIDVALUETAB];
|
---|
381 | uint16_t value[CS_MAX_CAIDVALUETAB];
|
---|
382 | } CAIDVALUETAB;
|
---|
383 |
|
---|
384 | typedef struct s_classtab
|
---|
385 | {
|
---|
386 | uchar an;
|
---|
387 | uchar bn;
|
---|
388 | uchar aclass[31];
|
---|
389 | uchar bclass[31];
|
---|
390 | } CLASSTAB;
|
---|
391 |
|
---|
392 | typedef struct s_caidtab
|
---|
393 | {
|
---|
394 | uint16_t caid[CS_MAXCAIDTAB];
|
---|
395 | uint16_t mask[CS_MAXCAIDTAB];
|
---|
396 | uint16_t cmap[CS_MAXCAIDTAB];
|
---|
397 | } CAIDTAB;
|
---|
398 |
|
---|
399 | typedef struct s_tuntab
|
---|
400 | {
|
---|
401 | uint16_t n;
|
---|
402 | uint16_t bt_caidfrom[CS_MAXTUNTAB];
|
---|
403 | uint16_t bt_caidto[CS_MAXTUNTAB];
|
---|
404 | uint16_t bt_srvid[CS_MAXTUNTAB];
|
---|
405 | } TUNTAB;
|
---|
406 |
|
---|
407 | typedef struct s_sidtab
|
---|
408 | {
|
---|
409 | char label[64];
|
---|
410 | uint16_t num_caid;
|
---|
411 | uint16_t num_provid;
|
---|
412 | uint16_t num_srvid;
|
---|
413 | uint16_t *caid;
|
---|
414 | uint32_t *provid;
|
---|
415 | uint16_t *srvid;
|
---|
416 | struct s_sidtab *next;
|
---|
417 | } SIDTAB;
|
---|
418 |
|
---|
419 |
|
---|
420 | typedef struct s_filter
|
---|
421 | {
|
---|
422 | uint16_t caid;
|
---|
423 | uchar nprids;
|
---|
424 | uint32_t prids[CS_MAXPROV];
|
---|
425 | } FILTER;
|
---|
426 |
|
---|
427 | typedef struct s_ftab
|
---|
428 | {
|
---|
429 | int32_t nfilts;
|
---|
430 | FILTER filts[CS_MAXFILTERS];
|
---|
431 | } FTAB;
|
---|
432 |
|
---|
433 | typedef struct s_port
|
---|
434 | {
|
---|
435 | int32_t fd;
|
---|
436 | int32_t s_port;
|
---|
437 | int32_t ncd_key_is_set; //0 or 1
|
---|
438 | uchar ncd_key[16];
|
---|
439 | FTAB ftab;
|
---|
440 | } PORT;
|
---|
441 |
|
---|
442 | typedef struct s_ptab
|
---|
443 | {
|
---|
444 | int32_t nports;
|
---|
445 | PORT ports[CS_MAXPORTS];
|
---|
446 | } PTAB;
|
---|
447 |
|
---|
448 | typedef struct aes_entry {
|
---|
449 | uint16_t keyid;
|
---|
450 | uint16_t caid;
|
---|
451 | uint32_t ident;
|
---|
452 | uchar plainkey[16];
|
---|
453 | AES_KEY key;
|
---|
454 | struct aes_entry *next;
|
---|
455 | } AES_ENTRY;
|
---|
456 |
|
---|
457 | struct s_ecm
|
---|
458 | {
|
---|
459 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
460 | uchar cw[16];
|
---|
461 | uint16_t caid;
|
---|
462 | uint64_t grp;
|
---|
463 | struct s_reader *reader;
|
---|
464 | int32_t rc;
|
---|
465 | time_t time;
|
---|
466 | };
|
---|
467 |
|
---|
468 | struct s_emm
|
---|
469 | {
|
---|
470 | uchar emmd5[CS_EMMSTORESIZE];
|
---|
471 | uchar type;
|
---|
472 | int32_t count;
|
---|
473 | };
|
---|
474 |
|
---|
475 | // failban listmember
|
---|
476 | typedef struct v_ban {
|
---|
477 | int32_t v_count;
|
---|
478 | uint32_t v_ip;
|
---|
479 | time_t v_time;
|
---|
480 | } V_BAN;
|
---|
481 |
|
---|
482 | struct s_client ;
|
---|
483 | struct ecm_request_t ;
|
---|
484 | struct emm_packet_t ;
|
---|
485 |
|
---|
486 | struct s_module
|
---|
487 | {
|
---|
488 | int8_t active;
|
---|
489 | int8_t multi;
|
---|
490 | int8_t type;
|
---|
491 | int8_t watchdog;
|
---|
492 | char desc[16];
|
---|
493 | char *logtxt;
|
---|
494 | //int32_t s_port;
|
---|
495 | in_addr_t s_ip;
|
---|
496 | void *(*s_handler)(struct s_client *, uchar *, int);
|
---|
497 | void (*s_init)(struct s_client *);
|
---|
498 | int32_t (*recv)(struct s_client *, uchar *, int32_t);
|
---|
499 | void (*send_dcw)(struct s_client*, struct ecm_request_t *);
|
---|
500 | void (*cleanup)(struct s_client*);
|
---|
501 | int8_t c_multi;
|
---|
502 | int32_t (*c_recv_chk)(struct s_client*, uchar *, int32_t *, uchar *, int32_t);
|
---|
503 | int32_t (*c_init)(struct s_client*);
|
---|
504 | int32_t (*c_send_ecm)(struct s_client *, struct ecm_request_t *, uchar *);
|
---|
505 | int32_t (*c_send_emm)(struct emm_packet_t *);
|
---|
506 | int32_t (*c_init_log)(void);
|
---|
507 | int32_t (*c_recv_log)(uint16_t *, uint32_t *, uint16_t *);
|
---|
508 | int32_t (*c_available)(struct s_reader *, int32_t); //Schlocke: available check for load-balancing,
|
---|
509 | //params:
|
---|
510 | //rdr (reader to check)
|
---|
511 | //int32_t checktype (0=return connected, 1=return loadbalance-avail) return int
|
---|
512 | void (*c_idle)(void); //Schlocke: called when reader is idle
|
---|
513 | void (*c_card_info)(void); //Schlocke: request card infos
|
---|
514 | int32_t c_port;
|
---|
515 | PTAB *ptab;
|
---|
516 | int32_t num;
|
---|
517 | };
|
---|
518 |
|
---|
519 | struct s_ATR ;
|
---|
520 |
|
---|
521 | struct s_cardreader
|
---|
522 | {
|
---|
523 | int8_t active;
|
---|
524 | char desc[16];
|
---|
525 | int32_t (*reader_init)(struct s_reader*);
|
---|
526 | int32_t (*get_status)(struct s_reader*, int*);
|
---|
527 | int32_t (*activate)(struct s_reader*, struct s_ATR *);
|
---|
528 | int32_t (*transmit)(struct s_reader*, unsigned char *sent, uint32_t size);
|
---|
529 | int32_t (*receive)(struct s_reader*, unsigned char *data, uint32_t size);
|
---|
530 | int32_t (*close)(struct s_reader*);
|
---|
531 | int32_t (*set_parity)(struct s_reader*, uchar parity);
|
---|
532 | 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);
|
---|
533 | int32_t (*set_protocol)(struct s_reader*, unsigned char * params, uint32_t *length, uint32_t len_request);
|
---|
534 | 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
|
---|
535 | int32_t typ; //fixme: workaround, remove when all old code is converted
|
---|
536 |
|
---|
537 | int8_t max_clock_speed; // 1 for reader->typ > R_MOUSE
|
---|
538 | int8_t need_inverse; //0 = reader does inversing; 1 = inversing done by oscam
|
---|
539 | //io_serial config
|
---|
540 | int8_t flush;
|
---|
541 | int8_t read_written; // 1 = written bytes has to read from device
|
---|
542 | };
|
---|
543 |
|
---|
544 | struct s_cardsystem
|
---|
545 | {
|
---|
546 | int8_t active;
|
---|
547 | char *desc;
|
---|
548 | int32_t (*card_init)();
|
---|
549 | int32_t (*card_info)();
|
---|
550 | int32_t (*do_ecm)();
|
---|
551 | int32_t (*do_emm)();
|
---|
552 | void (*post_process)();
|
---|
553 | int32_t (*get_emm_type)();
|
---|
554 | void (*get_emm_filter)();
|
---|
555 | uchar caids[2];
|
---|
556 | };
|
---|
557 |
|
---|
558 | #ifdef IRDETO_GUESSING
|
---|
559 | struct s_irdeto_quess
|
---|
560 | {
|
---|
561 | int32_t b47;
|
---|
562 | uint16_t caid;
|
---|
563 | uint16_t sid;
|
---|
564 | struct s_irdeto_quess *next;
|
---|
565 | };
|
---|
566 | #endif
|
---|
567 |
|
---|
568 | typedef struct ecm_request_t
|
---|
569 | {
|
---|
570 | uchar ecm[256];
|
---|
571 | uchar cw[16];
|
---|
572 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
573 | int16_t l;
|
---|
574 | uint16_t caid;
|
---|
575 | uint16_t ocaid; //original caid, used for betatunneling
|
---|
576 | uint16_t srvid;
|
---|
577 | uint16_t chid;
|
---|
578 | uint16_t pid;
|
---|
579 | uint16_t idx;
|
---|
580 | uint32_t prid;
|
---|
581 | struct s_reader *selected_reader;
|
---|
582 | LLIST *matching_rdr; //list of matching readers
|
---|
583 | LL_NODE *fallback; // in *matching_rdr, at position "fallback" the first fallback reader is in the list
|
---|
584 | struct s_client *client; //contains pointer to 'c' client while running in 'r' client
|
---|
585 | int32_t cpti; // client pending table index
|
---|
586 | int32_t stage; // processing stage in server module
|
---|
587 | int32_t level; // send-level in client module
|
---|
588 | int32_t rc;
|
---|
589 | uchar rcEx;
|
---|
590 | struct timeb tps; // incoming time stamp
|
---|
591 | uchar locals_done;
|
---|
592 | int32_t btun; // mark er as betatunneled
|
---|
593 | int32_t reader_avail; //count of available readers
|
---|
594 | int32_t reader_count; //count of contacted readers
|
---|
595 | #ifdef CS_WITH_DOUBLECHECK
|
---|
596 | int32_t checked;
|
---|
597 | uchar cw_checked[16];
|
---|
598 | #endif
|
---|
599 |
|
---|
600 | #ifdef MODULE_CCCAM
|
---|
601 | struct s_reader *origin_reader;
|
---|
602 | void * origin_card; //CCcam preferred card!
|
---|
603 | #endif
|
---|
604 |
|
---|
605 | void *src_data;
|
---|
606 |
|
---|
607 | struct s_ecm *ecmcacheptr; //Pointer to ecm-cw-rc-cache!
|
---|
608 |
|
---|
609 | char msglog[MSGLOGSIZE];
|
---|
610 | } ECM_REQUEST;
|
---|
611 |
|
---|
612 | #ifdef CS_ANTICASC
|
---|
613 | struct s_acasc_shm {
|
---|
614 | uint16_t ac_count : 15;
|
---|
615 | uint16_t ac_deny : 1;
|
---|
616 | };
|
---|
617 |
|
---|
618 | struct s_acasc {
|
---|
619 | uint16_t stat[10];
|
---|
620 | uchar idx; // current active index in stat[]
|
---|
621 | };
|
---|
622 | #endif
|
---|
623 |
|
---|
624 | struct s_client
|
---|
625 | {
|
---|
626 | int8_t init_done;
|
---|
627 | pthread_mutex_t thread_lock;
|
---|
628 | int8_t thread_active;
|
---|
629 | int8_t kill;
|
---|
630 | LLIST *joblist;
|
---|
631 | in_addr_t ip;
|
---|
632 | in_port_t port;
|
---|
633 | time_t login;
|
---|
634 | time_t last;
|
---|
635 | time_t lastswitch;
|
---|
636 | time_t lastemm;
|
---|
637 | time_t lastecm;
|
---|
638 | time_t expirationdate;
|
---|
639 | int32_t allowedtimeframe[2];
|
---|
640 | int8_t c35_suppresscmd08;
|
---|
641 | uint8_t c35_sleepsend;
|
---|
642 | int8_t ncd_keepalive;
|
---|
643 | int8_t disabled;
|
---|
644 | uint64_t grp;
|
---|
645 | int8_t crypted;
|
---|
646 | int8_t dup;
|
---|
647 | LLIST *aureader_list;
|
---|
648 | int8_t autoau;
|
---|
649 | int8_t monlvl;
|
---|
650 | CAIDTAB ctab;
|
---|
651 | TUNTAB ttab;
|
---|
652 | SIDTABBITS sidtabok; // positiv services
|
---|
653 | SIDTABBITS sidtabno; // negative services
|
---|
654 | 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
|
---|
655 | int32_t ctyp;
|
---|
656 | int32_t stat;
|
---|
657 | int32_t last_srvid;
|
---|
658 | int32_t last_caid;
|
---|
659 | struct s_srvid *last_srvidptr;
|
---|
660 | int32_t tosleep;
|
---|
661 | struct s_auth *account;
|
---|
662 | int32_t udp_fd;
|
---|
663 | struct sockaddr_in udp_sa;
|
---|
664 | int32_t log;
|
---|
665 | int32_t logcounter;
|
---|
666 | int32_t cwfound; // count found ECMs per client
|
---|
667 | int32_t cwcache; // count ECMs from cache1/2 per client
|
---|
668 | int32_t cwnot; // count not found ECMs per client
|
---|
669 | int32_t cwtun; // count betatunneled ECMs per client
|
---|
670 | int32_t cwignored; // count ignored ECMs per client
|
---|
671 | int32_t cwtout; // count timeouted ECMs per client
|
---|
672 | int32_t cwlastresptime; //last Responsetime (ms)
|
---|
673 | int32_t cwlastresptimes[CS_ECM_RINGBUFFER_MAX]; //ringbuffer for last 20 times
|
---|
674 | int32_t cwlastresptimes_last; // ringbuffer pointer
|
---|
675 | int32_t emmok; // count EMM ok
|
---|
676 | int32_t emmnok; // count EMM nok
|
---|
677 | int32_t pending; // number of ECMs pending
|
---|
678 | #ifdef WEBIF
|
---|
679 | int8_t wihidden; // hidden in webinterface status
|
---|
680 | char lastreader[64]; // last cw got from this reader
|
---|
681 | #endif
|
---|
682 | uchar ucrc[4]; // needed by monitor and used by camd35
|
---|
683 | uint32_t pcrc; // pwd crc
|
---|
684 | AES_KEY aeskey; // encryption key needed by monitor and used by camd33, camd35
|
---|
685 | AES_KEY aeskey_decrypt; // decryption key needed by monitor and used by camd33, camd35
|
---|
686 | uint16_t ncd_msgid;
|
---|
687 | char ncd_client_id[5];
|
---|
688 | uchar ncd_skey[16];
|
---|
689 |
|
---|
690 | #ifdef MODULE_CCCAM
|
---|
691 | void *cc;
|
---|
692 | #endif
|
---|
693 | #ifdef MODULE_GBOX
|
---|
694 | void *gbox;
|
---|
695 | #endif
|
---|
696 | int32_t port_idx; // index in server ptab
|
---|
697 | int32_t ncd_server; // newcamd server
|
---|
698 | #ifdef CS_ANTICASC
|
---|
699 | uint16_t ac_limit;
|
---|
700 | struct s_acasc_shm acasc;
|
---|
701 | #endif
|
---|
702 | FTAB fchid;
|
---|
703 | FTAB ftab; // user [caid] and ident filter
|
---|
704 | CLASSTAB cltab;
|
---|
705 |
|
---|
706 |
|
---|
707 | int32_t pfd; // Primary FD, must be closed on exit
|
---|
708 | struct s_reader *reader; //points to s_reader when cl->typ='r'
|
---|
709 |
|
---|
710 | ECM_REQUEST *ecmtask;
|
---|
711 | struct s_emm *emmcache;
|
---|
712 |
|
---|
713 | pthread_t thread;
|
---|
714 | pthread_mutex_t **mutexstore;
|
---|
715 | uint16_t mutexstore_alloc;
|
---|
716 | uint16_t mutexstore_used;
|
---|
717 | #ifdef WITH_MUTEXDEBUG
|
---|
718 | char **mutexstore_file;
|
---|
719 | uint16_t *mutexstore_line;
|
---|
720 | #endif
|
---|
721 |
|
---|
722 | struct s_serial_client *serialdata;
|
---|
723 |
|
---|
724 | //reader common
|
---|
725 | int32_t last_idx;
|
---|
726 | uint16_t idx;
|
---|
727 | int32_t rotate;
|
---|
728 |
|
---|
729 | uchar *req;
|
---|
730 |
|
---|
731 | int32_t ncd_proto;
|
---|
732 |
|
---|
733 | //camd35
|
---|
734 | uchar upwd[64];
|
---|
735 | int8_t is_udp;
|
---|
736 | int8_t stopped;
|
---|
737 | int32_t lastcaid;
|
---|
738 | int32_t lastsrvid;
|
---|
739 | int32_t lastpid;
|
---|
740 | time_t emm_last;
|
---|
741 | int8_t disable_counter;
|
---|
742 | uchar lastserial[8];
|
---|
743 |
|
---|
744 | //monitor
|
---|
745 | int32_t auth;
|
---|
746 |
|
---|
747 | //cs_hexdump buffer
|
---|
748 | uchar dump[520];
|
---|
749 |
|
---|
750 | //oscam.c
|
---|
751 | struct timeval tv;
|
---|
752 |
|
---|
753 | //failban value set bitwise - compared with BAN_
|
---|
754 | int32_t failban;
|
---|
755 | int8_t cleaned;
|
---|
756 | struct s_client *next; //make client a linked list
|
---|
757 | };
|
---|
758 |
|
---|
759 |
|
---|
760 | //for viaccess var in s_reader:
|
---|
761 | struct geo_cache
|
---|
762 | {
|
---|
763 | uint32_t provid;
|
---|
764 | uchar geo[256];
|
---|
765 | uchar geo_len;
|
---|
766 | int32_t number_ecm;
|
---|
767 | };
|
---|
768 | // for videoguard in s_reader
|
---|
769 | struct s_CmdTabEntry {
|
---|
770 | unsigned char cla;
|
---|
771 | unsigned char cmd;
|
---|
772 | unsigned char len;
|
---|
773 | unsigned char mode;
|
---|
774 | };
|
---|
775 |
|
---|
776 | struct s_CmdTab {
|
---|
777 | unsigned char index;
|
---|
778 | unsigned char size;
|
---|
779 | unsigned char Nentries;
|
---|
780 | unsigned char dummy;
|
---|
781 | struct s_CmdTabEntry e[1];
|
---|
782 | };
|
---|
783 |
|
---|
784 | struct s_ecmWhitelist {
|
---|
785 | int16_t caid;
|
---|
786 | struct s_ecmWhitelistIdent *idents;
|
---|
787 | struct s_ecmWhitelist *next;
|
---|
788 | };
|
---|
789 |
|
---|
790 | struct s_ecmWhitelistIdent {
|
---|
791 | uint32_t ident;
|
---|
792 | struct s_ecmWhitelistLen *lengths;
|
---|
793 | struct s_ecmWhitelistIdent *next;
|
---|
794 | };
|
---|
795 |
|
---|
796 | struct s_ecmWhitelistLen {
|
---|
797 | int16_t len;
|
---|
798 | struct s_ecmWhitelistLen *next;
|
---|
799 | };
|
---|
800 |
|
---|
801 | //ratelimit
|
---|
802 | struct ecmrl {
|
---|
803 | uint16_t srvid;
|
---|
804 | time_t last;
|
---|
805 | };
|
---|
806 | #define MAXECMRATELIMIT 20
|
---|
807 |
|
---|
808 | struct s_reader //contains device info, reader info and card info
|
---|
809 | {
|
---|
810 | uint32_t auprovid; // AU only for this provid
|
---|
811 | int8_t audisabled; // exclude reader from auto AU
|
---|
812 | int8_t smargopatch;
|
---|
813 | struct s_client * client; //pointer to 'r'client this reader is running in
|
---|
814 | int8_t enable;
|
---|
815 | int8_t available; //Schlocke: New flag for loadbalancing. Only reader if reader supports ph.c_available function
|
---|
816 | int32_t fd_error;
|
---|
817 | uint64_t grp;
|
---|
818 | int32_t fallback;
|
---|
819 | int32_t typ;
|
---|
820 | char label[64];
|
---|
821 | char device[128];
|
---|
822 | void *spec_dev; //pointer to structure that contains specific device data
|
---|
823 | uint16_t slot; //in case of multiple slots like sc8in1; first slot = 1
|
---|
824 | int32_t handle; //device handle
|
---|
825 | int32_t fdmc; //device handle for multicam
|
---|
826 | #ifdef WITH_STAPI
|
---|
827 | uint32_t stsmart_handle; //device handle for stsmart driver
|
---|
828 | #endif
|
---|
829 | char pcsc_name[128];
|
---|
830 | int8_t pcsc_has_card;
|
---|
831 | int32_t detect;
|
---|
832 | int32_t mhz; //actual clock rate of reader in 10khz steps
|
---|
833 | int32_t cardmhz; //standard clock speed your card should have in 10khz steps; normally 357 but for Irdeto cards 600
|
---|
834 | int32_t r_port;
|
---|
835 | char r_usr[64];
|
---|
836 | char r_pwd[64];
|
---|
837 | char l_pwd[64];
|
---|
838 | int32_t l_port;
|
---|
839 | int32_t log_port;
|
---|
840 | CAIDTAB ctab;
|
---|
841 | uint32_t boxid;
|
---|
842 | int8_t nagra_read; // read nagra ncmed records: 0 disabled (default), 1 read all records, 2 read valid records only
|
---|
843 | uchar nagra_boxkey[16]; //n3 boxkey 8byte or tiger idea key 16byte
|
---|
844 | char country_code[3]; // irdeto country code.
|
---|
845 | int8_t force_irdeto;
|
---|
846 | uchar rsa_mod[120]; //rsa modulus for nagra cards.
|
---|
847 | uchar atr[64];
|
---|
848 | int32_t atrlen;
|
---|
849 | SIDTABBITS sidtabok; // positiv services
|
---|
850 | SIDTABBITS sidtabno; // negative services
|
---|
851 | uchar hexserial[8];
|
---|
852 | int32_t nprov;
|
---|
853 | uchar prid[CS_MAXPROV][8];
|
---|
854 | uchar availkeys[CS_MAXPROV][16]; // viaccess; misused in seca, if availkeys[PROV][0]=0 then expired, 1 then valid.
|
---|
855 | uchar sa[CS_MAXPROV][4]; // viaccess & seca
|
---|
856 | uint16_t acs; // irdeto
|
---|
857 | uint16_t caid;
|
---|
858 | uint16_t b_nano;
|
---|
859 | uint16_t s_nano;
|
---|
860 | int32_t blockemm;
|
---|
861 | char * emmfile;
|
---|
862 | char pincode[5];
|
---|
863 | int32_t ucpk_valid;
|
---|
864 | int32_t logemm;
|
---|
865 | int32_t cachemm;
|
---|
866 | int32_t rewritemm;
|
---|
867 | int8_t card_status;
|
---|
868 | int8_t deprecated; //if 0 ATR obeyed, if 1 default speed (9600) is chosen; for devices that cannot switch baudrate
|
---|
869 | struct s_module ph;
|
---|
870 | struct s_cardreader crdr;
|
---|
871 | struct s_cardsystem csystem;
|
---|
872 | uchar ncd_key[16];
|
---|
873 | uchar ncd_skey[16];
|
---|
874 | int8_t ncd_disable_server_filt;
|
---|
875 | uint16_t ncd_msgid;
|
---|
876 | int32_t ncd_proto;
|
---|
877 | #ifdef MODULE_CCCAM
|
---|
878 | char cc_version[7]; // cccam version
|
---|
879 | char cc_build[7]; // cccam build number
|
---|
880 | int8_t cc_maxhop; // cccam max distance
|
---|
881 | int8_t cc_mindown; // cccam min downhops
|
---|
882 | int8_t cc_currenthops; // number of hops for CCCam
|
---|
883 | int8_t cc_want_emu; //Schlocke: Client want to have EMUs, 0 - NO; 1 - YES
|
---|
884 | uint32_t cc_id;
|
---|
885 | int8_t cc_keepalive;
|
---|
886 | int8_t cc_hop; //For non-cccam reader: hop for virtual cards
|
---|
887 | #endif
|
---|
888 | uchar tcp_connected;
|
---|
889 | int32_t tcp_ito; // inactivity timeout
|
---|
890 | int32_t tcp_rto; // reconnect timeout
|
---|
891 | struct timeb tcp_block_connect_till; //time tcp connect ist blocked
|
---|
892 | int32_t tcp_block_delay; //incrementing block time
|
---|
893 | time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect )
|
---|
894 | time_t last_s; // send
|
---|
895 | uchar show_cls; // number of classes subscription showed on kill -31
|
---|
896 | FTAB fchid;
|
---|
897 | FTAB ftab;
|
---|
898 | CLASSTAB cltab;
|
---|
899 | struct s_ecmWhitelist *ecmWhitelist;
|
---|
900 | char *init_history;
|
---|
901 | int32_t init_history_pos;
|
---|
902 | int32_t brk_pos;
|
---|
903 | int32_t msg_idx;
|
---|
904 | #ifdef WEBIF
|
---|
905 | int32_t emmwritten[4]; //count written EMM
|
---|
906 | int32_t emmskipped[4]; //count skipped EMM
|
---|
907 | int32_t emmerror[4]; //count error EMM
|
---|
908 | int32_t emmblocked[4]; //count blocked EMM
|
---|
909 | int32_t lbvalue; //loadbalance Value
|
---|
910 | #endif
|
---|
911 | #ifdef HAVE_PCSC
|
---|
912 | SCARDCONTEXT hContext;
|
---|
913 | SCARDHANDLE hCard;
|
---|
914 | DWORD dwActiveProtocol;
|
---|
915 | #endif
|
---|
916 | #ifdef LIBUSB
|
---|
917 | uint8_t device_endpoint; // usb endpoint for Infinity USB Smart in smartreader mode.
|
---|
918 | struct s_sr_config *sr_config;
|
---|
919 | #endif
|
---|
920 | #ifdef AZBOX
|
---|
921 | int32_t mode;
|
---|
922 | #endif
|
---|
923 | ////variables from icc_async.h start
|
---|
924 | int32_t convention; //Convention of this ICC
|
---|
925 | unsigned char protocol_type; // Type of protocol
|
---|
926 | uint16_t BWT,CWT; // (for overclocking uncorrected) block waiting time, character waiting time, in ETU
|
---|
927 | uint32_t current_baudrate; // (for overclocking uncorrected) baudrate to prevent unnecessary conversions from/to termios structure
|
---|
928 | uint32_t read_timeout; // Max timeout (ms) to receive characters
|
---|
929 | uint32_t block_delay; // Delay (ms) after starting to transmit
|
---|
930 | uint32_t char_delay; // Delay (ms) after transmiting each sucesive char
|
---|
931 | ////variables from io_serial.h
|
---|
932 | int32_t written; //keep score of how much bytes are written to serial port, since they are echoed back they have to be read
|
---|
933 | ////variables from protocol_t1.h
|
---|
934 | uint16_t ifsc; /* Information field size for the ICC */
|
---|
935 | unsigned char ns; /* Send sequence number */
|
---|
936 | ////variables from reader-dre.c
|
---|
937 | unsigned char provider;
|
---|
938 | ////variables from reader-nagra.c
|
---|
939 | IDEA_KEY_SCHEDULE ksSession;
|
---|
940 | int8_t is_pure_nagra;
|
---|
941 | int8_t is_tiger;
|
---|
942 | int8_t is_n3_na;
|
---|
943 | int8_t has_dt08;
|
---|
944 | int8_t swapCW;
|
---|
945 | uint8_t ExpiryDate[2];
|
---|
946 | uint8_t ActivationDate[2];
|
---|
947 | unsigned char rom[15];
|
---|
948 | unsigned char plainDT08RSA[64];
|
---|
949 | unsigned char IdeaCamKey[16];
|
---|
950 | unsigned char irdId[4];
|
---|
951 | unsigned char sessi[16];
|
---|
952 | unsigned char signature[8];
|
---|
953 | unsigned char cam_state[3];
|
---|
954 | ////variables from reader-irdeto.c
|
---|
955 | int32_t acs57; // A flag for the ACS57 ITA DVB-T
|
---|
956 | ////variables from reader-cryptoworks.c
|
---|
957 | BIGNUM exp;
|
---|
958 | BIGNUM ucpk;
|
---|
959 | ////variables from reader-viaccess.c
|
---|
960 | struct geo_cache last_geo;
|
---|
961 | #ifdef MODULE_CCCAM
|
---|
962 | int32_t cc_reshare;
|
---|
963 | #endif
|
---|
964 | #ifdef WITH_LB
|
---|
965 | int32_t lb_weight; //loadbalance weight factor, if unset, weight=100. The higher the value, the higher the usage-possibility
|
---|
966 | int32_t lb_usagelevel; //usagelevel for loadbalancer
|
---|
967 | int32_t lb_usagelevel_ecmcount;
|
---|
968 | time_t lb_usagelevel_time; //time for counting ecms, this creates usagelevel
|
---|
969 | struct timeb lb_last; //time for oldest reader
|
---|
970 | LLIST *lb_stat; //loadbalancer reader statistics
|
---|
971 | #endif
|
---|
972 | // multi AES linked list
|
---|
973 | AES_ENTRY *aes_list;
|
---|
974 | // variables from reader-videoguard*
|
---|
975 | int8_t ndsversion; // 0 auto (default), 1 NDS1, 12 NDS1+, 2 NDS2
|
---|
976 | const char * card_desc;
|
---|
977 | int32_t card_baseyear;
|
---|
978 | int32_t card_tierstart;
|
---|
979 | int32_t card_system_version;
|
---|
980 | struct s_CmdTab *cmd_table;
|
---|
981 | uint16_t cardkeys[3][32];
|
---|
982 | unsigned char stateD3A[16];
|
---|
983 | AES_KEY ekey;
|
---|
984 | AES_KEY astrokey;
|
---|
985 | //ratelimit
|
---|
986 | int32_t ratelimitecm;
|
---|
987 | int32_t ratelimitseconds;
|
---|
988 | struct ecmrl rlecmh[MAXECMRATELIMIT];
|
---|
989 | int8_t fix_9993;
|
---|
990 | struct s_reader *next;
|
---|
991 | };
|
---|
992 |
|
---|
993 | #ifdef CS_ANTICASC
|
---|
994 | struct s_cpmap
|
---|
995 | {
|
---|
996 | uint16_t caid;
|
---|
997 | uint32_t provid;
|
---|
998 | uint16_t sid;
|
---|
999 | uint16_t chid;
|
---|
1000 | uint16_t dwtime;
|
---|
1001 | struct s_cpmap *next;
|
---|
1002 | };
|
---|
1003 | #endif
|
---|
1004 |
|
---|
1005 | struct s_auth
|
---|
1006 | {
|
---|
1007 | char usr[64];
|
---|
1008 | char pwd[64];
|
---|
1009 | #ifdef WEBIF
|
---|
1010 | char description[64];
|
---|
1011 | #endif
|
---|
1012 | int8_t uniq;
|
---|
1013 | LLIST *aureader_list;
|
---|
1014 | int8_t autoau;
|
---|
1015 | int8_t monlvl;
|
---|
1016 | uint64_t grp;
|
---|
1017 | int32_t tosleep;
|
---|
1018 | CAIDTAB ctab;
|
---|
1019 | SIDTABBITS sidtabok; // positiv services
|
---|
1020 | SIDTABBITS sidtabno; // negative services
|
---|
1021 | FTAB fchid;
|
---|
1022 | FTAB ftab; // user [caid] and ident filter
|
---|
1023 | CLASSTAB cltab;
|
---|
1024 | TUNTAB ttab;
|
---|
1025 | #ifdef CS_ANTICASC
|
---|
1026 | int32_t ac_users; // 0 - unlimited
|
---|
1027 | uchar ac_penalty; // 0 - log, >0 - fake dw
|
---|
1028 | struct s_acasc ac_stat;
|
---|
1029 | #endif
|
---|
1030 | in_addr_t dynip;
|
---|
1031 | uchar dyndns[64];
|
---|
1032 | time_t expirationdate;
|
---|
1033 | time_t firstlogin;
|
---|
1034 | int32_t allowedtimeframe[2];
|
---|
1035 | int8_t c35_suppresscmd08;
|
---|
1036 | uint8_t c35_sleepsend;
|
---|
1037 | int8_t ncd_keepalive;
|
---|
1038 | int32_t cccmaxhops;
|
---|
1039 | int32_t cccreshare;
|
---|
1040 | int8_t cccignorereshare;
|
---|
1041 | int8_t cccstealth;
|
---|
1042 | int8_t disabled;
|
---|
1043 | int32_t failban;
|
---|
1044 |
|
---|
1045 | int32_t cwfound;
|
---|
1046 | int32_t cwcache;
|
---|
1047 | int32_t cwnot;
|
---|
1048 | int32_t cwtun;
|
---|
1049 | int32_t cwignored;
|
---|
1050 | int32_t cwtout;
|
---|
1051 | int32_t emmok;
|
---|
1052 | int32_t emmnok;
|
---|
1053 |
|
---|
1054 | struct s_auth *next;
|
---|
1055 | };
|
---|
1056 |
|
---|
1057 | struct s_srvid
|
---|
1058 | {
|
---|
1059 | int32_t srvid;
|
---|
1060 | int32_t ncaid;
|
---|
1061 | int32_t caid[10];
|
---|
1062 | char *data;
|
---|
1063 | char *prov;
|
---|
1064 | char *name;
|
---|
1065 | char *type;
|
---|
1066 | char *desc;
|
---|
1067 | struct s_srvid *next;
|
---|
1068 | };
|
---|
1069 |
|
---|
1070 | struct s_tierid
|
---|
1071 | {
|
---|
1072 | int32_t tierid;
|
---|
1073 | int32_t ncaid;
|
---|
1074 | int32_t caid[10];
|
---|
1075 | char name[33];
|
---|
1076 | struct s_tierid *next;
|
---|
1077 | };
|
---|
1078 |
|
---|
1079 | //Todo #ifdef CCCAM
|
---|
1080 | struct s_provid
|
---|
1081 | {
|
---|
1082 | int32_t caid;
|
---|
1083 | uint32_t provid;
|
---|
1084 | char prov[33];
|
---|
1085 | char sat[33];
|
---|
1086 | char lang[33];
|
---|
1087 | struct s_provid *next;
|
---|
1088 | };
|
---|
1089 |
|
---|
1090 | struct s_ip
|
---|
1091 | {
|
---|
1092 | in_addr_t ip[2];
|
---|
1093 | struct s_ip *next;
|
---|
1094 | };
|
---|
1095 |
|
---|
1096 | struct s_config
|
---|
1097 | {
|
---|
1098 | int32_t nice;
|
---|
1099 | uint32_t netprio;
|
---|
1100 | uint32_t ctimeout;
|
---|
1101 | uint32_t ftimeout;
|
---|
1102 | uint32_t cmaxidle;
|
---|
1103 | int32_t ulparent;
|
---|
1104 | uint32_t delay;
|
---|
1105 | int32_t bindwait;
|
---|
1106 | int32_t tosleep;
|
---|
1107 | in_addr_t srvip;
|
---|
1108 | char *usrfile;
|
---|
1109 | char *cwlogdir;
|
---|
1110 | char *emmlogdir;
|
---|
1111 | char *logfile;
|
---|
1112 | char *mailfile;
|
---|
1113 | uint8_t logtostdout;
|
---|
1114 | uint8_t logtosyslog;
|
---|
1115 | uint32_t loghistorysize;
|
---|
1116 | int8_t disablelog;
|
---|
1117 | int8_t disablemail;
|
---|
1118 | int8_t disableuserfile;
|
---|
1119 | int8_t usrfileflag;
|
---|
1120 | struct s_auth *account;
|
---|
1121 | struct s_srvid *srvid[16];
|
---|
1122 | struct s_tierid *tierid;
|
---|
1123 | //Todo #ifdef CCCAM
|
---|
1124 | struct s_provid *provid;
|
---|
1125 | struct s_sidtab *sidtab;
|
---|
1126 | int32_t mon_port;
|
---|
1127 | in_addr_t mon_srvip;
|
---|
1128 | struct s_ip *mon_allowed;
|
---|
1129 | int32_t mon_aulow;
|
---|
1130 | int32_t mon_hideclient_to;
|
---|
1131 | int32_t mon_level;
|
---|
1132 | int32_t mon_appendchaninfo;
|
---|
1133 | #ifdef WEBIF
|
---|
1134 | int32_t http_port;
|
---|
1135 | char http_user[65];
|
---|
1136 | char http_pwd[65];
|
---|
1137 | char http_css[128];
|
---|
1138 | char http_jscript[128];
|
---|
1139 | char http_tpl[128];
|
---|
1140 | char http_script[128];
|
---|
1141 | int32_t http_refresh;
|
---|
1142 | int8_t http_hide_idle_clients;
|
---|
1143 | struct s_ip *http_allowed;
|
---|
1144 | int8_t http_readonly;
|
---|
1145 | in_addr_t http_dynip;
|
---|
1146 | uchar http_dyndns[64];
|
---|
1147 | int8_t http_use_ssl;
|
---|
1148 | char http_cert[128];
|
---|
1149 | char http_help_lang[3];
|
---|
1150 | #endif
|
---|
1151 | int8_t http_full_cfg;
|
---|
1152 | int32_t failbantime;
|
---|
1153 | int32_t failbancount;
|
---|
1154 | LLIST *v_list; //failban list
|
---|
1155 | int32_t c33_port;
|
---|
1156 | in_addr_t c33_srvip;
|
---|
1157 | uchar c33_key[16];
|
---|
1158 | int32_t c33_crypted;
|
---|
1159 | int32_t c33_passive;
|
---|
1160 | struct s_ip *c33_plain;
|
---|
1161 | int32_t c35_port;
|
---|
1162 | in_addr_t c35_srvip;
|
---|
1163 | int8_t c35_suppresscmd08;
|
---|
1164 | int8_t c35_tcp_suppresscmd08;
|
---|
1165 | int8_t c35_udp_suppresscmd08;
|
---|
1166 | PTAB c35_tcp_ptab;
|
---|
1167 | in_addr_t c35_tcp_srvip;
|
---|
1168 | PTAB ncd_ptab;
|
---|
1169 | in_addr_t ncd_srvip;
|
---|
1170 | uchar ncd_key[16];
|
---|
1171 | int32_t ncd_keepalive;
|
---|
1172 | int8_t ncd_mgclient;
|
---|
1173 | struct s_ip *ncd_allowed;
|
---|
1174 | int32_t rad_port;
|
---|
1175 | in_addr_t rad_srvip;
|
---|
1176 | #ifdef MODULE_CCCAM
|
---|
1177 | uint16_t cc_port[CS_MAXPORTS];
|
---|
1178 | int8_t cc_reshare;
|
---|
1179 | int8_t cc_ignore_reshare;
|
---|
1180 | int32_t cc_update_interval;
|
---|
1181 | in_addr_t cc_srvip;
|
---|
1182 | char cc_version[7];
|
---|
1183 | int8_t cc_minimize_cards;
|
---|
1184 | int8_t cc_keep_connected;
|
---|
1185 | int8_t cc_stealth;
|
---|
1186 | int8_t cc_reshare_services;
|
---|
1187 | int8_t cc_forward_origin_card;
|
---|
1188 | int8_t cc_use_fixed_nodeid;
|
---|
1189 | uint8_t cc_fixed_nodeid[8];
|
---|
1190 | #endif
|
---|
1191 | char gbox_hostname[128];
|
---|
1192 | char gbox_key[9];
|
---|
1193 | char gbox_gsms_path[200];
|
---|
1194 | int32_t gbox_port;
|
---|
1195 | struct s_ip *rad_allowed;
|
---|
1196 | char rad_usr[32];
|
---|
1197 | char ser_device[512];
|
---|
1198 | uint32_t srtimeout; // SerialReaderTimeount in millisec
|
---|
1199 | int32_t max_log_size;
|
---|
1200 | int8_t waitforcards;
|
---|
1201 | int32_t waitforcards_extra_delay;
|
---|
1202 | int8_t preferlocalcards;
|
---|
1203 | int8_t saveinithistory;
|
---|
1204 | int32_t reader_restart_seconds; //schlocke: reader restart auf x seconds, disable = 0
|
---|
1205 | int8_t dropdups; //drop duplicate logins
|
---|
1206 |
|
---|
1207 |
|
---|
1208 | //Loadbalancer-Config:
|
---|
1209 | #ifdef WITH_LB
|
---|
1210 | int32_t lb_mode; //schlocke: reader loadbalancing mode
|
---|
1211 | int32_t lb_save; //schlocke: load/save statistics to file, save every x ecms
|
---|
1212 | int32_t lb_nbest_readers; // count of best readers
|
---|
1213 | int32_t lb_nfb_readers; // count of fallback readers
|
---|
1214 | int32_t lb_min_ecmcount; // minimal ecm count to evaluate lbvalues
|
---|
1215 | int32_t lb_max_ecmcount; // maximum ecm count before reseting lbvalues
|
---|
1216 | int32_t lb_reopen_seconds; //time between retrying failed readers/caids/prov/srv
|
---|
1217 | int32_t lb_retrylimit; //reopen only happens if reader response time > retrylimit
|
---|
1218 | CAIDVALUETAB lb_retrylimittab;
|
---|
1219 | CAIDVALUETAB lb_nbest_readers_tab; //like nbest_readers, but for special caids
|
---|
1220 | CAIDTAB lb_noproviderforcaid; //do not store loadbalancer stats with providers for this caid
|
---|
1221 | char *lb_savepath; //path where the stat file is save. Empty=default=/tmp/.oscam/stat
|
---|
1222 | int32_t lb_stat_cleanup; //duration in hours for cleaning old statistics
|
---|
1223 | int32_t lb_use_locking; //use a mutex lock while searching for readers (get_cw())
|
---|
1224 | int32_t lb_reopen_mode; //reopen readers mode
|
---|
1225 | int32_t lb_max_readers; //limit the amount of readers during learning
|
---|
1226 | int32_t lb_auto_betatunnel; //automatic selection of betatunnel convertion based on learned data
|
---|
1227 | #endif
|
---|
1228 | int32_t resolve_gethostbyname;
|
---|
1229 |
|
---|
1230 | #ifdef CS_WITH_DOUBLECHECK
|
---|
1231 | int8_t double_check; //schlocke: Double checks each ecm+dcw from two (or more) readers
|
---|
1232 | #endif
|
---|
1233 |
|
---|
1234 | #ifdef IRDETO_GUESSING
|
---|
1235 | struct s_irdeto_quess *itab[0xff];
|
---|
1236 | #endif
|
---|
1237 |
|
---|
1238 | #ifdef HAVE_DVBAPI
|
---|
1239 | int8_t dvbapi_enabled;
|
---|
1240 | int8_t dvbapi_au;
|
---|
1241 | char dvbapi_usr[64];
|
---|
1242 | int8_t dvbapi_boxtype;
|
---|
1243 | int8_t dvbapi_pmtmode;
|
---|
1244 | int8_t dvbapi_requestmode;
|
---|
1245 | SIDTABBITS dvbapi_sidtabok; // positiv services
|
---|
1246 | SIDTABBITS dvbapi_sidtabno; // negative services
|
---|
1247 | #endif
|
---|
1248 |
|
---|
1249 | #ifdef CS_ANTICASC
|
---|
1250 | char ac_enabled;
|
---|
1251 | int32_t ac_users; // num of users for account (0 - default)
|
---|
1252 | int32_t ac_stime; // time to collect AC statistics (3 min - default)
|
---|
1253 | int32_t ac_samples; // qty of samples
|
---|
1254 | int32_t ac_penalty; // 0 - write to log
|
---|
1255 | int32_t ac_fakedelay; // 100-1000 ms
|
---|
1256 | int32_t ac_denysamples;
|
---|
1257 | char ac_logfile[128];
|
---|
1258 | struct s_cpmap *cpmap;
|
---|
1259 | #endif
|
---|
1260 |
|
---|
1261 | #ifdef QBOXHD_LED
|
---|
1262 | int8_t disableqboxhdled; // disable qboxhd led , default = 0
|
---|
1263 | #endif
|
---|
1264 |
|
---|
1265 | #ifdef LCDSUPPORT
|
---|
1266 | char *lcd_output_path;
|
---|
1267 | int32_t lcd_hide_idle;
|
---|
1268 | int32_t lcd_write_intervall;
|
---|
1269 | #endif
|
---|
1270 |
|
---|
1271 | };
|
---|
1272 |
|
---|
1273 | struct s_clientinit
|
---|
1274 | {
|
---|
1275 | void *(*handler)(struct s_client*);
|
---|
1276 | struct s_client * client;
|
---|
1277 | };
|
---|
1278 |
|
---|
1279 | struct s_data {
|
---|
1280 | int action;
|
---|
1281 | struct s_reader *rdr;
|
---|
1282 | struct s_client *cl;
|
---|
1283 | void *ptr;
|
---|
1284 | uint16_t len;
|
---|
1285 | };
|
---|
1286 |
|
---|
1287 | typedef struct reader_stat_t
|
---|
1288 | {
|
---|
1289 | int32_t rc;
|
---|
1290 | uint16_t caid;
|
---|
1291 | uint32_t prid;
|
---|
1292 | uint16_t srvid;
|
---|
1293 | int16_t ecmlen;
|
---|
1294 |
|
---|
1295 | time_t last_received;
|
---|
1296 |
|
---|
1297 | int32_t ecm_count;
|
---|
1298 | int32_t time_avg;
|
---|
1299 | int32_t time_stat[LB_MAX_STAT_TIME];
|
---|
1300 | int32_t time_idx;
|
---|
1301 |
|
---|
1302 | int32_t fail_factor;
|
---|
1303 | } READER_STAT;
|
---|
1304 |
|
---|
1305 | typedef struct emm_packet_t
|
---|
1306 | {
|
---|
1307 | uchar emm[258];
|
---|
1308 | uchar l;
|
---|
1309 | uchar caid[2];
|
---|
1310 | uchar provid[4];
|
---|
1311 | uchar hexserial[8]; //contains hexserial or SA of EMM
|
---|
1312 | uchar type;
|
---|
1313 | struct s_client *client;
|
---|
1314 | } EMM_PACKET;
|
---|
1315 |
|
---|
1316 | #ifdef QBOXHD_LED
|
---|
1317 | typedef struct {
|
---|
1318 | uint16_t H; // range 0-359
|
---|
1319 | unsigned char S; // range 0-99
|
---|
1320 | unsigned char V; // range 0-99
|
---|
1321 | } qboxhd_led_color_struct;
|
---|
1322 | typedef struct {
|
---|
1323 | unsigned char red; // first 5 bit used (&0x1F)
|
---|
1324 | unsigned char green; // first 5 bit used (&0x1F)
|
---|
1325 | unsigned char blue; // first 5 bit used (&0x1F)
|
---|
1326 | } qboxhdmini_led_color_struct;
|
---|
1327 | #endif
|
---|
1328 |
|
---|
1329 |
|
---|
1330 | /* ===========================
|
---|
1331 | * global variables
|
---|
1332 | * =========================== */
|
---|
1333 | extern char cs_tmpdir[200];
|
---|
1334 | extern pthread_key_t getclient;
|
---|
1335 | extern struct s_client *first_client;
|
---|
1336 | extern struct s_reader *first_active_reader; //points to list of _active_ readers (enable = 1, deleted = 0)
|
---|
1337 | extern LLIST *configured_readers;
|
---|
1338 | extern int32_t cs_dblevel;
|
---|
1339 | extern uint16_t len4caid[256];
|
---|
1340 | extern struct s_config cfg;
|
---|
1341 | extern char cs_confdir[];
|
---|
1342 | extern char *loghist, *loghistptr;
|
---|
1343 | extern struct s_module ph[CS_MAX_MOD];
|
---|
1344 | extern struct s_cardsystem cardsystem[CS_MAX_MOD];
|
---|
1345 | extern struct s_cardreader cardreader[CS_MAX_MOD];
|
---|
1346 | extern pthread_mutex_t gethostbyname_lock;
|
---|
1347 |
|
---|
1348 | pid_t server_pid; // PID of server - set while startup
|
---|
1349 |
|
---|
1350 | #ifdef CS_ANTICASC
|
---|
1351 | extern FILE *fpa;
|
---|
1352 | #endif
|
---|
1353 |
|
---|
1354 | /* ===========================
|
---|
1355 | * global functions
|
---|
1356 | * =========================== */
|
---|
1357 | #include "global-functions.h"
|
---|
1358 |
|
---|
1359 | #endif // CS_GLOBALS
|
---|