[8] | 1 | #include <stdlib.h>
|
---|
| 2 | #include <stdio.h>
|
---|
| 3 | #include <assert.h>
|
---|
| 4 | #include <fcntl.h>
|
---|
| 5 | #include <sys/ioctl.h>
|
---|
| 6 | #include <sys/poll.h>
|
---|
| 7 | #include <ctype.h>
|
---|
| 8 | #include <sys/types.h>
|
---|
| 9 | #include <sys/stat.h>
|
---|
| 10 | #include <sys/shm.h>
|
---|
| 11 | #include <sys/wait.h>
|
---|
| 12 | #include <unistd.h>
|
---|
| 13 | #include <sys/mman.h>
|
---|
| 14 | #include <stdarg.h>
|
---|
| 15 | #include <time.h>
|
---|
| 16 | #include <sys/timeb.h>
|
---|
| 17 | #include <limits.h>
|
---|
| 18 |
|
---|
| 19 | #include <sys/socket.h>
|
---|
| 20 | #include <netinet/in.h>
|
---|
[56] | 21 | #include <arpa/inet.h>
|
---|
[8] | 22 | #include <netdb.h>
|
---|
| 23 | #include <string.h>
|
---|
| 24 | #include <signal.h>
|
---|
| 25 | #include <errno.h>
|
---|
| 26 |
|
---|
| 27 | #include <pthread.h>
|
---|
| 28 |
|
---|
| 29 | #ifndef CS_GLOBALS
|
---|
| 30 | #define CS_GLOBALS
|
---|
[78] | 31 | #define CS_VERSION "0.99.3svn"
|
---|
[8] | 32 |
|
---|
| 33 | #if defined(__GNUC__)
|
---|
| 34 | # define GCC_PACK __attribute__((packed))
|
---|
| 35 | #else
|
---|
| 36 | # define GCC_PACK
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
[21] | 39 | #include "oscam-config.h"
|
---|
| 40 | #include "oscam-types.h"
|
---|
[8] | 41 | #include "cscrypt/cscrypt.h"
|
---|
| 42 |
|
---|
| 43 | #ifndef CS_CONFDIR
|
---|
| 44 | #define CS_CONFDIR "/usr/local/etc"
|
---|
| 45 | #endif
|
---|
| 46 | #ifndef CS_MMAPFILE
|
---|
| 47 | #define CS_MMAPFILE "/tmp/mcps.mem"
|
---|
| 48 | #endif
|
---|
| 49 | #ifndef CS_LOGFILE
|
---|
| 50 | #define CS_LOGFILE "/var/log/mcps.log"
|
---|
| 51 | #endif
|
---|
| 52 | #define CS_QLEN 128 // size of request queue
|
---|
| 53 | #define CS_MAXQLEN 128 // size of request queue for cardreader
|
---|
| 54 | #define CS_MAXCAIDTAB 32 // max. caid-defs/user
|
---|
[41] | 55 | #define CS_MAXTUNTAB 4 // max. betatunnel mappings
|
---|
[8] | 56 | #define CS_MAXPROV 32
|
---|
| 57 | #define CS_MAXPORTS 32 // max server ports
|
---|
| 58 | #define CS_MAXFILTERS 16
|
---|
| 59 |
|
---|
| 60 | #define CS_MAXCARDS 4096
|
---|
| 61 | #define CS_MAXIGNORE 1024
|
---|
| 62 | #define CS_MAXLOCALS 16
|
---|
| 63 | #define CS_ECMSTORESIZE 16 // use MD5()
|
---|
| 64 | #define CS_EMMSTORESIZE 270
|
---|
[93] | 65 | #define CS_CLIENT_TIMEOUT 5000
|
---|
[8] | 66 | #define CS_CLIENT_MAXIDLE 120
|
---|
| 67 | #define CS_BIND_TIMEOUT 120
|
---|
| 68 | #define CS_DELAY 0
|
---|
| 69 | #define CS_RESOLVE_DELAY 30
|
---|
| 70 | #define CS_MAXLOGHIST 30
|
---|
| 71 | #define CS_LOGHISTSIZE 160 // 32+128: username + logline
|
---|
| 72 |
|
---|
| 73 | #ifdef OLD_DEFS
|
---|
| 74 | #ifdef CS_EMBEDDED
|
---|
| 75 | #define CS_MAXPENDING 32
|
---|
| 76 | #define CS_ECMCACHESIZE 32
|
---|
| 77 | #define CS_EMMCACHESIZE 64
|
---|
| 78 | #define CS_MAXPID 32
|
---|
| 79 | #define CS_MAXREADER 8
|
---|
| 80 | #else
|
---|
| 81 | #define CS_MAXPENDING 128
|
---|
| 82 | #define CS_ECMCACHESIZE 128
|
---|
| 83 | #define CS_EMMCACHESIZE 256
|
---|
| 84 | #define CS_MAXPID 128
|
---|
| 85 | #define CS_MAXREADER 64
|
---|
| 86 | #endif
|
---|
| 87 | #endif
|
---|
| 88 |
|
---|
| 89 | #ifdef CS_EMBEDDED
|
---|
| 90 | #define CS_MAXPID 32
|
---|
| 91 | #define CS_MAXREADER (CS_MAXPID>>1)
|
---|
| 92 | #define CS_MAXPENDING CS_MAXPID
|
---|
| 93 | #define CS_ECMCACHESIZE CS_MAXPID
|
---|
| 94 | #define CS_EMMCACHESIZE (CS_MAXPID<<1)
|
---|
| 95 | #else
|
---|
| 96 | #define CS_MAXPID 512
|
---|
| 97 | #define CS_MAXREADER (CS_MAXPID>>2)
|
---|
| 98 | #define CS_MAXPENDING (CS_MAXPID<<1)
|
---|
| 99 | #define CS_ECMCACHESIZE CS_MAXPID
|
---|
| 100 | #define CS_EMMCACHESIZE (CS_MAXPID<<1)
|
---|
| 101 | #define CS_RDR_INIT_HIST
|
---|
| 102 | #endif
|
---|
| 103 |
|
---|
| 104 | #define D_DUMP 1 // Debug Dumps
|
---|
| 105 | #define D_MASTER 2 // Debug Master Process
|
---|
| 106 | #define D_READER 4 // Debug Reader/Proxy Process
|
---|
| 107 | #define D_CLIENT 8 // Debug Client Process
|
---|
| 108 | #define D_DEVICE 16 // Debug Reader I/O
|
---|
| 109 | #define D_WATCHDOG 32 // Debug Watchdog
|
---|
| 110 | #define D_ALL_DUMP 63
|
---|
| 111 |
|
---|
| 112 | #define R_MOUSE 0x1 // Reader smartcard mouse
|
---|
| 113 | #define R_INTERN 0x2 // Reader smartcard intern
|
---|
[71] | 114 | #define R_SMART 0x5 // Smartreader+
|
---|
[8] | 115 | #define R_CAMD35 0x10 // Reader cascading camd 3.5x
|
---|
| 116 | #define R_CAMD33 0x11 // Reader cascading camd 3.3x
|
---|
| 117 | #define R_NEWCAMD 0x12 // Reader cascading newcamd
|
---|
| 118 | #define R_RADEGAST 0x13 // Reader cascading radegast
|
---|
| 119 | #define R_CS378X 0x14 // Reader cascading camd 3.5x TCP
|
---|
| 120 | #define R_GBOX 0x20 // Reader cascading gbox
|
---|
| 121 | #define R_SERIAL 0x80 // Reader serial
|
---|
| 122 | #define R_IS_NETWORK 0x70
|
---|
| 123 | #define R_IS_CASCADING 0xF0
|
---|
| 124 |
|
---|
| 125 | #define CS_MAX_MOD 8
|
---|
| 126 | #define MOD_CONN_TCP 1
|
---|
| 127 | #define MOD_CONN_UDP 2
|
---|
| 128 | #define MOD_CONN_NET 3
|
---|
| 129 | #define MOD_CONN_SERIAL 4
|
---|
| 130 |
|
---|
| 131 | #ifdef CS_CORE
|
---|
| 132 | char *PIP_ID_TXT[] = { "ECM", "EMM", "LOG", "CIN", "HUP", NULL };
|
---|
| 133 | char *RDR_CD_TXT[] = { "cd", "dsr", "cts", "ring", "none",
|
---|
| 134 | #ifdef USE_GPIO
|
---|
| 135 | "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7",
|
---|
| 136 | #endif
|
---|
| 137 | NULL };
|
---|
| 138 | #else
|
---|
| 139 | extern char *PIP_ID_TXT[];
|
---|
| 140 | extern char *RDR_CD_TXT[];
|
---|
| 141 | #endif
|
---|
| 142 |
|
---|
| 143 | #define PIP_ID_ECM 0
|
---|
| 144 | #define PIP_ID_EMM 1
|
---|
| 145 | #define PIP_ID_LOG 2
|
---|
| 146 | #define PIP_ID_CIN 3 // CARD_INFO
|
---|
| 147 | #define PIP_ID_HUP 4
|
---|
| 148 | #define PIP_ID_MAX PIP_ID_HUP
|
---|
| 149 | #define PIP_ID_DCW 5
|
---|
| 150 |
|
---|
| 151 | #define PIP_ID_ERR (-1)
|
---|
| 152 | #define PIP_ID_DIR (-2)
|
---|
| 153 | #define PIP_ID_NUL (-3)
|
---|
| 154 |
|
---|
| 155 | #define cdiff *c_start
|
---|
| 156 |
|
---|
| 157 | #define NCD_AUTO 0
|
---|
| 158 | #define NCD_524 1
|
---|
| 159 | #define NCD_525 2
|
---|
| 160 |
|
---|
| 161 | #define CS_ANTICASC
|
---|
| 162 |
|
---|
[94] | 163 | // moved from reader-common.h
|
---|
| 164 | #define CARD_INSERTED 1
|
---|
| 165 | #define CARD_NEED_INIT 2
|
---|
| 166 | #define CARD_FAILURE 4
|
---|
| 167 |
|
---|
[8] | 168 | enum {E1_GLOBAL=0, E1_USER, E1_READER, E1_SERVER, E1_LSERVER};
|
---|
| 169 | enum {E2_GLOBAL=0, E2_GROUP, E2_CAID, E2_IDENT, E2_CLASS, E2_CHID, E2_QUEUE,
|
---|
| 170 | E2_EA_LEN, E2_F0_LEN, E2_OFFLINE, E2_SID};
|
---|
| 171 |
|
---|
| 172 | //typedef unsigned char uchar;
|
---|
| 173 | //typedef unsigned long ulong;
|
---|
| 174 |
|
---|
| 175 | typedef struct s_classtab
|
---|
| 176 | {
|
---|
| 177 | uchar an;
|
---|
| 178 | uchar bn;
|
---|
| 179 | uchar aclass[31];
|
---|
| 180 | uchar bclass[31];
|
---|
| 181 | } GCC_PACK CLASSTAB;
|
---|
| 182 |
|
---|
| 183 | typedef struct s_caidtab
|
---|
| 184 | {
|
---|
| 185 | ushort caid[CS_MAXCAIDTAB];
|
---|
| 186 | ushort mask[CS_MAXCAIDTAB];
|
---|
| 187 | ushort cmap[CS_MAXCAIDTAB];
|
---|
| 188 | } GCC_PACK CAIDTAB;
|
---|
| 189 |
|
---|
[41] | 190 | typedef struct s_tuntab
|
---|
| 191 | {
|
---|
| 192 | ushort bt_caidfrom[CS_MAXTUNTAB];
|
---|
| 193 | ushort bt_caidto[CS_MAXTUNTAB];
|
---|
| 194 | ushort bt_srvid[CS_MAXTUNTAB];
|
---|
| 195 | } GCC_PACK TUNTAB;
|
---|
| 196 |
|
---|
[8] | 197 | typedef struct s_sidtab
|
---|
| 198 | {
|
---|
| 199 | char label[33];
|
---|
| 200 | ushort num_caid;
|
---|
| 201 | ushort num_provid;
|
---|
| 202 | ushort num_srvid;
|
---|
| 203 | ushort *caid;
|
---|
| 204 | ulong *provid;
|
---|
| 205 | ushort *srvid;
|
---|
| 206 | struct s_sidtab *next;
|
---|
| 207 | } GCC_PACK SIDTAB;
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | typedef struct s_filter
|
---|
| 211 | {
|
---|
| 212 | ushort caid;
|
---|
| 213 | uchar nprids;
|
---|
| 214 | ulong prids[CS_MAXPROV];
|
---|
| 215 | } GCC_PACK FILTER;
|
---|
| 216 |
|
---|
| 217 | typedef struct s_ftab
|
---|
| 218 | {
|
---|
| 219 | int nfilts;
|
---|
| 220 | FILTER filts[CS_MAXFILTERS];
|
---|
| 221 | } GCC_PACK FTAB;
|
---|
| 222 |
|
---|
| 223 | typedef struct s_port
|
---|
| 224 | {
|
---|
| 225 | int fd;
|
---|
| 226 | int s_port;
|
---|
| 227 | FTAB ftab;
|
---|
| 228 | } GCC_PACK PORT;
|
---|
| 229 |
|
---|
| 230 | typedef struct s_ptab
|
---|
| 231 | {
|
---|
| 232 | int nports;
|
---|
| 233 | PORT ports[CS_MAXPORTS];
|
---|
| 234 | } GCC_PACK PTAB;
|
---|
| 235 |
|
---|
| 236 | struct s_ecm
|
---|
| 237 | {
|
---|
| 238 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
| 239 | uchar cw[16];
|
---|
| 240 | ushort caid;
|
---|
| 241 | ulong prid;
|
---|
| 242 | ulong grp;
|
---|
| 243 | // int level;
|
---|
| 244 | };
|
---|
| 245 |
|
---|
| 246 | struct s_emm
|
---|
| 247 | {
|
---|
| 248 | uchar emm[CS_EMMSTORESIZE];
|
---|
| 249 | uchar type;
|
---|
| 250 | int count;
|
---|
| 251 | };
|
---|
| 252 |
|
---|
| 253 | struct s_module
|
---|
| 254 | {
|
---|
| 255 | //int fd;
|
---|
| 256 | int multi;
|
---|
| 257 | int type;
|
---|
| 258 | int watchdog;
|
---|
| 259 | char desc[16];
|
---|
| 260 | char *logtxt;
|
---|
| 261 | //int s_port;
|
---|
| 262 | in_addr_t s_ip;
|
---|
| 263 | void (*s_handler)();
|
---|
| 264 | int (*recv)();
|
---|
| 265 | void (*send_dcw)();
|
---|
| 266 | int c_multi;
|
---|
| 267 | int (*c_recv_chk)();
|
---|
| 268 | int (*c_init)();
|
---|
| 269 | int (*c_send_ecm)();
|
---|
| 270 | int (*c_init_log)();
|
---|
| 271 | int (*c_recv_log)();
|
---|
| 272 | int c_port;
|
---|
| 273 | PTAB *ptab;
|
---|
| 274 | };
|
---|
| 275 |
|
---|
| 276 | struct s_irdeto_quess
|
---|
| 277 | {
|
---|
| 278 | int b47;
|
---|
| 279 | ushort caid;
|
---|
| 280 | ushort sid;
|
---|
| 281 | struct s_irdeto_quess *next;
|
---|
| 282 | };
|
---|
| 283 |
|
---|
| 284 | struct s_client
|
---|
| 285 | {
|
---|
| 286 | pid_t pid;
|
---|
| 287 | in_addr_t ip;
|
---|
| 288 | in_port_t port;
|
---|
| 289 | time_t login;
|
---|
| 290 | time_t last;
|
---|
| 291 | time_t lastswitch;
|
---|
| 292 | time_t lastemm;
|
---|
| 293 | time_t lastecm;
|
---|
| 294 | ulong grp;
|
---|
| 295 | int crypted;
|
---|
| 296 | int dup;
|
---|
| 297 | int au;
|
---|
| 298 | int monlvl;
|
---|
| 299 | int dbglvl;
|
---|
| 300 | CAIDTAB ctab;
|
---|
[41] | 301 | TUNTAB ttab;
|
---|
[8] | 302 | ulong sidtabok; // positiv services
|
---|
| 303 | ulong sidtabno; // negative services
|
---|
| 304 | int typ;
|
---|
| 305 | int ctyp;
|
---|
| 306 | int stat;
|
---|
| 307 | int ufd;
|
---|
| 308 | int last_srvid;
|
---|
| 309 | int last_caid;
|
---|
| 310 | int tosleep;
|
---|
| 311 | char usr[32];
|
---|
| 312 | int udp_fd;
|
---|
| 313 | int fd_m2c;
|
---|
| 314 | struct sockaddr_in udp_sa;
|
---|
| 315 | int log;
|
---|
| 316 | int logcounter;
|
---|
| 317 | int cwfound;
|
---|
| 318 | int cwcache;
|
---|
| 319 | int cwnot;
|
---|
| 320 | uchar ucrc[4]; // needed by monitor and used by camd35
|
---|
| 321 | ulong pcrc; // pwd crc
|
---|
| 322 | AES_KEY aeskey; // needed by monitor and used by camd33, camd35
|
---|
| 323 | ushort ncd_msgid;
|
---|
| 324 | uchar ncd_skey[16];
|
---|
| 325 | int port_idx; // index in server ptab
|
---|
| 326 | int ncd_server; // newcamd server?
|
---|
| 327 | #ifdef CS_ANTICASC
|
---|
| 328 | ushort ac_idx;
|
---|
| 329 | ushort ac_limit;
|
---|
| 330 | uchar ac_penalty;
|
---|
| 331 | #endif
|
---|
| 332 | FTAB fchid;
|
---|
| 333 | FTAB ftab; // user [caid] and ident filter
|
---|
| 334 | CLASSTAB cltab;
|
---|
| 335 | };
|
---|
| 336 |
|
---|
| 337 | struct s_reader
|
---|
| 338 | {
|
---|
| 339 | int cs_idx;
|
---|
| 340 | int fd;
|
---|
| 341 | ulong grp;
|
---|
| 342 | int fallback;
|
---|
| 343 | int typ;
|
---|
| 344 | int card_system;
|
---|
| 345 | char label[32];
|
---|
| 346 | char device[128];
|
---|
| 347 | int detect;
|
---|
[9] | 348 | int mhz;
|
---|
[14] | 349 | int custom_speed;
|
---|
[8] | 350 | int r_port;
|
---|
| 351 | char r_usr[64];
|
---|
| 352 | char r_pwd[64];
|
---|
| 353 | int r_crypted;
|
---|
| 354 | int l_port;
|
---|
| 355 | int log_port;
|
---|
| 356 | CAIDTAB ctab;
|
---|
[83] | 357 | ulong boxid;
|
---|
[89] | 358 | uchar aes_key[16];
|
---|
[8] | 359 | ulong sidtabok; // positiv services
|
---|
| 360 | ulong sidtabno; // negative services
|
---|
| 361 | uchar hexserial[8];
|
---|
| 362 | int nprov;
|
---|
| 363 | uchar prid[CS_MAXPROV][8];
|
---|
| 364 | uchar availkeys[CS_MAXPROV][16]; // viaccess; misused in seca, if availkeys[PROV][0]=0 then expired, 1 then valid.
|
---|
| 365 | uchar sa[CS_MAXPROV][4]; // viaccess & seca
|
---|
| 366 | ushort acs; // irdeto
|
---|
| 367 | ushort caid[16];
|
---|
| 368 | uchar b_nano[256];
|
---|
[38] | 369 | char pincode[5];
|
---|
[8] | 370 | int logemm;
|
---|
| 371 | int cachemm;
|
---|
| 372 | int rewritemm;
|
---|
| 373 | int online;
|
---|
[94] | 374 | int card_status;
|
---|
[8] | 375 | struct s_module ph;
|
---|
| 376 | uchar ncd_key[16];
|
---|
| 377 | uchar ncd_skey[16];
|
---|
| 378 | int ncd_disable_server_filt;
|
---|
| 379 | ushort ncd_msgid;
|
---|
| 380 | int ncd_proto;
|
---|
| 381 | uchar tcp_connected;
|
---|
| 382 | int tcp_ito; // inactivity timeout
|
---|
| 383 | int tcp_rto; // reconnect timeout
|
---|
| 384 | time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect )
|
---|
| 385 | time_t last_s; // send
|
---|
| 386 | uchar show_cls; // number of classes subscription showed on kill -31
|
---|
| 387 | int maxqlen; // max queue length
|
---|
| 388 | int qlen; // current queue length
|
---|
| 389 | FTAB fchid;
|
---|
| 390 | FTAB ftab;
|
---|
| 391 | CLASSTAB cltab;
|
---|
| 392 | uchar gbox_pwd[4];
|
---|
| 393 | uchar gbox_timecode[7];
|
---|
| 394 | int gbox_online;
|
---|
| 395 | uchar gbox_vers;
|
---|
| 396 | uchar gbox_prem;
|
---|
| 397 | int gbox_fd;
|
---|
| 398 | struct timeb gbox_lasthello; // incoming time stamp
|
---|
| 399 | #ifdef CS_RDR_INIT_HIST
|
---|
| 400 | uchar init_history[1024];
|
---|
| 401 | int init_history_pos;
|
---|
| 402 | #endif
|
---|
| 403 | };
|
---|
| 404 |
|
---|
| 405 | #ifdef CS_ANTICASC
|
---|
| 406 |
|
---|
| 407 | struct s_acasc_shm {
|
---|
| 408 | ushort count : 15;
|
---|
| 409 | ushort deny : 1;
|
---|
| 410 | };
|
---|
| 411 |
|
---|
| 412 | struct s_acasc {
|
---|
| 413 | ushort stat[10];
|
---|
| 414 | uchar idx; // current active index in stat[]
|
---|
| 415 | };
|
---|
| 416 |
|
---|
| 417 | struct s_cpmap
|
---|
| 418 | {
|
---|
| 419 | ushort caid;
|
---|
| 420 | ulong provid;
|
---|
| 421 | ushort sid;
|
---|
| 422 | ushort chid;
|
---|
| 423 | ushort dwtime;
|
---|
| 424 | struct s_cpmap *next;
|
---|
| 425 | };
|
---|
| 426 | #endif
|
---|
| 427 |
|
---|
| 428 | struct s_auth
|
---|
| 429 | {
|
---|
| 430 | char usr[33];
|
---|
| 431 | char pwd[33];
|
---|
| 432 | int uniq;
|
---|
| 433 | int au;
|
---|
| 434 | int monlvl;
|
---|
| 435 | ulong grp;
|
---|
| 436 | int tosleep;
|
---|
| 437 | CAIDTAB ctab;
|
---|
| 438 | ulong sidtabok; // positiv services
|
---|
| 439 | ulong sidtabno; // negative services
|
---|
| 440 | FTAB fchid;
|
---|
| 441 | FTAB ftab; // user [caid] and ident filter
|
---|
| 442 | CLASSTAB cltab;
|
---|
[41] | 443 | TUNTAB ttab;
|
---|
[8] | 444 | #ifdef CS_ANTICASC
|
---|
| 445 | int ac_idx;
|
---|
| 446 | int ac_users; // 0 - unlimited
|
---|
| 447 | uchar ac_penalty; // 0 - log, >0 - fake dw
|
---|
| 448 | #endif
|
---|
| 449 | in_addr_t dynip;
|
---|
| 450 | uchar dyndns[64];
|
---|
| 451 | struct s_auth *next;
|
---|
| 452 | };
|
---|
| 453 |
|
---|
| 454 | struct s_srvid
|
---|
| 455 | {
|
---|
| 456 | int srvid;
|
---|
| 457 | char name[33];
|
---|
| 458 | struct s_srvid *next;
|
---|
| 459 | };
|
---|
| 460 |
|
---|
| 461 | struct s_ip
|
---|
| 462 | {
|
---|
| 463 | in_addr_t ip[2];
|
---|
| 464 | struct s_ip *next;
|
---|
| 465 | };
|
---|
| 466 |
|
---|
| 467 | struct s_config
|
---|
| 468 | {
|
---|
| 469 | int nice;
|
---|
| 470 | ulong netprio;
|
---|
[93] | 471 | ulong ctimeout;
|
---|
| 472 | ulong ftimeout;
|
---|
[8] | 473 | int cmaxidle;
|
---|
[57] | 474 | int ulparent;
|
---|
[8] | 475 | ulong delay;
|
---|
| 476 | int bindwait;
|
---|
| 477 | int resolvedelay;
|
---|
| 478 | int tosleep;
|
---|
| 479 | in_addr_t srvip;
|
---|
| 480 | char pidfile[128];
|
---|
| 481 | char usrfile[128];
|
---|
| 482 | struct s_auth *account;
|
---|
| 483 | struct s_srvid *srvid;
|
---|
| 484 | struct s_sidtab *sidtab;
|
---|
| 485 | int mon_port;
|
---|
| 486 | in_addr_t mon_srvip;
|
---|
| 487 | struct s_ip *mon_allowed;
|
---|
| 488 | int mon_aulow;
|
---|
| 489 | int mon_hideclient_to;
|
---|
| 490 | int mon_level;
|
---|
| 491 | int c33_port;
|
---|
| 492 | in_addr_t c33_srvip;
|
---|
| 493 | uchar c33_key[16];
|
---|
| 494 | int c33_crypted;
|
---|
| 495 | int c33_passive;
|
---|
| 496 | struct s_ip *c33_plain;
|
---|
| 497 | int c35_port;
|
---|
| 498 | in_addr_t c35_srvip;
|
---|
| 499 | PTAB c35_tcp_ptab;
|
---|
| 500 | in_addr_t c35_tcp_srvip;
|
---|
| 501 | PTAB ncd_ptab;
|
---|
| 502 | in_addr_t ncd_srvip;
|
---|
| 503 | uchar ncd_key[16];
|
---|
| 504 | int rad_port;
|
---|
| 505 | in_addr_t rad_srvip;
|
---|
| 506 | struct s_ip *rad_allowed;
|
---|
| 507 | char rad_usr[32];
|
---|
| 508 | char ser_device[512];
|
---|
| 509 | int srtimeout; // SerialReaderTimeount in millisec
|
---|
| 510 | int max_log_size;
|
---|
| 511 | int show_ecm_dw;
|
---|
[94] | 512 | int waitforcards;
|
---|
[95] | 513 | int preferlocalcards;
|
---|
[8] | 514 | uchar gbox_pwd[8];
|
---|
| 515 | uchar ignorefile[512];
|
---|
| 516 | uchar cardfile[512];
|
---|
| 517 | uchar gbxShareOnl[512];
|
---|
| 518 | int maxdist;
|
---|
| 519 | int num_locals;
|
---|
| 520 | unsigned long locals[CS_MAXLOCALS];
|
---|
| 521 | //struct s_irdeto_quess *itab[0xff];
|
---|
| 522 | #ifdef CS_ANTICASC
|
---|
| 523 | char ac_enabled;
|
---|
| 524 | int ac_users; // num of users for account (0 - default)
|
---|
| 525 | int ac_stime; // time to collect AC statistics (3 min - default)
|
---|
| 526 | int ac_samples; // qty of samples
|
---|
| 527 | int ac_penalty; // 0 - write to log
|
---|
| 528 | int ac_fakedelay; // 100-1000 ms
|
---|
| 529 | int ac_denysamples;
|
---|
| 530 | char ac_logfile[128];
|
---|
| 531 | struct s_cpmap *cpmap;
|
---|
| 532 | #endif
|
---|
| 533 | // struct s_reader reader[];
|
---|
| 534 | };
|
---|
| 535 |
|
---|
| 536 | typedef struct ecm_request_t
|
---|
| 537 | {
|
---|
| 538 |
|
---|
| 539 | uchar ecm[256];
|
---|
| 540 | uchar cw[16];
|
---|
| 541 | uchar ecmd5[CS_ECMSTORESIZE];
|
---|
| 542 | // uchar l;
|
---|
| 543 | short l;
|
---|
| 544 | ushort caid;
|
---|
| 545 | ushort ocaid;
|
---|
| 546 | ushort srvid;
|
---|
| 547 | ushort chid;
|
---|
| 548 | ushort pid;
|
---|
| 549 | ushort idx;
|
---|
| 550 | ulong prid;
|
---|
| 551 | int reader[CS_MAXREADER];
|
---|
| 552 | int cidx; // client index
|
---|
| 553 | int cpti; // client pending table index
|
---|
| 554 | int stage; // processing stage in server module
|
---|
| 555 | int level; // send-level in client module
|
---|
| 556 | int rc;
|
---|
| 557 | uchar rcEx;
|
---|
| 558 | struct timeb tps; // incoming time stamp
|
---|
[95] | 559 | uchar locals_done;
|
---|
[8] | 560 | ushort gbxCWFrom;
|
---|
| 561 | ushort gbxFrom;
|
---|
| 562 | ushort gbxTo;
|
---|
| 563 |
|
---|
| 564 | uchar gbxForward[16];
|
---|
| 565 | int gbxRidx;
|
---|
| 566 | } GCC_PACK ECM_REQUEST;
|
---|
| 567 |
|
---|
| 568 | typedef struct emm_packet_t
|
---|
| 569 | {
|
---|
| 570 | uchar emm[258];
|
---|
| 571 | uchar l;
|
---|
| 572 | uchar caid[2];
|
---|
| 573 | uchar provid[4];
|
---|
| 574 | uchar hexserial[8];
|
---|
| 575 | uchar type;
|
---|
| 576 | int cidx;
|
---|
| 577 | } GCC_PACK EMM_PACKET;
|
---|
| 578 |
|
---|
[21] | 579 | // oscam-simples
|
---|
[8] | 580 | extern char *remote_txt(void);
|
---|
| 581 | extern char *trim(char *);
|
---|
| 582 | extern char *strtolower(char *);
|
---|
| 583 | extern int gethexval(char);
|
---|
| 584 | extern int cs_atob(uchar *, char *, int);
|
---|
| 585 | extern ulong cs_atoi(char *, int, int);
|
---|
| 586 | extern int byte_atob(char *);
|
---|
| 587 | extern long word_atob(char *);
|
---|
| 588 | extern int key_atob(char *, uchar *);
|
---|
| 589 | extern int key_atob4(char *, uchar *);
|
---|
| 590 | extern char *key_btoa(char *, uchar *);
|
---|
| 591 | extern char *cs_hexdump(int, uchar *, int);
|
---|
| 592 | extern in_addr_t cs_inet_order(in_addr_t);
|
---|
| 593 | extern char *cs_inet_ntoa(in_addr_t);
|
---|
| 594 | extern in_addr_t cs_inet_addr(char *txt);
|
---|
| 595 | extern ulong b2i(int, uchar *);
|
---|
| 596 | extern ullong b2ll(int, uchar *);
|
---|
| 597 | extern uchar *i2b(int, ulong);
|
---|
| 598 | extern ulong a2i(char *, int);
|
---|
| 599 | extern int boundary(int, int);
|
---|
| 600 | extern void cs_ftime(struct timeb *);
|
---|
| 601 | extern void cs_sleepms(int);
|
---|
| 602 | extern int bytes_available(int);
|
---|
| 603 | extern void cs_setpriority(int);
|
---|
| 604 | extern struct s_auth *find_user(char *);
|
---|
| 605 |
|
---|
[21] | 606 | // oscam variables
|
---|
[8] | 607 | extern int pfd, rfd, fd_c2m, fd_m2c, cs_idx, *c_start, cs_ptyp, cs_dblevel, cs_hw;
|
---|
| 608 | extern int *logidx, *loghistidx, *log_fd;
|
---|
| 609 | extern int is_server, *mcl;
|
---|
| 610 | extern uchar mbuf[1024];
|
---|
| 611 | extern ushort len4caid[256];
|
---|
| 612 | extern pid_t master_pid;
|
---|
| 613 | extern struct s_ecm *ecmcache;
|
---|
| 614 | extern struct s_client *client;
|
---|
| 615 | extern struct s_reader *reader;
|
---|
| 616 |
|
---|
| 617 | extern struct card_struct *Cards;
|
---|
| 618 | extern struct idstore_struct *idstore;
|
---|
| 619 | extern unsigned long *IgnoreList;
|
---|
| 620 |
|
---|
| 621 | extern struct s_config *cfg;
|
---|
| 622 | extern char cs_confdir[], *loghist;
|
---|
| 623 | extern EMM_PACKET epg;
|
---|
| 624 | extern struct s_module ph[CS_MAX_MOD];
|
---|
| 625 | extern ECM_REQUEST *ecmtask;
|
---|
| 626 | extern char logfile[256];
|
---|
| 627 | #ifdef CS_ANTICASC
|
---|
| 628 | extern struct s_acasc_shm *acasc;
|
---|
| 629 | extern FILE *fpa;
|
---|
| 630 | extern int use_ac_log;
|
---|
| 631 | #endif
|
---|
| 632 |
|
---|
| 633 |
|
---|
[21] | 634 | // oscam
|
---|
[8] | 635 | extern char *cs_platform(char *);
|
---|
| 636 | extern int recv_from_udpipe(uchar *, int);
|
---|
| 637 | extern char* username(int);
|
---|
| 638 | extern int idx_from_pid(pid_t);
|
---|
| 639 | extern int chk_bcaid(ECM_REQUEST *, CAIDTAB *);
|
---|
| 640 | extern void cs_exit(int sig);
|
---|
| 641 | extern int cs_fork(in_addr_t, in_port_t);
|
---|
| 642 | extern void wait4master(void);
|
---|
| 643 | extern int cs_auth_client(struct s_auth *, char*);
|
---|
| 644 | extern void cs_disconnect_client(void);
|
---|
| 645 | extern int check_ecmcache(ECM_REQUEST *, ulong);
|
---|
| 646 | extern int write_to_pipe(int, int, uchar *, int);
|
---|
| 647 | extern int read_from_pipe(int, uchar **, int);
|
---|
| 648 | extern int write_ecm_request(int, ECM_REQUEST *);
|
---|
| 649 | extern int write_ecm_answer(int, ECM_REQUEST *);
|
---|
| 650 | extern void log_emm_request(int);
|
---|
| 651 | extern ulong chk_provid(uchar *, ushort);
|
---|
| 652 | extern void guess_cardsystem(ECM_REQUEST *);
|
---|
| 653 | extern void guess_irdeto(ECM_REQUEST *);
|
---|
| 654 | extern void get_cw(ECM_REQUEST *);
|
---|
| 655 | extern void do_emm(EMM_PACKET *);
|
---|
| 656 | extern ECM_REQUEST *get_ecmtask(void);
|
---|
[95] | 657 | extern void request_cw(ECM_REQUEST *, int, int);
|
---|
[8] | 658 | extern int send_dcw(ECM_REQUEST *);
|
---|
| 659 | extern int process_input(uchar *, int, int);
|
---|
| 660 | extern int chk_srvid(ECM_REQUEST *, int);
|
---|
| 661 | extern int chk_sfilter(ECM_REQUEST *, PTAB*);
|
---|
| 662 | extern int chk_ufilters(ECM_REQUEST *);
|
---|
| 663 | extern int chk_rfilter(ECM_REQUEST *, struct s_reader *);
|
---|
| 664 | extern int chk_rsfilter(ECM_REQUEST *, int);
|
---|
| 665 | extern int chk_avail_reader(ECM_REQUEST *, struct s_reader *);
|
---|
| 666 | extern void set_signal_handler(int , int , void (*)(int));
|
---|
| 667 | extern void cs_log_config(void);
|
---|
| 668 |
|
---|
| 669 | #ifdef CS_ANTICASC
|
---|
| 670 | //extern void start_anticascader(void);
|
---|
| 671 | extern void init_ac(void);
|
---|
| 672 | extern void ac_init_stat(int);
|
---|
| 673 | extern int ac_init_log(char*);
|
---|
| 674 | extern void ac_do_stat(void);
|
---|
| 675 | extern void ac_init_client(struct s_auth *);
|
---|
| 676 | extern void ac_chk(ECM_REQUEST*, int);
|
---|
| 677 | #endif
|
---|
| 678 |
|
---|
[21] | 679 | // oscam-nano
|
---|
[8] | 680 | extern int chk_class(ECM_REQUEST *, CLASSTAB*, const char*, const char*);
|
---|
| 681 |
|
---|
[21] | 682 | // oscam-config
|
---|
[8] | 683 | extern int init_config(void);
|
---|
| 684 | extern int init_userdb(void);
|
---|
| 685 | extern int init_readerdb(void);
|
---|
| 686 | extern int init_sidtab(void);
|
---|
| 687 | extern int init_srvid(void);
|
---|
| 688 | extern int search_boxkey(ushort, ulong, char *);
|
---|
| 689 | extern void init_len4caid(void);
|
---|
| 690 | extern int init_irdeto_guess_tab(void);
|
---|
| 691 |
|
---|
[21] | 692 | // oscam-reader
|
---|
[8] | 693 | extern int ridx, logfd;
|
---|
| 694 | extern void cs_ri_brk(int);
|
---|
| 695 | extern void cs_ri_log(char *,...);
|
---|
| 696 | extern void start_cardreader(void);
|
---|
| 697 | extern void reader_card_info(void);
|
---|
| 698 |
|
---|
[21] | 699 | // oscam-log
|
---|
[8] | 700 | extern int cs_init_log(char *);
|
---|
| 701 | extern void cs_log(char *,...);
|
---|
| 702 | extern void cs_debug(char *,...);
|
---|
| 703 | extern void cs_ddump(uchar *, int, char *, ...);
|
---|
| 704 | extern void cs_close_log(void);
|
---|
| 705 | extern int cs_init_statistics(char *);
|
---|
| 706 | extern void cs_statistics(int);
|
---|
| 707 | extern void cs_dump(uchar *, int, char *, ...);
|
---|
| 708 |
|
---|
[21] | 709 | // oscam-aes
|
---|
[8] | 710 | extern void aes_set_key(char *);
|
---|
| 711 | extern void aes_encrypt_idx(int, uchar *, int);
|
---|
| 712 | extern void aes_decrypt(uchar *, int);
|
---|
| 713 | #define aes_encrypt(b, n) aes_encrypt_idx(cs_idx, b, n)
|
---|
| 714 |
|
---|
| 715 | // reader-common
|
---|
| 716 | extern int reader_device_init(char *, int);
|
---|
| 717 | extern int reader_checkhealth(void);
|
---|
| 718 | extern int reader_ecm(ECM_REQUEST *);
|
---|
| 719 | extern int reader_emm(EMM_PACKET *);
|
---|
| 720 |
|
---|
| 721 | // reader-irdeto
|
---|
| 722 | extern int irdeto_card_init(uchar *, int);
|
---|
| 723 | extern int irdeto_do_ecm(ECM_REQUEST *);
|
---|
| 724 | extern int irdeto_do_emm(EMM_PACKET *);
|
---|
| 725 | extern int irdeto_card_info(void);
|
---|
| 726 |
|
---|
| 727 | // reader-viaccess
|
---|
| 728 | extern int viaccess_card_init(uchar *, int);
|
---|
| 729 | extern int viaccess_do_ecm(ECM_REQUEST *);
|
---|
| 730 | extern int viaccess_do_emm(EMM_PACKET *);
|
---|
| 731 | extern int viaccess_card_info(void);
|
---|
| 732 |
|
---|
[14] | 733 | // reader-videoguard
|
---|
| 734 | extern int videoguard_card_init(uchar *, int);
|
---|
| 735 | extern int videoguard_do_ecm(ECM_REQUEST *);
|
---|
| 736 | extern int videoguard_do_emm(EMM_PACKET *);
|
---|
| 737 | extern int videoguard_card_info(void);
|
---|
| 738 |
|
---|
[8] | 739 | // reader-cryptoworks
|
---|
| 740 | extern int cryptoworks_card_init(uchar *, int);
|
---|
| 741 | extern int cryptoworks_do_ecm(ECM_REQUEST *);
|
---|
| 742 | extern int cryptoworks_do_emm(EMM_PACKET *);
|
---|
| 743 | extern int cryptoworks_card_info(void);
|
---|
| 744 |
|
---|
| 745 | // reader-seca
|
---|
| 746 | extern int seca_card_init(uchar *, int);
|
---|
| 747 | extern int seca_do_ecm(ECM_REQUEST *);
|
---|
| 748 | extern int seca_do_emm(EMM_PACKET *);
|
---|
| 749 | extern int seca_card_info(void);
|
---|
| 750 |
|
---|
| 751 | // protocol modules
|
---|
| 752 | extern int monitor_send_idx(int, char *);
|
---|
| 753 | extern void module_monitor(struct s_module *);
|
---|
| 754 | extern void module_camd35(struct s_module *);
|
---|
| 755 | extern void module_camd35_tcp(struct s_module *);
|
---|
| 756 | extern void module_camd33(struct s_module *);
|
---|
| 757 | extern void module_newcamd(struct s_module *);
|
---|
| 758 | extern void module_radegast(struct s_module *);
|
---|
[21] | 759 | extern void module_oscam_ser(struct s_module *);
|
---|
[8] | 760 | extern void module_gbox(struct s_module *);
|
---|
| 761 | extern struct timeval *chk_pending(struct timeb tp_ctimeout);
|
---|
| 762 | #endif // CS_GLOBALS
|
---|