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 |
|
---|
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 |
|
---|
29 | #include <pthread.h>
|
---|
30 |
|
---|
31 | //for reader-nagra variables in s_reader:
|
---|
32 | #include "cscrypt/idea.h"
|
---|
33 |
|
---|
34 | #ifndef CS_GLOBALS
|
---|
35 | #define CS_GLOBALS
|
---|
36 | #define CS_VERSION "0.99.4svn"
|
---|
37 | #ifndef CS_SVN_VERSION
|
---|
38 | # define CS_SVN_VERSION "test"
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | #if defined(__GNUC__)
|
---|
42 | # define GCC_PACK __attribute__((packed))
|
---|
43 | #else
|
---|
44 | # define GCC_PACK
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #define call(arg) \
|
---|
48 | if (arg) { \
|
---|
49 | cs_debug_mask(D_TRACE, "ERROR, function call %s returns error.",#arg); \
|
---|
50 | return ERROR; \
|
---|
51 | }
|
---|
52 |
|
---|
53 | #include "oscam-config.h"
|
---|
54 | #ifndef USE_CMAKE
|
---|
55 | # include "oscam-ostype.h"
|
---|
56 | #endif
|
---|
57 | #include "oscam-types.h"
|
---|
58 | #include "cscrypt/cscrypt.h"
|
---|
59 |
|
---|
60 | #ifdef HAVE_PCSC
|
---|
61 | #ifdef OS_CYGWIN32
|
---|
62 | #define __reserved
|
---|
63 | #define __nullnullterminated
|
---|
64 | #include <specstrings.h>
|
---|
65 | #include "cygwin/WinSCard.h"
|
---|
66 | #else
|
---|
67 | #include <PCSC/pcsclite.h>
|
---|
68 | #ifdef OS_MACOSX
|
---|
69 | #include <PCSC/wintypes.h>
|
---|
70 | #else
|
---|
71 | #include <PCSC/reader.h>
|
---|
72 | #endif
|
---|
73 | #endif
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #if defined(LIBUSB)
|
---|
77 | #include <libusb-1.0/libusb.h>
|
---|
78 | #include "csctapi/smartreader_types.h"
|
---|
79 | #endif
|
---|
80 |
|
---|
81 | #ifndef CS_CONFDIR
|
---|
82 | #define CS_CONFDIR "/usr/local/etc"
|
---|
83 | #endif
|
---|
84 | #ifndef CS_MMAPFILE
|
---|
85 | #define CS_MMAPFILE "/tmp/oscam.mem"
|
---|
86 | #endif
|
---|
87 | #ifndef CS_LOGFILE
|
---|
88 | #define CS_LOGFILE "/var/log/oscam.log"
|
---|
89 | #endif
|
---|
90 | #define CS_QLEN 128 // size of request queue
|
---|
91 | #define CS_MAXQLEN 128 // size of request queue for cardreader
|
---|
92 | #define CS_MAXCAIDTAB 32 // max. caid-defs/user
|
---|
93 | #define CS_MAXTUNTAB 16 // max. betatunnel mappings
|
---|
94 | #define CS_MAXPROV 32
|
---|
95 | #define CS_MAXPORTS 32 // max server ports
|
---|
96 | #define CS_MAXFILTERS 16
|
---|
97 |
|
---|
98 | #define CS_MAXCARDS 4096
|
---|
99 | #define CS_MAXIGNORE 1024
|
---|
100 | #define CS_MAXLOCALS 16
|
---|
101 | #define CS_ECMSTORESIZE 16 // use MD5()
|
---|
102 | #define CS_EMMSTORESIZE 270
|
---|
103 | #define CS_CLIENT_TIMEOUT 5000
|
---|
104 | #define CS_CLIENT_MAXIDLE 120
|
---|
105 | #define CS_BIND_TIMEOUT 120
|
---|
106 | #define CS_DELAY 0
|
---|
107 | #define CS_RESOLVE_DELAY 30
|
---|
108 | #define CS_MAXLOGHIST 30
|
---|
109 | #define CS_LOGHISTSIZE 193 // 32+128+33: username + logline + channelname
|
---|
110 | #define CS_MAXREADERCAID 16
|
---|
111 |
|
---|
112 | #ifdef CS_EMBEDDED
|
---|
113 | #define CS_MAXPID 32
|
---|
114 | #define CS_MAXREADER (CS_MAXPID>>1)
|
---|
115 | #define CS_MAXPENDING CS_MAXPID
|
---|
116 | #define CS_ECMCACHESIZE CS_MAXPID
|
---|
117 | #define CS_EMMCACHESIZE (CS_MAXPID<<1)
|
---|
118 | #else
|
---|
119 | #define CS_MAXPID 512
|
---|
120 | #define CS_MAXREADER (CS_MAXPID>>2)
|
---|
121 | #define CS_MAXPENDING (CS_MAXPID<<1)
|
---|
122 | #define CS_ECMCACHESIZE CS_MAXPID
|
---|
123 | #define CS_EMMCACHESIZE (CS_MAXPID<<1)
|
---|
124 | #define CS_RDR_INIT_HIST
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | #define D_TRACE 1 // Generate very detailed error/trace messages per routine
|
---|
128 | #define D_ATR 2 // Debug ATR parsing, dump of ecm, cw
|
---|
129 | #define D_READER 4 // Debug Reader/Proxy Process
|
---|
130 | #define D_CLIENT 8 // Debug Client Process
|
---|
131 | #define D_IFD 16 // Debug IFD+protocol
|
---|
132 | #define D_DEVICE 32 // Debug Reader I/O
|
---|
133 | #define D_EMM 64 // Dumps EMM
|
---|
134 | #define D_FUT 128 // Reserved for future use
|
---|
135 | #define D_ALL_DUMP 255 // dumps all
|
---|
136 |
|
---|
137 | #define R_DB2COM1 0x1 // Reader Dbox2 @ com1
|
---|
138 | #define R_DB2COM2 0x2 // Reader Dbox2 @ com1
|
---|
139 | #define R_SC8in1 0x3 // Reader smartcard mouse
|
---|
140 | #define R_MOUSE 0x4 // Reader smartcard mouse
|
---|
141 | /////////////////// phoenix readers which need baudrate setting and timings need to be guarded by OSCam: BEFORE R_MOUSE
|
---|
142 | #define R_INTERNAL 0x5 // Reader smartcard intern
|
---|
143 | /////////////////// internal readers (Dreambox, Coolstream, IPBox) are all R_INTERNAL, they are determined compile-time
|
---|
144 | /////////////////// readers that do not reed baudrate setting and timings are guarded by reader itself (large buffer built in): AFTER R_SMART
|
---|
145 | #define R_SMART 0x6 // Smartreader+
|
---|
146 | #define R_PCSC 0x7 // PCSC
|
---|
147 | /////////////////// proxy readers after R_CS378X
|
---|
148 | #define R_CAMD35 0x10 // Reader cascading camd 3.5x
|
---|
149 | #define R_CAMD33 0x11 // Reader cascading camd 3.3x
|
---|
150 | #define R_NEWCAMD 0x12 // Reader cascading newcamd
|
---|
151 | #define R_RADEGAST 0x13 // Reader cascading radegast
|
---|
152 | #define R_CS378X 0x14 // Reader cascading camd 3.5x TCP
|
---|
153 | #define R_CONSTCW 0x15 // Reader for Constant CW
|
---|
154 | /////////////////// peer to peer proxy readers after R_CCCAM
|
---|
155 | #ifdef CS_WITH_GBOX
|
---|
156 | #define R_GBOX 0x20 // Reader cascading gbox
|
---|
157 | #endif
|
---|
158 | #define R_CCCAM 0x25 // Reader cascading cccam
|
---|
159 | #define R_SERIAL 0x80 // Reader serial
|
---|
160 | #define R_IS_NETWORK 0x70
|
---|
161 | #define R_IS_CASCADING 0xF0
|
---|
162 |
|
---|
163 |
|
---|
164 | #define CS_MAX_MOD 12
|
---|
165 | #define MOD_CONN_TCP 1
|
---|
166 | #define MOD_CONN_UDP 2
|
---|
167 | #define MOD_CONN_NET 3
|
---|
168 | #define MOD_CONN_SERIAL 4
|
---|
169 | #define MOD_NO_CONN 8
|
---|
170 |
|
---|
171 | #ifdef HAVE_DVBAPI
|
---|
172 | #define BOXTYPE_DREAMBOX 1
|
---|
173 | #define BOXTYPE_DUCKBOX 2
|
---|
174 | #define BOXTYPE_UFS910 3
|
---|
175 | #define BOXTYPE_DBOX2 4
|
---|
176 | #define BOXTYPE_IPBOX 5
|
---|
177 | #define BOXTYPE_IPBOX_PMT 6
|
---|
178 | #define BOXTYPES 6
|
---|
179 | extern char *boxdesc[];
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | #ifdef CS_CORE
|
---|
183 | char *PIP_ID_TXT[] = { "ECM", "EMM", "LOG", "CIN", "HUP", "RST", "KCL", "STA", "BES", "RES", NULL };
|
---|
184 | char *RDR_CD_TXT[] = { "cd", "dsr", "cts", "ring", "none",
|
---|
185 | #ifdef USE_GPIO
|
---|
186 | "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", //felix: changed so that gpio can be used
|
---|
187 | #endif
|
---|
188 | NULL };
|
---|
189 | #else
|
---|
190 | extern char *PIP_ID_TXT[];
|
---|
191 | extern char *RDR_CD_TXT[];
|
---|
192 | #endif
|
---|
193 |
|
---|
194 | #define PIP_ID_ECM 0
|
---|
195 | #define PIP_ID_EMM 1
|
---|
196 | #define PIP_ID_LOG 2
|
---|
197 | #define PIP_ID_CIN 3 // CARD_INFO
|
---|
198 | #define PIP_ID_HUP 4
|
---|
199 | #define PIP_ID_RST 5 // Schlocke: Restart Reader, CCcam for example (param: ridx)
|
---|
200 | #define PIP_ID_KCL 6 // Schlocke: Kill all Clients (no param)
|
---|
201 | #define PIP_ID_STA 7 // Schlocke: Add statistic (param: ADD_READER_STAT)
|
---|
202 | #define PIP_ID_BES 8 // Schlocke: Get best reader (param ECM_REQUEST, return to client with data int ridx)
|
---|
203 | #define PIP_ID_RES 9 // Schlocke: reset reader statistiks
|
---|
204 | #define PIP_ID_DCW 10
|
---|
205 | #define PIP_ID_MAX PIP_ID_RES
|
---|
206 |
|
---|
207 |
|
---|
208 | #define PIP_ID_ERR (-1)
|
---|
209 | #define PIP_ID_DIR (-2)
|
---|
210 | #define PIP_ID_NUL (-3)
|
---|
211 |
|
---|
212 | #define cdiff *c_start
|
---|
213 |
|
---|
214 | #define NCD_AUTO 0
|
---|
215 | #define NCD_524 1
|
---|
216 | #define NCD_525 2
|
---|
217 |
|
---|
218 | #define CS_ANTICASC
|
---|
219 |
|
---|
220 | // moved from reader-common.h
|
---|
221 | #define NO_CARD 0
|
---|
222 | #define CARD_NEED_INIT 1
|
---|
223 | #define CARD_INSERTED 2
|
---|
224 | #define CARD_FAILURE 3
|
---|
225 |
|
---|
226 | enum {E1_GLOBAL=0, E1_USER, E1_READER, E1_SERVER, E1_LSERVER};
|
---|
227 | enum {E2_GLOBAL=0, E2_GROUP, E2_CAID, E2_IDENT, E2_CLASS, E2_CHID, E2_QUEUE,
|
---|
228 | E2_EA_LEN, E2_F0_LEN, E2_OFFLINE, E2_SID};
|
---|
229 |
|
---|
230 | //typedef unsigned char uchar;
|
---|
231 | //typedef unsigned long ulong;
|
---|
232 |
|
---|
233 | typedef unsigned char uint8;
|
---|
234 | typedef unsigned short uint16;
|
---|
235 | typedef unsigned int uint32;
|
---|
236 | typedef unsigned long long uint64;
|
---|
237 |
|
---|
238 | // constants
|
---|
239 | #define CTA_RES_LEN 512
|
---|
240 |
|
---|
241 | #ifdef CS_LED
|
---|
242 | #define LED1A 0
|
---|
243 | #define LED1B 1
|
---|
244 | #define LED2 2
|
---|
245 | #define LED3 3
|
---|
246 | #define LED_OFF 0
|
---|
247 | #define LED_ON 1
|
---|
248 | #define LED_BLINK_ON 2
|
---|
249 | #define LED_BLINK_OFF 3
|
---|
250 | #define LED_DEFAULT 10
|
---|
251 | extern void cs_switch_led(int led, int action);
|
---|
252 | #endif
|
---|
253 |
|
---|
254 | typedef struct s_classtab
|
---|
255 | {
|
---|
256 | uchar an;
|
---|
257 | uchar bn;
|
---|
258 | uchar aclass[31];
|
---|
259 | uchar bclass[31];
|
---|
260 | } GCC_PACK CLASSTAB;
|
---|
261 |
|
---|
262 | typedef struct s_caidtab
|
---|
263 | {
|
---|
264 | ushort caid[CS_MAXCAIDTAB];
|
---|
265 | ushort mask[CS_MAXCAIDTAB];
|
---|
266 | ushort cmap[CS_MAXCAIDTAB];
|
---|
267 | } GCC_PACK CAIDTAB;
|
---|
268 |
|
---|
269 | typedef struct s_tuntab
|
---|
270 | {
|
---|
271 | ushort bt_caidfrom[CS_MAXTUNTAB];
|
---|
272 | ushort bt_caidto[CS_MAXTUNTAB];
|
---|
273 | ushort bt_srvid[CS_MAXTUNTAB];
|
---|
274 | } GCC_PACK TUNTAB;
|
---|
275 |
|
---|
276 | typedef struct s_sidtab
|
---|
277 | {
|
---|
278 | char label[33];
|
---|
279 | ushort num_caid;
|
---|
280 | ushort num_provid;
|
---|
281 | ushort num_srvid;
|
---|
282 | ushort *caid;
|
---|
283 | ulong *provid;
|
---|
284 | ushort *srvid;
|
---|
285 | struct s_sidtab *next;
|
---|
286 | } GCC_PACK SIDTAB;
|
---|
287 |
|
---|
288 |
|
---|
289 | typedef struct s_filter
|
---|
290 | {
|
---|
291 | ushort caid;
|
---|
292 | uchar nprids;
|
---|
293 | ulong prids[CS_MAXPROV];
|
---|
294 | } GCC_PACK FILTER;
|
---|
295 |
|
---|
296 | typedef struct s_ftab
|
---|
297 | {
|
---|
298 | int nfilts;
|
---|
299 | FILTER filts[CS_MAXFILTERS];
|
---|
300 | } GCC_PACK FTAB;
|
---|
301 |
|
---|
302 | typedef struct s_port
|
---|
303 | {
|
---|
304 | int fd;
|
---|
305 | int s_port;
|
---|
306 | FTAB ftab;
|
---|
307 | } GCC_PACK PORT;
|
---|
308 |
|
---|
309 | typedef struct s_ptab
|
---|
310 | {
|
---|
311 | int nports;
|
---|
312 | PORT ports[CS_MAXPORTS];
|
---|
313 | } GCC_PACK PTAB;
|
---|
314 |
|
---|
315 | #if defined(LIBUSB)
|
---|
316 | typedef struct {
|
---|
317 | int F;
|
---|
318 | float D;
|
---|
319 | int fs;
|
---|
320 | int N;
|
---|
321 | int T;
|
---|
322 | int inv;
|
---|
323 | int parity;
|
---|
324 | int irdeto;
|
---|
325 | int running;
|
---|
326 | libusb_device *usb_dev;
|
---|
327 | libusb_device_handle *usb_dev_handle;
|
---|
328 | enum smartreader_chip_type type;
|
---|
329 | int in_ep; // 0x01
|
---|
330 | int out_ep; // 0x82
|
---|
331 | int index;
|
---|
332 | /** usb read timeout */
|
---|
333 | int usb_read_timeout;
|
---|
334 | /** usb write timeout */
|
---|
335 | int usb_write_timeout;
|
---|
336 | unsigned int writebuffer_chunksize;
|
---|
337 | unsigned char bitbang_enabled;
|
---|
338 | int baudrate;
|
---|
339 | int interface; // 0 or 1
|
---|
340 | /** maximum packet size. Needed for filtering modem status bytes every n packets. */
|
---|
341 | unsigned int max_packet_size;
|
---|
342 | unsigned char g_read_buffer[4096];
|
---|
343 | unsigned int g_read_buffer_size;
|
---|
344 | pthread_mutex_t g_read_mutex;
|
---|
345 | pthread_mutex_t g_usb_mutex;
|
---|
346 | pthread_t rt;
|
---|
347 | unsigned char modem_status;
|
---|
348 | } SR_CONFIG;
|
---|
349 | #endif
|
---|
350 |
|
---|
351 | typedef struct aes_entry {
|
---|
352 | ushort keyid;
|
---|
353 | ushort caid;
|
---|
354 | uint32 ident;
|
---|
355 | AES_KEY key;
|
---|
356 | struct aes_entry *next;
|
---|
357 | } AES_ENTRY;
|
---|
358 |
|
---|
359 | struct s_ecm
|
---|
360 | {
|
---|
361 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
362 | uchar cw[16];
|
---|
363 | ushort caid;
|
---|
364 | ulong grp;
|
---|
365 | //int level;
|
---|
366 | };
|
---|
367 |
|
---|
368 | struct s_emm
|
---|
369 | {
|
---|
370 | uchar emm[CS_EMMSTORESIZE];
|
---|
371 | uchar type;
|
---|
372 | int count;
|
---|
373 | };
|
---|
374 |
|
---|
375 | #define AVAIL_CHECK_CONNECTED 0
|
---|
376 | #define AVAIL_CHECK_LOADBALANCE 1
|
---|
377 |
|
---|
378 | struct s_module
|
---|
379 | {
|
---|
380 | //int fd;
|
---|
381 | int multi;
|
---|
382 | int type;
|
---|
383 | int watchdog;
|
---|
384 | char desc[16];
|
---|
385 | char *logtxt;
|
---|
386 | //int s_port;
|
---|
387 | in_addr_t s_ip;
|
---|
388 | void (*s_handler)();
|
---|
389 | int (*recv)();
|
---|
390 | void (*send_dcw)();
|
---|
391 | void (*cleanup)();
|
---|
392 | int c_multi;
|
---|
393 | int (*c_recv_chk)();
|
---|
394 | int (*c_init)();
|
---|
395 | int (*c_send_ecm)();
|
---|
396 | int (*c_send_emm)();
|
---|
397 | int (*c_init_log)();
|
---|
398 | int (*c_recv_log)();
|
---|
399 | int (*c_available)(); //Schlocke: available check for load-balancing,
|
---|
400 | //params:
|
---|
401 | //int ridx (reader to check)
|
---|
402 | //int checktype (0=return connected, 1=return loadbalance-avail) return int
|
---|
403 | void (*c_idle)(); //Schlocke: called when reader is idle
|
---|
404 | int c_port;
|
---|
405 | PTAB *ptab;
|
---|
406 | };
|
---|
407 |
|
---|
408 | #ifdef IRDETO_GUESSING
|
---|
409 | struct s_irdeto_quess
|
---|
410 | {
|
---|
411 | int b47;
|
---|
412 | ushort caid;
|
---|
413 | ushort sid;
|
---|
414 | struct s_irdeto_quess *next;
|
---|
415 | };
|
---|
416 | #endif
|
---|
417 |
|
---|
418 | struct s_client
|
---|
419 | {
|
---|
420 | pid_t pid;
|
---|
421 | in_addr_t ip;
|
---|
422 | in_port_t port;
|
---|
423 | time_t login;
|
---|
424 | time_t last;
|
---|
425 | time_t lastswitch;
|
---|
426 | time_t lastemm;
|
---|
427 | time_t lastecm;
|
---|
428 | time_t expirationdate;
|
---|
429 | int c35_suppresscmd08;
|
---|
430 | int c35_sleepsend;
|
---|
431 | int ncd_keepalive;
|
---|
432 | int disabled;
|
---|
433 | ulong grp;
|
---|
434 | int crypted;
|
---|
435 | int dup;
|
---|
436 | int au;
|
---|
437 | int autoau;
|
---|
438 | int monlvl;
|
---|
439 | int dbglvl;
|
---|
440 | CAIDTAB ctab;
|
---|
441 | TUNTAB ttab;
|
---|
442 | ulong sidtabok; // positiv services
|
---|
443 | ulong sidtabno; // negative services
|
---|
444 | int typ;
|
---|
445 | int ctyp;
|
---|
446 | int stat;
|
---|
447 | int ufd;
|
---|
448 | int last_srvid;
|
---|
449 | int last_caid;
|
---|
450 | int tosleep;
|
---|
451 | char usr[32];
|
---|
452 | int udp_fd;
|
---|
453 | int fd_m2c; //master writes to this fd
|
---|
454 | int fd_m2c_c; //client reads from this fd
|
---|
455 | struct sockaddr_in udp_sa;
|
---|
456 | int log;
|
---|
457 | int logcounter;
|
---|
458 | int cwfound; // count found ECMs per client
|
---|
459 | int cwcache; // count ECMs from cache1/2 per client
|
---|
460 | int cwnot; // count not found ECMs per client
|
---|
461 | int cwtun; // count betatunneled ECMs per client
|
---|
462 | int cwignored; // count ignored ECMs per client
|
---|
463 | int cwtout; // count timeouted ECMs per client
|
---|
464 | int cwlastresptime; //last Responsetime (ms)
|
---|
465 | int emmok; // count EMM ok
|
---|
466 | int emmnok; // count EMM nok
|
---|
467 | #ifdef WEBIF
|
---|
468 | int wihidden; // hidden in webinterface status
|
---|
469 | char lastreader[32]; // last cw got from this reader
|
---|
470 | #endif
|
---|
471 | uchar ucrc[4]; // needed by monitor and used by camd35
|
---|
472 | ulong pcrc; // pwd crc
|
---|
473 | AES_KEY aeskey; // needed by monitor and used by camd33, camd35
|
---|
474 | ushort ncd_msgid;
|
---|
475 | uchar ncd_skey[16];
|
---|
476 | void *cc;
|
---|
477 | int port_idx; // index in server ptab
|
---|
478 | int ncd_server; // newcamd server
|
---|
479 | #ifdef CS_ANTICASC
|
---|
480 | ushort ac_idx;
|
---|
481 | ushort ac_limit;
|
---|
482 | uchar ac_penalty;
|
---|
483 | #endif
|
---|
484 | FTAB fchid;
|
---|
485 | FTAB ftab; // user [caid] and ident filter
|
---|
486 | CLASSTAB cltab;
|
---|
487 | };
|
---|
488 |
|
---|
489 | //for viaccess var in s_reader:
|
---|
490 | struct geo_cache
|
---|
491 | {
|
---|
492 | ulong provid;
|
---|
493 | uchar geo[256];
|
---|
494 | uchar geo_len;
|
---|
495 | };
|
---|
496 |
|
---|
497 | struct s_reader //contains device info, reader info and card info
|
---|
498 | {
|
---|
499 | ulong auprovid; // AU only for this provid
|
---|
500 | int audisabled; // exclude reader from auto AU
|
---|
501 | int deleted; // if this flag is set the reader is not shown in webif and becomes not writte to oscam.server
|
---|
502 | int smargopatch;
|
---|
503 | int pid;
|
---|
504 | int cs_idx;
|
---|
505 | int ridx; //FIXME reader[ridx] reader has to know what number it is, should be replaced by storing pointer to reader instead of array index
|
---|
506 | int enable;
|
---|
507 | int available; //Schlocke: New flag for loadbalancing. Only reader if reader supports ph.c_available function
|
---|
508 | int fd_error;
|
---|
509 | int fd;
|
---|
510 | ulong grp;
|
---|
511 | int fallback;
|
---|
512 | int typ;
|
---|
513 | int card_system;
|
---|
514 | char label[32];
|
---|
515 | char device[128];
|
---|
516 | ushort slot; //in case of multiple slots like sc8in1; first slot = 1
|
---|
517 | int handle; //device handle
|
---|
518 | #ifdef ST_LINUX
|
---|
519 | unsigned int stsmart_handle; //device handle for stsmart driver
|
---|
520 | #endif
|
---|
521 | char pcsc_name[128];
|
---|
522 | int pcsc_has_card;
|
---|
523 | int detect;
|
---|
524 | int mhz; //actual clock rate of reader in 10khz steps
|
---|
525 | int cardmhz; //standard clock speed your card should have in 10khz steps; normally 357 but for Irdeto cards 600
|
---|
526 | int r_port;
|
---|
527 | char r_usr[64];
|
---|
528 | char r_pwd[64];
|
---|
529 | int r_crypted;
|
---|
530 | int l_port;
|
---|
531 | int log_port;
|
---|
532 | CAIDTAB ctab;
|
---|
533 | ulong boxid;
|
---|
534 | uchar nagra_boxkey[16]; //n3 boxkey 8byte or tiger idea key 16byte
|
---|
535 | int has_rsa;
|
---|
536 | char country_code[3]; // irdeto country code.
|
---|
537 | int force_irdeto;
|
---|
538 | uchar aes_key[16];
|
---|
539 | uchar rsa_mod[120]; //rsa modulus for nagra cards.
|
---|
540 | uchar atr[64];
|
---|
541 | int atrlen;
|
---|
542 | ulong sidtabok; // positiv services
|
---|
543 | ulong sidtabno; // negative services
|
---|
544 | uchar hexserial[8];
|
---|
545 | int nprov;
|
---|
546 | uchar prid[CS_MAXPROV][8];
|
---|
547 | uchar availkeys[CS_MAXPROV][16]; // viaccess; misused in seca, if availkeys[PROV][0]=0 then expired, 1 then valid.
|
---|
548 | uchar sa[CS_MAXPROV][4]; // viaccess & seca
|
---|
549 | ushort acs; // irdeto
|
---|
550 | ushort caid[CS_MAXREADERCAID];
|
---|
551 | uchar b_nano[256];
|
---|
552 | int blockemm_unknown; //block EMMs that have unknown type
|
---|
553 | int blockemm_u; //blcok Unique EMMs
|
---|
554 | int blockemm_s; //block Shared EMMS
|
---|
555 | int blockemm_g; //block Global EMMs
|
---|
556 | char * emmfile;
|
---|
557 | char pincode[5];
|
---|
558 | int ucpk_valid;
|
---|
559 | int logemm;
|
---|
560 | int cachemm;
|
---|
561 | int cachecm;
|
---|
562 | int rewritemm;
|
---|
563 | int card_status;
|
---|
564 | int deprecated; //if 0 ATR obeyed, if 1 default speed (9600) is chosen; for devices that cannot switch baudrate
|
---|
565 | struct s_module ph;
|
---|
566 | uchar ncd_key[16];
|
---|
567 | uchar ncd_skey[16];
|
---|
568 | int ncd_disable_server_filt;
|
---|
569 | ushort ncd_msgid;
|
---|
570 | int ncd_proto;
|
---|
571 | char cc_version[7]; // cccam version
|
---|
572 | char cc_build[5]; // cccam build number
|
---|
573 | int cc_maxhop; // cccam max distance
|
---|
574 | int cc_currenthops; // number of hops for CCCam
|
---|
575 | void *cc; // ptr to cccam internal data struct
|
---|
576 | int cc_disable_retry_ecm; //Schlocke
|
---|
577 | int cc_disable_auto_block; //Schlocke
|
---|
578 | int cc_force_resend_ecm; //Schlocke
|
---|
579 | int cc_want_emu; //Schlocke: Client want to have EMUs, 0 - NO; 1 - YES
|
---|
580 | uint cc_id;
|
---|
581 | uchar tcp_connected;
|
---|
582 | int tcp_ito; // inactivity timeout
|
---|
583 | int tcp_rto; // reconnect timeout
|
---|
584 | time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect )
|
---|
585 | time_t last_s; // send
|
---|
586 | uchar show_cls; // number of classes subscription showed on kill -31
|
---|
587 | int maxqlen; // max queue length
|
---|
588 | int qlen; // current queue length
|
---|
589 | FTAB fchid;
|
---|
590 | FTAB ftab;
|
---|
591 | CLASSTAB cltab;
|
---|
592 | #ifdef CS_WITH_GBOX
|
---|
593 | uchar gbox_pwd[4];
|
---|
594 | uchar gbox_timecode[7];
|
---|
595 | int gbox_online;
|
---|
596 | uchar gbox_vers;
|
---|
597 | uchar gbox_prem;
|
---|
598 | int gbox_fd;
|
---|
599 | struct timeb gbox_lasthello; // incoming time stamp
|
---|
600 | #endif
|
---|
601 | #ifdef CS_RDR_INIT_HIST
|
---|
602 | uchar init_history[4096];
|
---|
603 | #endif
|
---|
604 | int init_history_pos;
|
---|
605 | int msg_idx;
|
---|
606 | #ifdef WEBIF
|
---|
607 | int emmwritten[4]; //count written EMM
|
---|
608 | int emmskipped[4]; //count skipped EMM
|
---|
609 | int emmerror[4]; //count error EMM
|
---|
610 | int emmblocked[4]; //count blocked EMM
|
---|
611 | int lbvalue; //loadbalance Value
|
---|
612 | #endif
|
---|
613 | #ifdef HAVE_PCSC
|
---|
614 | SCARDCONTEXT hContext;
|
---|
615 | SCARDHANDLE hCard;
|
---|
616 | DWORD dwActiveProtocol;
|
---|
617 | #endif
|
---|
618 | #ifdef LIBUSB
|
---|
619 | SR_CONFIG *sr_config;
|
---|
620 | #endif
|
---|
621 | ////variables from icc_async.h start
|
---|
622 | int convention; //Convention of this ICC
|
---|
623 | unsigned char protocol_type; // Type of protocol
|
---|
624 | unsigned short BWT,CWT; // (for overclocking uncorrected) block waiting time, character waiting time, in ETU
|
---|
625 | unsigned long current_baudrate; // (for overclocking uncorrected) baudrate to prevent unnecessary conversions from/to termios structure
|
---|
626 | unsigned int read_timeout; // Max timeout (ms) to receive characters
|
---|
627 | unsigned int block_delay; // Delay (ms) after starting to transmit
|
---|
628 | unsigned int char_delay; // Delay (ms) after transmiting each sucesive char
|
---|
629 | ////variables from io_serial.h start
|
---|
630 | int written; //keep score of how much bytes are written to serial port, since they are echoed back they have to be read
|
---|
631 | ////variables from reader-dre.c
|
---|
632 | unsigned char provider;
|
---|
633 | ////variables from reader-nagra.c
|
---|
634 | IDEA_KEY_SCHEDULE ksSession;
|
---|
635 | int is_pure_nagra;
|
---|
636 | int is_tiger;
|
---|
637 | int has_dt08;
|
---|
638 | int swapCW;
|
---|
639 | unsigned char rom[15];
|
---|
640 | unsigned char plainDT08RSA[64];
|
---|
641 | unsigned char IdeaCamKey[16];
|
---|
642 | unsigned char irdId[4];
|
---|
643 | unsigned char sessi[16];
|
---|
644 | unsigned char signature[8];
|
---|
645 | unsigned char cam_state[3];
|
---|
646 | ////variables from reader-cryptoworks.c
|
---|
647 | BIGNUM exp;
|
---|
648 | BIGNUM ucpk;
|
---|
649 | ////variables from reader-viaccess.c
|
---|
650 | struct geo_cache last_geo;
|
---|
651 | int cc_reshare;
|
---|
652 | int lb_weight; //loadbalance weight factor, if unset, weight=100. The higher the value, the higher the usage-possibility
|
---|
653 | int lb_usagelevel; //usagelevel for loadbalancer
|
---|
654 | int lb_usagelevel_ecmcount;
|
---|
655 | time_t lb_usagelevel_time; //time for counting ecms, this creates usagelevel
|
---|
656 | time_t lb_last; //time for oldest reader
|
---|
657 | // multi AES linked list
|
---|
658 | AES_ENTRY *aes_list;
|
---|
659 | };
|
---|
660 |
|
---|
661 | #ifdef CS_ANTICASC
|
---|
662 |
|
---|
663 | struct s_acasc_shm {
|
---|
664 | ushort ac_count : 15;
|
---|
665 | ushort ac_deny : 1;
|
---|
666 | };
|
---|
667 |
|
---|
668 | struct s_acasc {
|
---|
669 | ushort stat[10];
|
---|
670 | uchar idx; // current active index in stat[]
|
---|
671 | };
|
---|
672 |
|
---|
673 | struct s_cpmap
|
---|
674 | {
|
---|
675 | ushort caid;
|
---|
676 | ulong provid;
|
---|
677 | ushort sid;
|
---|
678 | ushort chid;
|
---|
679 | ushort dwtime;
|
---|
680 | struct s_cpmap *next;
|
---|
681 | };
|
---|
682 | #endif
|
---|
683 |
|
---|
684 | struct s_auth
|
---|
685 | {
|
---|
686 | char usr[33];
|
---|
687 | char pwd[33];
|
---|
688 | int uniq;
|
---|
689 | int au;
|
---|
690 | int autoau;
|
---|
691 | int monlvl;
|
---|
692 | ulong grp;
|
---|
693 | int tosleep;
|
---|
694 | CAIDTAB ctab;
|
---|
695 | ulong sidtabok; // positiv services
|
---|
696 | ulong sidtabno; // negative services
|
---|
697 | FTAB fchid;
|
---|
698 | FTAB ftab; // user [caid] and ident filter
|
---|
699 | CLASSTAB cltab;
|
---|
700 | TUNTAB ttab;
|
---|
701 | #ifdef CS_ANTICASC
|
---|
702 | int ac_idx;
|
---|
703 | int ac_users; // 0 - unlimited
|
---|
704 | uchar ac_penalty; // 0 - log, >0 - fake dw
|
---|
705 | #endif
|
---|
706 | in_addr_t dynip;
|
---|
707 | uchar dyndns[64];
|
---|
708 | time_t expirationdate;
|
---|
709 | int c35_suppresscmd08;
|
---|
710 | int c35_sleepsend;
|
---|
711 | int ncd_keepalive;
|
---|
712 | int cccmaxhops;
|
---|
713 | int cccreshare;
|
---|
714 | int disabled;
|
---|
715 | struct s_auth *next;
|
---|
716 | };
|
---|
717 |
|
---|
718 | struct s_srvid
|
---|
719 | {
|
---|
720 | int srvid;
|
---|
721 | int ncaid;
|
---|
722 | int caid[10];
|
---|
723 | char prov[33];
|
---|
724 | char name[33];
|
---|
725 | char type[33];
|
---|
726 | char desc[33];
|
---|
727 | struct s_srvid *next;
|
---|
728 | };
|
---|
729 |
|
---|
730 | //Todo #ifdef CCCAM
|
---|
731 | struct s_provid
|
---|
732 | {
|
---|
733 | int caid;
|
---|
734 | ulong provid;
|
---|
735 | char prov[33];
|
---|
736 | char sat[33];
|
---|
737 | char lang[33];
|
---|
738 | struct s_provid *next;
|
---|
739 | };
|
---|
740 |
|
---|
741 | struct s_ip
|
---|
742 | {
|
---|
743 | in_addr_t ip[2];
|
---|
744 | struct s_ip *next;
|
---|
745 | };
|
---|
746 |
|
---|
747 | struct s_config
|
---|
748 | {
|
---|
749 | int nice;
|
---|
750 | int debuglvl;
|
---|
751 | ulong netprio;
|
---|
752 | ulong ctimeout;
|
---|
753 | ulong ftimeout;
|
---|
754 | ulong cmaxidle;
|
---|
755 | int ulparent;
|
---|
756 | ulong delay;
|
---|
757 | int bindwait;
|
---|
758 | int resolvedelay;
|
---|
759 | int clientdyndns;
|
---|
760 | int tosleep;
|
---|
761 | in_addr_t srvip;
|
---|
762 | char *pidfile;
|
---|
763 | char *usrfile;
|
---|
764 | char *cwlogdir;
|
---|
765 | char *logfile;
|
---|
766 | int disablelog;
|
---|
767 | int disableuserfile;
|
---|
768 | int usrfileflag;
|
---|
769 | struct s_auth *account;
|
---|
770 | struct s_srvid *srvid;
|
---|
771 | //Todo #ifdef CCCAM
|
---|
772 | struct s_provid *provid;
|
---|
773 | struct s_sidtab *sidtab;
|
---|
774 | int mon_port;
|
---|
775 | in_addr_t mon_srvip;
|
---|
776 | struct s_ip *mon_allowed;
|
---|
777 | int mon_aulow;
|
---|
778 | int mon_hideclient_to;
|
---|
779 | int mon_level;
|
---|
780 | int mon_appendchaninfo;
|
---|
781 | #ifdef WEBIF
|
---|
782 | int http_port;
|
---|
783 | char http_user[65];
|
---|
784 | char http_pwd[65];
|
---|
785 | char http_css[128];
|
---|
786 | char http_tpl[128];
|
---|
787 | char http_script[128];
|
---|
788 | int http_refresh;
|
---|
789 | int http_hide_idle_clients;
|
---|
790 | struct s_ip *http_allowed;
|
---|
791 | int http_readonly;
|
---|
792 | in_addr_t http_dynip;
|
---|
793 | uchar http_dyndns[64];
|
---|
794 | #endif
|
---|
795 | int c33_port;
|
---|
796 | in_addr_t c33_srvip;
|
---|
797 | uchar c33_key[16];
|
---|
798 | int c33_crypted;
|
---|
799 | int c33_passive;
|
---|
800 | struct s_ip *c33_plain;
|
---|
801 | int c35_port;
|
---|
802 | in_addr_t c35_srvip;
|
---|
803 | int c35_suppresscmd08;
|
---|
804 | PTAB c35_tcp_ptab;
|
---|
805 | in_addr_t c35_tcp_srvip;
|
---|
806 | PTAB ncd_ptab;
|
---|
807 | in_addr_t ncd_srvip;
|
---|
808 | uchar ncd_key[16];
|
---|
809 | int ncd_keepalive;
|
---|
810 | int ncd_mgclient;
|
---|
811 | struct s_ip *ncd_allowed;
|
---|
812 | PTAB cc_ptab;
|
---|
813 | int rad_port;
|
---|
814 | in_addr_t rad_srvip;
|
---|
815 | int cc_port;
|
---|
816 | int cc_reshare;
|
---|
817 | in_addr_t cc_srvip;
|
---|
818 | uchar cc_version[7];
|
---|
819 | struct s_ip *rad_allowed;
|
---|
820 | char rad_usr[32];
|
---|
821 | char ser_device[512];
|
---|
822 | ulong srtimeout; // SerialReaderTimeount in millisec
|
---|
823 | int max_log_size;
|
---|
824 | int waitforcards;
|
---|
825 | int preferlocalcards;
|
---|
826 | int saveinithistory;
|
---|
827 | int reader_restart_seconds; //schlocke: reader restart auf x seconds, disable = 0
|
---|
828 | int reader_auto_loadbalance; //schlocke: reader loadbalancing disable = 0 enable = 1
|
---|
829 | int reader_auto_loadbalance_save; //schlocke: load/save statistics to file, save every x ecms
|
---|
830 |
|
---|
831 | #ifdef CS_WITH_GBOX
|
---|
832 | uchar gbox_pwd[8];
|
---|
833 | uchar ignorefile[128];
|
---|
834 | uchar cardfile[128];
|
---|
835 | uchar gbxShareOnl[128];
|
---|
836 | int maxdist;
|
---|
837 | int num_locals;
|
---|
838 | unsigned long locals[CS_MAXLOCALS];
|
---|
839 | #endif
|
---|
840 |
|
---|
841 | #ifdef IRDETO_GUESSING
|
---|
842 | struct s_irdeto_quess *itab[0xff];
|
---|
843 | #endif
|
---|
844 |
|
---|
845 | #ifdef HAVE_DVBAPI
|
---|
846 | int dvbapi_enabled;
|
---|
847 | int dvbapi_au;
|
---|
848 | char dvbapi_usr[33];
|
---|
849 | int dvbapi_boxtype;
|
---|
850 | int dvbapi_pmtmode;
|
---|
851 | CAIDTAB dvbapi_prioritytab;
|
---|
852 | CAIDTAB dvbapi_ignoretab;
|
---|
853 | CAIDTAB dvbapi_delaytab;
|
---|
854 | #endif
|
---|
855 |
|
---|
856 | #ifdef CS_ANTICASC
|
---|
857 | char ac_enabled;
|
---|
858 | int ac_users; // num of users for account (0 - default)
|
---|
859 | int ac_stime; // time to collect AC statistics (3 min - default)
|
---|
860 | int ac_samples; // qty of samples
|
---|
861 | int ac_penalty; // 0 - write to log
|
---|
862 | int ac_fakedelay; // 100-1000 ms
|
---|
863 | int ac_denysamples;
|
---|
864 | char ac_logfile[128];
|
---|
865 | struct s_cpmap *cpmap;
|
---|
866 | #endif
|
---|
867 | // struct s_reader reader[];
|
---|
868 | };
|
---|
869 |
|
---|
870 | typedef struct ecm_request_t
|
---|
871 | {
|
---|
872 |
|
---|
873 | uchar ecm[256];
|
---|
874 | uchar cw[16];
|
---|
875 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
876 | // uchar l;
|
---|
877 | short l;
|
---|
878 | ushort caid;
|
---|
879 | ushort ocaid;
|
---|
880 | ushort srvid;
|
---|
881 | ushort chid;
|
---|
882 | ushort pid;
|
---|
883 | ushort idx;
|
---|
884 | ulong prid;
|
---|
885 | int reader[CS_MAXREADER];
|
---|
886 | int cidx; // client index
|
---|
887 | int cpti; // client pending table index
|
---|
888 | int stage; // processing stage in server module
|
---|
889 | int level; // send-level in client module
|
---|
890 | int rc;
|
---|
891 | uchar rcEx;
|
---|
892 | struct timeb tps; // incoming time stamp
|
---|
893 | uchar locals_done;
|
---|
894 | int btun; // mark er as betatunneled
|
---|
895 |
|
---|
896 | #ifdef CS_WITH_GBOX
|
---|
897 | ushort gbxCWFrom;
|
---|
898 | ushort gbxFrom;
|
---|
899 | ushort gbxTo;
|
---|
900 | uchar gbxForward[16];
|
---|
901 | int gbxRidx;
|
---|
902 | #endif
|
---|
903 |
|
---|
904 | } GCC_PACK ECM_REQUEST;
|
---|
905 |
|
---|
906 | //Loadbalance constants:
|
---|
907 | #define LB_NONE 0
|
---|
908 | #define LB_FASTEST_READER_FIRST 1
|
---|
909 | #define LB_OLDEST_READER_FIRST 2
|
---|
910 | #define LB_LOWEST_USAGELEVEL 3
|
---|
911 |
|
---|
912 | #define MAX_STAT_TIME 20
|
---|
913 | #define MIN_ECM_COUNT 5
|
---|
914 | #define MAX_ECM_COUNT 500
|
---|
915 |
|
---|
916 |
|
---|
917 | typedef struct add_reader_stat_t
|
---|
918 | {
|
---|
919 | int ridx;
|
---|
920 | int time;
|
---|
921 | int rc;
|
---|
922 |
|
---|
923 | ushort caid;
|
---|
924 | ulong prid;
|
---|
925 | ushort srvid;
|
---|
926 | } GCC_PACK ADD_READER_STAT;
|
---|
927 |
|
---|
928 | typedef struct reader_stat_t
|
---|
929 | {
|
---|
930 | int rc;
|
---|
931 | ushort caid;
|
---|
932 | ulong prid;
|
---|
933 | ushort srvid;
|
---|
934 |
|
---|
935 | int ecm_count;
|
---|
936 | int time_avg;
|
---|
937 | int time_stat[MAX_STAT_TIME];
|
---|
938 | int time_idx;
|
---|
939 | } GCC_PACK READER_STAT;
|
---|
940 |
|
---|
941 | typedef struct get_reader_stat_t
|
---|
942 | {
|
---|
943 | ushort caid;
|
---|
944 | ulong prid;
|
---|
945 | ushort srvid;
|
---|
946 | int cidx;
|
---|
947 | int reader_avail[CS_MAXREADER];
|
---|
948 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
949 | } GCC_PACK GET_READER_STAT;
|
---|
950 |
|
---|
951 | typedef struct emm_packet_t
|
---|
952 | {
|
---|
953 | uchar emm[258];
|
---|
954 | uchar l;
|
---|
955 | uchar caid[2];
|
---|
956 | uchar provid[4];
|
---|
957 | uchar hexserial[8]; //contains hexserial or SA of EMM
|
---|
958 | uchar type;
|
---|
959 | int cidx;
|
---|
960 | } GCC_PACK EMM_PACKET;
|
---|
961 |
|
---|
962 | //EMM types:
|
---|
963 | #define UNKNOWN 0
|
---|
964 | #define UNIQUE 1
|
---|
965 | #define SHARED 2
|
---|
966 | #define GLOBAL 3
|
---|
967 |
|
---|
968 | // oscam-simples
|
---|
969 | extern char *remote_txt(void);
|
---|
970 | extern char *trim(char *);
|
---|
971 | extern char *strtolower(char *);
|
---|
972 | extern int gethexval(char);
|
---|
973 | extern int cs_atob(uchar *, char *, int);
|
---|
974 | extern ulong cs_atoi(char *, int, int);
|
---|
975 | extern int byte_atob(char *);
|
---|
976 | extern long word_atob(char *);
|
---|
977 | extern int key_atob(char *, uchar *);
|
---|
978 | extern int key_atob14(char *, uchar *);
|
---|
979 | extern int key_atob_l(char *, uchar *, int);
|
---|
980 | extern char *key_btoa(char *, uchar *);
|
---|
981 | extern char *cs_hexdump(int, uchar *, int);
|
---|
982 | extern in_addr_t cs_inet_order(in_addr_t);
|
---|
983 | extern char *cs_inet_ntoa(in_addr_t);
|
---|
984 | extern in_addr_t cs_inet_addr(char *txt);
|
---|
985 | extern ulong b2i(int, uchar *);
|
---|
986 | extern ullong b2ll(int, uchar *);
|
---|
987 | extern uchar *i2b(int, ulong);
|
---|
988 | extern ulong a2i(char *, int);
|
---|
989 | extern int boundary(int, int);
|
---|
990 | extern void cs_ftime(struct timeb *);
|
---|
991 | extern void cs_sleepms(unsigned int);
|
---|
992 | extern void cs_sleepus(unsigned int);
|
---|
993 | extern int bytes_available(int);
|
---|
994 | extern void cs_setpriority(int);
|
---|
995 | extern struct s_auth *find_user(char *);
|
---|
996 | #ifdef WEBIF
|
---|
997 | extern int x2i(int i);
|
---|
998 | extern void urldecode(char *s);
|
---|
999 | extern char to_hex(char code);
|
---|
1000 | extern char *urlencode(char *str);
|
---|
1001 | extern char *char_to_hex(const unsigned char* p_array, unsigned int p_array_len, char hex2ascii[256][2]);
|
---|
1002 | extern void create_rand_str(char *dst, int size);
|
---|
1003 | #endif
|
---|
1004 | extern void long2bitchar(long value, char *result);
|
---|
1005 | extern int file_exists(const char * filename);
|
---|
1006 | extern void clear_sip(struct s_ip **sip);
|
---|
1007 | extern void clear_ptab(struct s_ptab *ptab);
|
---|
1008 | extern void clear_ftab(struct s_ftab *ftab);
|
---|
1009 | void clear_caidtab(struct s_caidtab *ctab);
|
---|
1010 | void clear_tuntab(struct s_tuntab *ttab);
|
---|
1011 | extern int safe_overwrite_with_bak(char *destfile, char *tmpfile, char *bakfile, int forceBakOverWrite);
|
---|
1012 | extern void fprintf_conf(FILE *f, int varnameWidth, const char *varname, const char *fmtstring, ...);
|
---|
1013 | extern void cs_strncpy(char * destination, const char * source, size_t num);
|
---|
1014 | extern char *get_servicename(int srvid, int caid);
|
---|
1015 | extern char *get_provider(int caid, ulong provid);
|
---|
1016 | extern void make_non_blocking(int fd);
|
---|
1017 |
|
---|
1018 | // oscam variables
|
---|
1019 | extern int pfd, fd_c2m, cs_idx, *c_start, cs_ptyp, cs_dblevel;
|
---|
1020 | extern int *logidx, *loghistidx, *log_fd;
|
---|
1021 | extern int is_server, *mcl;
|
---|
1022 | extern uchar mbuf[1024];
|
---|
1023 | extern ushort len4caid[256];
|
---|
1024 | extern pid_t master_pid;
|
---|
1025 | extern struct s_ecm *ecmcache;
|
---|
1026 | extern struct s_client *client;
|
---|
1027 |
|
---|
1028 | extern struct card_struct *Cards;
|
---|
1029 | extern struct idstore_struct *idstore;
|
---|
1030 | extern unsigned long *IgnoreList;
|
---|
1031 |
|
---|
1032 | extern struct s_config *cfg;
|
---|
1033 | extern char cs_confdir[], *loghist;
|
---|
1034 | extern struct s_module ph[CS_MAX_MOD];
|
---|
1035 | extern ECM_REQUEST *ecmtask;
|
---|
1036 | #ifdef CS_ANTICASC
|
---|
1037 | extern struct s_acasc_shm *acasc;
|
---|
1038 | extern FILE *fpa;
|
---|
1039 | extern int use_ac_log;
|
---|
1040 | #endif
|
---|
1041 | extern pthread_mutex_t gethostbyname_lock; //gethostbyname ist NOT threadsafe! So we need a mutex-lock!
|
---|
1042 |
|
---|
1043 | // oscam
|
---|
1044 | extern int recv_from_udpipe(uchar *);
|
---|
1045 | extern char* username(int);
|
---|
1046 | extern int idx_from_pid(pid_t);
|
---|
1047 | extern int chk_bcaid(ECM_REQUEST *, CAIDTAB *);
|
---|
1048 | extern void cs_exit(int sig);
|
---|
1049 | extern int cs_fork(in_addr_t, in_port_t);
|
---|
1050 | extern void wait4master(void);
|
---|
1051 | extern int cs_auth_client(struct s_auth *, char*);
|
---|
1052 | extern void cs_disconnect_client(void);
|
---|
1053 | extern int check_ecmcache1(ECM_REQUEST *, ulong);
|
---|
1054 | extern int check_ecmcache2(ECM_REQUEST *, ulong);
|
---|
1055 | extern void store_logentry(char *);
|
---|
1056 | extern int write_to_pipe(int, int, uchar *, int);
|
---|
1057 | extern int read_from_pipe(int, uchar **, int);
|
---|
1058 | extern int write_ecm_request(int, ECM_REQUEST *);
|
---|
1059 | extern int write_ecm_answer(struct s_reader *, int, ECM_REQUEST *);
|
---|
1060 | extern void log_emm_request(int);
|
---|
1061 | extern ulong chk_provid(uchar *, ushort);
|
---|
1062 | extern void guess_cardsystem(ECM_REQUEST *);
|
---|
1063 | #ifdef IRDETO_GUESSING
|
---|
1064 | extern void guess_irdeto(ECM_REQUEST *);
|
---|
1065 | #endif
|
---|
1066 | extern void get_cw(ECM_REQUEST *);
|
---|
1067 | extern void do_emm(EMM_PACKET *);
|
---|
1068 | extern ECM_REQUEST *get_ecmtask(void);
|
---|
1069 | extern void request_cw(ECM_REQUEST *, int, int);
|
---|
1070 | extern int send_dcw(ECM_REQUEST *);
|
---|
1071 | extern int process_input(uchar *, int, int);
|
---|
1072 | extern int chk_srvid(ECM_REQUEST *, int);
|
---|
1073 | extern int chk_srvid_match(ECM_REQUEST *, SIDTAB *);
|
---|
1074 | extern int chk_sfilter(ECM_REQUEST *, PTAB*);
|
---|
1075 | extern int chk_ufilters(ECM_REQUEST *);
|
---|
1076 | extern int chk_rfilter(ECM_REQUEST *, struct s_reader *);
|
---|
1077 | extern int chk_rsfilter(struct s_reader * reader, ECM_REQUEST *, int);
|
---|
1078 | extern int chk_avail_reader(ECM_REQUEST *, struct s_reader *);
|
---|
1079 | extern int matching_reader(ECM_REQUEST *, struct s_reader *);
|
---|
1080 | extern void set_signal_handler(int , int , void (*)(int));
|
---|
1081 | extern void cs_log_config(void);
|
---|
1082 | extern void cs_waitforcardinit(void);
|
---|
1083 | extern void cs_reinit_clients(void);
|
---|
1084 | extern void chk_dcw(int fd);
|
---|
1085 | extern void update_reader_config(uchar *ptr);
|
---|
1086 | extern void send_restart_cardreader(int ridx);
|
---|
1087 | extern void send_clear_reader_stat(int ridx);
|
---|
1088 |
|
---|
1089 | #ifdef CS_ANTICASC
|
---|
1090 | //extern void start_anticascader(void);
|
---|
1091 | extern void init_ac(void);
|
---|
1092 | extern void ac_init_stat();
|
---|
1093 | extern int ac_init_log(char*);
|
---|
1094 | extern void ac_do_stat(void);
|
---|
1095 | extern void ac_init_client(struct s_auth *);
|
---|
1096 | extern void ac_chk(ECM_REQUEST*, int);
|
---|
1097 | #endif
|
---|
1098 |
|
---|
1099 | // oscam-nano
|
---|
1100 | extern int chk_class(ECM_REQUEST *, CLASSTAB*, const char*, const char*);
|
---|
1101 |
|
---|
1102 | // oscam-config
|
---|
1103 | extern int init_config(void);
|
---|
1104 | extern int init_userdb(struct s_auth **authptr_org);
|
---|
1105 | extern int init_readerdb(void);
|
---|
1106 | extern int init_sidtab(void);
|
---|
1107 | extern int init_srvid(void);
|
---|
1108 | extern int search_boxkey(ushort, char *);
|
---|
1109 | extern void init_len4caid(void);
|
---|
1110 | #ifdef IRDETO_GUESSING
|
---|
1111 | extern int init_irdeto_guess_tab(void);
|
---|
1112 | #endif
|
---|
1113 | extern void chk_caidtab(char *caidasc, CAIDTAB *ctab);
|
---|
1114 | extern void chk_tuntab(char *tunasc, TUNTAB *ttab);
|
---|
1115 | extern void chk_services(char *labels, ulong *sidok, ulong *sidno);
|
---|
1116 | extern void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName);
|
---|
1117 | extern void chk_cltab(char *classasc, CLASSTAB *clstab);
|
---|
1118 | extern void chk_iprange(char *value, struct s_ip **base);
|
---|
1119 | extern void chk_port_tab(char *portasc, PTAB *ptab);
|
---|
1120 | #ifdef CS_ANTICASC
|
---|
1121 | extern void chk_t_ac(char *token, char *value);
|
---|
1122 | #endif
|
---|
1123 | extern void chk_t_camd33(char *token, char *value);
|
---|
1124 | extern void chk_t_camd35(char *token, char *value);
|
---|
1125 | extern void chk_t_camd35_tcp(char *token, char *value);
|
---|
1126 | extern void chk_t_newcamd(char *token, char *value);
|
---|
1127 | extern void chk_t_radegast(char *token, char *value);
|
---|
1128 | extern void chk_t_serial(char *token, char *value);
|
---|
1129 | #ifdef CS_WITH_GBOX
|
---|
1130 | extern void chk_t_gbox(char *token, char *value);
|
---|
1131 | #endif
|
---|
1132 | extern void chk_t_cccam(char *token, char *value);
|
---|
1133 | extern void chk_t_global(char *token, char *value);
|
---|
1134 | extern void chk_t_monitor(char *token, char *value);
|
---|
1135 | extern void chk_reader(char *token, char *value, struct s_reader *rdr);
|
---|
1136 |
|
---|
1137 | #ifdef HAVE_DVBAPI
|
---|
1138 | extern void chk_t_dvbapi(char *token, char *value);
|
---|
1139 | void dvbapi_chk_caidtab(char *caidasc, CAIDTAB *ctab);
|
---|
1140 | #endif
|
---|
1141 |
|
---|
1142 | #ifdef WEBIF
|
---|
1143 | extern void chk_t_webif(char *token, char *value);
|
---|
1144 | #endif
|
---|
1145 |
|
---|
1146 | extern void chk_account(char *token, char *value, struct s_auth *account);
|
---|
1147 | extern void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab);
|
---|
1148 | extern int write_services();
|
---|
1149 | extern int write_userdb(struct s_auth *authptr);
|
---|
1150 | extern int write_config();
|
---|
1151 | extern int write_server();
|
---|
1152 | extern char *mk_t_caidtab(CAIDTAB *ctab);
|
---|
1153 | extern char *mk_t_tuntab(TUNTAB *ttab);
|
---|
1154 | extern char *mk_t_group(ulong *grp);
|
---|
1155 | extern char *mk_t_ftab(FTAB *ftab);
|
---|
1156 | //Todo #ifdef CCCAM
|
---|
1157 | extern int init_provid();
|
---|
1158 | extern char * get_tmp_dir();
|
---|
1159 |
|
---|
1160 | // oscam-reader
|
---|
1161 | extern int ridx, logfd;
|
---|
1162 | extern int reader_cmd2icc(struct s_reader * reader, uchar *buf, int l, uchar *response, ushort *response_length);
|
---|
1163 | extern int card_write(struct s_reader * reader, uchar *, uchar *, uchar *, ushort *);
|
---|
1164 | extern int check_sct_len(const unsigned char *data, int off);
|
---|
1165 | extern void cs_ri_brk(struct s_reader * reader, int);
|
---|
1166 | extern void cs_ri_log(struct s_reader * reader, char *,...);
|
---|
1167 | extern void * start_cardreader(void *);
|
---|
1168 | extern void reader_card_info(struct s_reader * reader);
|
---|
1169 | extern int hostResolve();
|
---|
1170 | extern int network_tcp_connection_open();
|
---|
1171 | extern void network_tcp_connection_close(struct s_reader * reader, int);
|
---|
1172 |
|
---|
1173 | // oscam-log
|
---|
1174 | extern int cs_init_log(char *);
|
---|
1175 | extern void cs_write_log(char *);
|
---|
1176 | extern void cs_log(char *,...);
|
---|
1177 | extern void cs_debug(char *,...);
|
---|
1178 | extern void cs_debug_nolf(char *,...);
|
---|
1179 | extern void cs_debug_mask(unsigned short, char *,...);
|
---|
1180 | extern void cs_ddump(uchar *, int, char *, ...);
|
---|
1181 | extern void cs_ddump_mask(unsigned short, uchar *, int, char *, ...);
|
---|
1182 | extern void cs_close_log(void);
|
---|
1183 | extern int cs_init_statistics(char *);
|
---|
1184 | extern void cs_statistics(int);
|
---|
1185 | extern void cs_dump(uchar *, int, char *, ...);
|
---|
1186 |
|
---|
1187 | // oscam-aes
|
---|
1188 | extern void aes_set_key(char *);
|
---|
1189 | extern void aes_encrypt_idx(int, uchar *, int);
|
---|
1190 | extern void aes_decrypt(uchar *, int);
|
---|
1191 | extern int aes_decrypt_from_list(AES_ENTRY *list, ushort caid, uint32 provid,int keyid, uchar *buf, int n);
|
---|
1192 | extern int aes_present(AES_ENTRY *list, ushort caid, uint32 provid,int keyid);
|
---|
1193 | extern void parse_aes_keys(struct s_reader *rdr,char *value);
|
---|
1194 | extern void aes_clear_entries(struct s_reader *rdr);
|
---|
1195 |
|
---|
1196 | #define aes_encrypt(b, n) aes_encrypt_idx(cs_idx, b, n)
|
---|
1197 |
|
---|
1198 | // reader-common
|
---|
1199 | extern int reader_device_init(struct s_reader * reader);
|
---|
1200 | extern int reader_checkhealth(struct s_reader * reader);
|
---|
1201 | extern void reader_post_process(struct s_reader * reader);
|
---|
1202 | extern int reader_ecm(struct s_reader * reader, ECM_REQUEST *);
|
---|
1203 | extern int reader_emm(struct s_reader * reader, EMM_PACKET *);
|
---|
1204 | int reader_get_emm_type(EMM_PACKET *ep, struct s_reader * reader);
|
---|
1205 | void get_emm_filter(struct s_reader * rdr, uchar *filter);
|
---|
1206 | int get_cardsystem(ushort caid);
|
---|
1207 | extern int check_emm_cardsystem(struct s_reader * rdr, EMM_PACKET *ep);
|
---|
1208 | extern void reader_device_close(struct s_reader * reader);
|
---|
1209 |
|
---|
1210 | //module-stat
|
---|
1211 | extern void init_stat();
|
---|
1212 | extern void add_reader_stat(ADD_READER_STAT *add_stat);
|
---|
1213 | extern int get_best_reader(GET_READER_STAT *grs, int *result);
|
---|
1214 | extern void clear_reader_stat(int ridx);
|
---|
1215 |
|
---|
1216 | #ifdef HAVE_PCSC
|
---|
1217 | // reader-pcsc
|
---|
1218 | extern int pcsc_reader_do_api(struct s_reader *pcsc_reader, uchar *buf, uchar *cta_res, ushort *cta_lr,int l);
|
---|
1219 | extern int pcsc_activate_card(struct s_reader *pcsc_reader, uchar *atr, ushort *atr_size);
|
---|
1220 | extern int pcsc_check_card_inserted(struct s_reader *pcsc_reader);
|
---|
1221 | extern int pcsc_reader_init(struct s_reader *pcsc_reader, char *device);
|
---|
1222 | extern void pcsc_close(struct s_reader *pcsc_reader);
|
---|
1223 | #endif
|
---|
1224 |
|
---|
1225 | // protocol modules
|
---|
1226 | extern int monitor_send_idx(int, char *);
|
---|
1227 | extern void module_monitor(struct s_module *);
|
---|
1228 | extern void module_camd35(struct s_module *);
|
---|
1229 | extern void module_camd35_tcp(struct s_module *);
|
---|
1230 | extern void module_camd33(struct s_module *);
|
---|
1231 | extern void module_newcamd(struct s_module *);
|
---|
1232 | extern void module_radegast(struct s_module *);
|
---|
1233 | extern void module_oscam_ser(struct s_module *);
|
---|
1234 | extern void module_cccam(struct s_module *);
|
---|
1235 | extern void module_constcw(struct s_module *);
|
---|
1236 | extern struct timeval *chk_pending(struct timeb tp_ctimeout);
|
---|
1237 | #ifdef CS_WITH_GBOX
|
---|
1238 | extern void module_gbox(struct s_module *);
|
---|
1239 | #endif
|
---|
1240 | #ifdef HAVE_DVBAPI
|
---|
1241 | extern void module_dvbapi(struct s_module *);
|
---|
1242 | #endif
|
---|
1243 | #ifdef WITH_STAPI
|
---|
1244 | extern void module_stapi(struct s_module *);
|
---|
1245 | #endif
|
---|
1246 |
|
---|
1247 |
|
---|
1248 | // module-monitor
|
---|
1249 | extern char *monitor_get_proto(int idx);
|
---|
1250 | extern int cs_idx2ridx(int idx);
|
---|
1251 |
|
---|
1252 | #ifdef WEBIF
|
---|
1253 | // oscam-http
|
---|
1254 | extern void http_srv();
|
---|
1255 | #endif
|
---|
1256 |
|
---|
1257 | #ifdef ST_LINUX
|
---|
1258 | extern void Fortis_STSMART_Close();
|
---|
1259 | extern void Fortis_STPTI_Close();
|
---|
1260 | #endif
|
---|
1261 |
|
---|
1262 | #endif // CS_GLOBALS
|
---|