source: trunk/globals.h@ 2025

Last change on this file since 2025 was 2025, checked in by merek, 12 years ago

Move ecmcache again back to reader section, sorry landlord 8)

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