- Timestamp:
- 07/13/10 19:44:44 (14 years ago)
- Location:
- branches/threaded
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/threaded/Distribution/doc/man/oscam.conf.5
r2700 r2734 162 162 higher is usage level 163 163 .RE 164 .PP 165 \fBreaderautoloadbalance_save\fP = \fB0\fP|\fBcounts\fP 166 .RS 3n 167 save autoloadbalance statistics: 168 169 0 = saving of autoloadbalance statistics disabled (default) 170 counts = save autoloadbalance statistics every \fBcounts\fP ECMs 171 172 To save CPU power a minimum counts of 100 is recommended. 173 .RE 164 174 .SS "The [monitor] section" 165 175 .PP -
branches/threaded/Distribution/doc/man/oscam.server.5
r2715 r2734 118 118 \fBaeskey\fP = \fBAES key\fP 119 119 .RS 3n 120 AES key for Viaccess SCs 120 16 byte AES key for Viaccess SCs 121 .RE 122 .PP 123 \fBaeskeys\fP = \fBCAID\fP@\fBident\fP:\fBAES key #1\fP[,\fBAES key #2\fP],...[;\fBCAID\fP@\fBident\fP:\fBAES key #2\fP[,\fBAES key #3\fP],...]... 124 .RS 3n 125 mutiple 16 byte AES keys for Viaccess SCs 126 127 example: 128 129 aeskeys = 0100@012345:000102030405060708090a0b0c0d0e0f;0200@543210:0,0,0f0e0d0c0b0a090807060504030201 121 130 .RE 122 131 .PP -
branches/threaded/Distribution/doc/txt/oscam.conf.txt
r2700 r2734 115 115 higher is usage level 116 116 117 readerautoloadbalance_save = 0|counts 118 save autoloadbalance statistics: 119 120 0 = saving of autoloadbalance statistics disabled (default) 121 counts = save autoloadbalance statistics every counts ECMs 122 123 To save CPU power a minimum counts of 100 is recommended. 124 117 125 The [monitor] section 118 126 port = 0|port -
branches/threaded/Distribution/doc/txt/oscam.server.txt
r2715 r2734 1 oscam.server(5) 1 oscam.server(5) oscam.server(5) 2 2 3 3 … … 7 7 8 8 SYNOPSIS 9 The server configuration file for OSCam contains reader parameters. sections in oscam.server are recurring (more10 than one reader possible). At least one [reader] section is required.9 The server configuration file for OSCam contains reader parameters. sections in oscam.server are recurring 10 (more than one reader possible). At least one [reader] section is required. 11 11 12 12 DESCRIPTIONS … … 24 24 constantcw: constant CW file name 25 25 26 constant CW file format: CA (4 digits):ID (6 digits):SID (4 digits):PMT PID (4 digits):ECM PID (4 digits):key27 (16 Bytes seperated by spaces)26 constant CW file format: CA (4 digits):ID (6 digits):SID (4 digits):PMT PID (4 digits):ECM PID (4 dig‐ 27 its):key (16 Bytes seperated by spaces) 28 28 29 29 expample: 1234:123456:1234:1234:1234:00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F … … 66 66 67 67 logport = 0|port 68 camd3 reader logport, camd3 UDP must beactivated, only works if there's no camd3 cascading, 0=disabled,68 camd3 reader logport, camd3 UDP must be activated, only works if there's no camd3 cascading, 0=disabled, 69 69 default=0 70 70 … … 86 86 87 87 aeskey = AES key 88 AES key for Viaccess SCs 88 16 byte AES key for Viaccess SCs 89 90 aeskeys = CAID@ident:AES key #1[,AES key #2],...[;CAID@ident:AES key #2[,AES key #3],...]... 91 mutiple 16 byte AES keys for Viaccess SCs 92 93 example: 94 95 aeskeys = 0100@012345:000102030405060708090a0b0c0d0e0f;0200@543210:0,0,0f0e0d0c0b0a090807060504030201 89 96 90 97 detect = CD|DSR|CTS|RING|NONE|gpio[1-7] … … 95 102 96 103 mhz = frequency 97 set reader frequency in units of 10 kHz, if mhz > cardmhz you are in overclocking mode, refer to OVERCLOCKING,98 default:357104 set reader frequency in units of 10 kHz, if mhz > cardmhz you are in overclocking mode, refer to OVERCLOCK‐ 105 ING, default:357 99 106 100 107 deprecated = 0|1 101 Frist the SC will be initialized in normal mode. If it fails, the SC will be automatically reverted to depre‐102 cated mode, so that the SC speed will not be changed and the communication will remain on normal ATR speed of103 9600 baud.108 Frist the SC will be initialized in normal mode. If it fails, the SC will be automatically reverted to dep‐ 109 recated mode, so that the SC speed will not be changed and the communication will remain on normal ATR 110 speed of 9600 baud. 104 111 105 112 1 = use deprecated SC mode only, default:0 … … 205 212 206 213 readnano = [path]filename 207 write file (usually a copy of a file saved by savenano) to your smartcard, if no path is specified, the speci‐ 208 fied file is searched for in the configuration directory, only valid for physical readers, default:none 214 write file (usually a copy of a file saved by savenano) to your smartcard, if no path is specified, the 215 specified file is searched for in the configuration directory, only valid for physical readers, 216 default:none 209 217 210 218 example: readnano = write.emm … … 232 240 233 241 cccdisableretryecm = 0|1 234 0 = enables ECM retrying: When an ECM request is denied from an CCCam server, OSCam immediatelly sends a new235 ECM request, 1= disables ECM retrying: When an ECM request is denied from an CCCam server, OSCam sends no new236 ECM request, default:0242 0 = enables ECM retrying: When an ECM request is denied from an CCCam server, OSCam immediatelly sends a 243 new ECM request, 1= disables ECM retrying: When an ECM request is denied from an CCCam server, OSCam sends 244 no new ECM request, default:0 237 245 238 246 cccdisableautoblock = 0|1 239 0 = enables auto block: When an ECM request is send to an CCCam server, it tries the SC with the lowest hop. If240 it is denied, the SID is blocked on this SC. When all SC are blocked, the CAID:PROV:SID information is stored241 i n a auto block list and is newer send again, 1= disabled auto block, default: 1247 0 = enables auto block: When an ECM request is send to an CCCam server, it tries the SC with the lowest 248 hop. If it is denied, the SID is blocked on this SC. When all SC are blocked, the CAID:PROV:SID information 249 is stored in a auto block list and is newer send again, 1= disabled auto block, default: 1 242 250 243 251 cccforceresendecm = 0|1 … … 255 263 · Dreambox and other internal readers 256 264 257 For Dreambox and other internal readers the highest possible clockrate will be auto detected. The mhz parameter258 lets you override the values chosen by OSCam, if it differs from 357 and 358, but usually you will not set any259 value for mhz.260 261 For certain Dreamboxes (especially PPC clones) the default mhz parameter leads to slow ECM times and/or "not262 found" ECMs. By setting mhz to values like 200, 300, 400, ... 1600 you can find a value that works for your263 receiver and your card. The higher the mhz value, the slower the ECM time (strange enough).264 265 If you choose the value too low, your card is not recognized (no ATR or "card not supported"). If you choose266 the value too high, you get slow ECM times. Our experience is that either no mhz line, or a line mhz = 1000267 works best.265 For Dreambox and other internal readers the highest possible clockrate will be auto detected. The mhz 266 parameter lets you override the values chosen by OSCam, if it differs from 357 and 358, but usually you 267 will not set any value for mhz. 268 269 For certain Dreamboxes (especially PPC clones) the default mhz parameter leads to slow ECM times and/or 270 "not found" ECMs. By setting mhz to values like 200, 300, 400, ... 1600 you can find a value that works for 271 your receiver and your card. The higher the mhz value, the slower the ECM time (strange enough). 272 273 If you choose the value too low, your card is not recognized (no ATR or "card not supported"). If you 274 choose the value too high, you get slow ECM times. Our experience is that either no mhz line, or a line mhz 275 = 1000 works best. 268 276 269 277 · Phoenix / Smartmouse reader 270 278 271 Overclocking does not work with Windows and Mac OS X. Set mhz equivalent to the frequency of thereader.279 Overclocking does not work with Windows and Mac OS X. Set mhz equivalent to the frequency of the reader. 272 280 OSCam can not set the frequency of the reader. 273 281 … … 276 284 Set the reader frequency with the native Smargo Smartreader+ tool (srp_tools). Do not set mhz and cardmhz. 277 285 278 OSCam tries to set the baudrate automatically. A standard serial port has limited baudrate settings, so SC over‐279 clocking might not work. When using a serial reader the best way for overclocking is connecting it to a FTDI280 based USB to serial port adapter.281 282 If overclocking does notwork, verify the effective baudrate in the logfile. If it deviates too much from the283 requested baudrate, the SC will not be recognized (no ATR) and the value for mhz should be adjusted again. The284 higher the baudrate, the more accurate the effective baudrate can be.286 OSCam tries to set the baudrate automatically. A standard serial port has limited baudrate settings, so SC 287 overclocking might not work. When using a serial reader the best way for overclocking is connecting it to a 288 FTDI based USB to serial port adapter. 289 290 If overclocking does not work, verify the effective baudrate in the logfile. If it deviates too much from the 291 requested baudrate, the SC will not be recognized (no ATR) and the value for mhz should be adjusted again. 292 The higher the baudrate, the more accurate the effective baudrate can be. 285 293 286 294 EXAMPLES … … 375 383 376 384 SEE ALSO 377 list_smargo(1), oscam(1), oscam.ac(5), oscam.cert(5), oscam.conf(5), oscam.guess(5),oscam.ird(5),385 list_smargo(1), oscam(1), oscam.ac(5), oscam.cert(5), oscam.conf(5), oscam.guess(5), oscam.ird(5), 378 386 oscam.provid(5), oscam.services(5), oscam.srvid(5), oscam.user(5) 379 387 380 388 381 389 382 390 oscam.server(5) -
branches/threaded/globals.h
r2715 r2734 346 346 #endif 347 347 348 typedef struct aes_entry { 349 ushort keyid; 350 ushort caid; 351 uint32 ident; 352 AES_KEY key; 353 struct aes_entry *next; 354 } AES_ENTRY; 348 355 349 356 struct s_ecm … … 718 725 time_t lb_usagelevel_time; //time for counting ecms, this creates usagelevel 719 726 time_t lb_last; //time for oldest reader 727 // multi AES linked list 728 AES_ENTRY *aes_list; 720 729 }; 721 730 … … 972 981 ushort srvid; 973 982 int cidx; 983 int reader_avail[CS_MAXREADER]; 974 984 } GCC_PACK GET_READER_STAT; 975 985 … … 1194 1204 extern void * start_cardreader(void *); 1195 1205 extern void reader_card_info(struct s_reader * reader); 1206 extern int hostResolve(); 1196 1207 extern int network_tcp_connection_open(); 1197 1208 extern void network_tcp_connection_close(struct s_reader * reader, int); … … 1215 1226 extern void aes_encrypt_idx(int, uchar *, int); 1216 1227 extern void aes_decrypt(uchar *, int); 1228 extern int aes_decrypt_from_list(AES_ENTRY *list, ushort caid, uint32 provid,int keyid, uchar *buf, int n); 1229 1230 extern void parse_aes_keys(struct s_reader *rdr,char *value); 1231 1217 1232 #define aes_encrypt(b, n) aes_encrypt_idx(cs_idx, b, n) 1218 1233 … … 1231 1246 extern void init_stat(); 1232 1247 extern void add_reader_stat(ADD_READER_STAT *add_stat); 1233 extern int get_best_reader( ushort caid, ulong prid, ushort srvid);1248 extern int get_best_reader(GET_READER_STAT *grs); 1234 1249 1235 1250 #ifdef HAVE_PCSC -
branches/threaded/module-camd35.c
r2720 r2734 30 30 aes_encrypt(sbuf, l); 31 31 32 if (client[cs_idx].is_udp) 33 return(sendto(client[cs_idx].udp_fd, rbuf, l+4, 0, 34 (struct sockaddr *)&client[cs_idx].udp_sa, 35 sizeof(client[cs_idx].udp_sa))); 36 else 37 return(send(client[cs_idx].udp_fd, rbuf, l + 4, 0)); 32 int status; 33 if (client[cs_idx].is_udp) { 34 status = sendto(client[cs_idx].udp_fd, rbuf, l+4, 0, 35 (struct sockaddr *)&client[cs_idx].udp_sa, 36 sizeof(client[cs_idx].udp_sa)); 37 if (status == -1) client[cs_idx].udp_sa.sin_addr.s_addr = 0; 38 } 39 else { 40 status = send(client[cs_idx].udp_fd, rbuf, l + 4, 0); 41 if (status == -1) network_tcp_connection_close(&reader[client[cs_idx].ridx], client[cs_idx].pfd); 42 } 43 return status; 38 44 } 39 45 … … 77 83 { 78 84 if (!client[cs_idx].udp_fd) return(-9); 79 rs =recv(client[cs_idx].udp_fd, buf, l, 0);85 rs = recv(client[cs_idx].udp_fd, buf, l, 0); 80 86 } 81 if (rs <24) rc=-1;87 if (rs < 24) rc = -1; 82 88 break; 83 89 case 1: … … 88 94 case 0: break; // ok 89 95 case 1: rc=-2; break; // unknown user 90 default: rc=-9; break; // error's from cs_auth()96 default: rc=-9; break; // error's from cs_auth() 91 97 } 92 98 break; … … 391 397 392 398 if (client[cs_idx].is_udp) { 393 client[cs_idx].pfd=client[cs_idx].udp_fd; 394 395 //TODO: dirty udp hotfix 396 struct addrinfo hints, *res = NULL; 397 398 memset(&hints, 0, sizeof(hints)); 399 hints.ai_socktype = SOCK_STREAM; 400 hints.ai_family = client[cs_idx].udp_sa.sin_family; 401 hints.ai_protocol = IPPROTO_TCP; 402 403 if (getaddrinfo(reader[client[cs_idx].ridx].device, NULL, &hints, &res) == 0) { 404 client[cs_idx].udp_sa.sin_addr.s_addr = ((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr; 405 client[cs_idx].ip = cs_inet_order(client[cs_idx].udp_sa.sin_addr.s_addr); 406 } else { 407 cs_log("can't resolve %s", reader[client[cs_idx].ridx].device); 408 } 409 if (res) freeaddrinfo(res); 410 } 399 client[cs_idx].pfd=client[cs_idx].udp_fd; 400 } 411 401 412 402 return(0); … … 491 481 client[cs_idx].lastpid = er->pid; 492 482 493 // if (!client[cs_idx].udp_sa.sin_addr.s_addr) // once resolved at least 494 // return(-1); 495 496 if (!client[cs_idx].is_udp && !tcp_connect()) return(-1); 497 483 if (client[cs_idx].is_udp) { 484 if (!client[cs_idx].udp_sa.sin_addr.s_addr) 485 if (!hostResolve()) return -1; 486 } 487 else { 488 if (!tcp_connect()) return -1; 489 } 490 498 491 reader[client[cs_idx].ridx].card_status = CARD_INSERTED; //for udp 499 492 … … 516 509 { 517 510 uchar buf[512]; 518 //if (!client[cs_idx].udp_sa.sin_addr.s_addr) // once resolved at least 519 // return(-1); 520 521 if (!client[cs_idx].is_udp && !tcp_connect()) return(-1); 522 511 512 if (client[cs_idx].is_udp) { 513 if (!client[cs_idx].udp_sa.sin_addr.s_addr) 514 if (!hostResolve()) return -1; 515 } 516 else { 517 if (!tcp_connect()) return -1; 518 } 519 523 520 memset(buf, 0, 20); 524 521 memset(buf+20, 0xff, ep->l+15); -
branches/threaded/module-dvbapi.c
r2720 r2734 305 305 int dvbapi_read_device(int dmx_fd, unsigned char *buf, int length) { 306 306 int len, rc; 307 struct pollfd pfd 3[1];308 309 pfd 3[0].fd = dmx_fd;310 pfd 3[0].events = (POLLIN | POLLPRI);311 312 rc = poll(pfd 3, 1, 2000);307 struct pollfd pfd[1]; 308 309 pfd[0].fd = dmx_fd; 310 pfd[0].events = (POLLIN | POLLPRI); 311 312 rc = poll(pfd, 1, 7000); 313 313 if (rc<1) { 314 314 cs_log("read on %d timed out", dmx_fd); … … 392 392 filter[16]=mask; 393 393 394 dvbapi_set_filter(demux_id, selected_api, pid, filter, filter+16, 4000, pidindex, 0, type);394 dvbapi_set_filter(demux_id, selected_api, pid, filter, filter+16, 7000, pidindex, 0, type); 395 395 } 396 396 … … 598 598 } 599 599 600 void dvbapi_process_emm (int demux_index, unsigned char *buffer, unsigned int len) {600 void dvbapi_process_emm (int demux_index, int filter_num, unsigned char *buffer, unsigned int len) { 601 601 EMM_PACKET epg; 602 static uchar emm_global[512]; 603 static int emm_global_len = 0; 604 int pos, emm_len = 0, k; 605 uchar emmbuf[512]; 602 606 603 607 if (demux[demux_index].pidindex==-1) return; 604 605 cs_ddump(buffer, 16, "emm:"); 608 609 switch (demux[demux_index].ECMpids[demux[demux_index].pidindex].CAID >> 8) { 610 case 0x05: 611 if (len>500) return; 612 switch(buffer[0]) { 613 case 0x8c: 614 case 0x8d: 615 if (!memcmp(emm_global, buffer, len)) return; 616 memcpy(emm_global, buffer, len); 617 emm_global_len=len; 618 //cs_ddump(buffer, len, "viaccess global emm:"); 619 return; 620 case 0x8e: 621 if (!emm_global_len) return; 622 623 memcpy(emmbuf, buffer, 7); 624 memcpy(emmbuf+7, "\x9E\x20", 2); 625 memcpy(emmbuf+9, buffer+7, 32); 626 pos=9+32; 627 for (k=3; k<emm_global[2]+2 && k<emm_global_len; k += emm_global[k+1]+2) { 628 memcpy(emmbuf+pos, emm_global+k, emm_global[k+1]+2); 629 pos += emm_global[k+1]+2; 630 } 631 memcpy(emmbuf+pos, "\xF0\x08", 2); 632 memcpy(emmbuf+pos+2, buffer+41, 8); 633 emm_len=pos+10; 634 emmbuf[2]=emm_len-3; 635 cs_ddump(buffer, len, "original emm:"); 636 memcpy(buffer, emmbuf, emm_len); 637 len=emm_len; 638 break; 639 } 640 break; 641 case 0x0d: 642 if (len>500) return; 643 switch (buffer[0]) { 644 case 0x86: 645 if (!memcmp(emm_global, buffer, len)) return; 646 memcpy(emm_global, buffer, len); 647 emm_global_len=len; 648 cs_ddump(buffer, len, "cryptoworks global emm:"); 649 return; 650 case 0x84: 651 if (!emm_global_len) return; 652 653 memcpy(emmbuf, buffer, 18); 654 pos=18; 655 for (k=5; k<emm_global[2]+2 && k<emm_global_len; k += emm_global[k+1]+2) { 656 memcpy(emmbuf+pos, emm_global+k, emm_global[k+1]+2); 657 pos += emm_global[k+1]+2; 658 } 659 memcpy(emmbuf+pos, buffer+18, len-18); 660 emm_len=pos+(len-18); 661 emmbuf[2]=emm_len-3; 662 cs_ddump(buffer, len, "original emm:"); 663 memcpy(buffer, emmbuf, emm_len); 664 len=emm_len; 665 666 break; 667 } 668 break; 669 } 670 671 672 cs_ddump(buffer, len, "emm from fd %d:", demux[demux_index].demux_fd[filter_num].fd); 606 673 607 674 memset(&epg, 0, sizeof(epg)); … … 1174 1241 return; 1175 1242 } 1176 cs_debug("EMM Filter fd %d", demux[demux_id].demux_fd[filter_num].fd); 1177 dvbapi_process_emm(demux_id, buffer, len); 1243 dvbapi_process_emm(demux_id, filter_num, buffer, len); 1178 1244 } 1179 1245 -
branches/threaded/module-monitor.c
r2700 r2734 234 234 int cs_idx2ridx(int idx){ 235 235 int i; 236 //TODO: ! 237 //for (i = 0; i < CS_MAXREADER; i++)238 // if (reader[i].cs_idx==idx)239 //return(i);236 237 for (i = 0; i < CS_MAXREADER; i++) 238 if (reader[i].cidx==idx) 239 return(i); 240 240 return(-1); 241 241 } -
branches/threaded/module-stat.c
r2715 r2734 229 229 * returns ridx when found or -1 when not found 230 230 */ 231 int get_best_reader( ushort caid, ulong prid, ushort srvid)231 int get_best_reader(GET_READER_STAT *grs) 232 232 { 233 233 int i; … … 236 236 READER_STAT *stat, *best_stat = NULL; 237 237 for (i = 0; i < CS_MAXREADER; i++) { 238 if (reader_stat[i] && reader[i].pid) { 239 if (reader[i].tcp_connected || reader[i].card_status == CARD_INSERTED) { 240 int weight = reader[i].lb_weight <= 0?100:reader[i].lb_weight; 241 stat = get_stat(i, caid, prid, srvid); 242 if (!stat) { 243 add_stat(i, caid, prid, srvid, 1, 0); 244 return -1; //this reader is active (now) but we need statistics first! 245 } 238 if (reader_stat[i] && grs->reader_avail[i]) { 239 int weight = reader[i].lb_weight <= 0?100:reader[i].lb_weight; 240 stat = get_stat(i, grs->caid, grs->prid, grs->srvid); 241 if (!stat) { 242 add_stat(i, grs->caid, grs->prid, grs->srvid, 1, 0); 243 return -1; //this reader is active (now) but we need statistics first! 244 } 246 245 247 if (stat->ecm_count > MAX_ECM_COUNT) { 248 reset_stat(caid, prid, srvid); 246 if (stat->ecm_count > MAX_ECM_COUNT) { 247 reset_stat(grs->caid, grs->prid, grs->srvid); 248 return -1; 249 } 250 251 if (stat->rc == 0 && stat->ecm_count < MIN_ECM_COUNT) { 252 cs_debug_mask(D_TRACE, "loadbalance: reader %s needs more statistics", reader[i].label); 253 return -1; //need more statistics! 254 } 255 256 257 //Reader can decode this service (rc==0) and has MIN_ECM_COUNT ecms: 258 if (stat->rc == 0) { 259 //get 260 switch (cfg->reader_auto_loadbalance) { 261 case LB_NONE: 262 cs_debug_mask(D_TRACE, "loadbalance disabled"); 263 return -1; 264 case LB_FASTEST_READER_FIRST: 265 current = stat->time_avg * 100 / weight; 266 break; 267 case LB_OLDEST_READER_FIRST: 268 current = (reader[i].lb_last-nulltime) * 100 / weight; 269 break; 270 case LB_LOWEST_USAGELEVEL: 271 current = reader[i].lb_usagelevel * 100 / weight; 272 break; 273 default: 249 274 return -1; 250 275 } 251 252 if (stat->rc == 0 && stat->ecm_count < MIN_ECM_COUNT) { 253 cs_debug_mask(D_TRACE, "loadbalance: reader %s needs more statistics", reader[i].label); 254 return -1; //need more statistics! 255 } 256 257 258 //Reader can decode this service (rc==0) and has MIN_ECM_COUNT ecms: 259 if (stat->rc == 0) { 260 //get 261 switch (cfg->reader_auto_loadbalance) { 262 case LB_NONE: 263 cs_debug_mask(D_TRACE, "loadbalance disabled"); 264 return -1; 265 case LB_FASTEST_READER_FIRST: 266 current = stat->time_avg * 100 / weight; 267 break; 268 case LB_OLDEST_READER_FIRST: 269 current = (reader[i].lb_last-nulltime) * 100 / weight; 270 break; 271 case LB_LOWEST_USAGELEVEL: 272 current = reader[i].lb_usagelevel * 100 / weight; 273 break; 274 default: 275 return -1; 276 } 277 278 cs_debug_mask(D_TRACE, "loadbalance reader %s value %d", reader[i].label, current); 279 if (!best_stat || current < best) { 280 if (!reader[i].ph.c_available 281 || reader[i].ph.c_available(i, 282 AVAIL_CHECK_LOADBALANCE)) { 283 best_stat = stat; 284 best_ridx = i; 285 best = current; 286 } 276 277 cs_debug_mask(D_TRACE, "loadbalance reader %s value %d", reader[i].label, current); 278 if (!best_stat || current < best) { 279 if (!reader[i].ph.c_available 280 || reader[i].ph.c_available(i, 281 AVAIL_CHECK_LOADBALANCE)) { 282 best_stat = stat; 283 best_ridx = i; 284 best = current; 287 285 } 288 286 } -
branches/threaded/module-stat.h
r2385 r2734 19 19 void add_reader_stat(ADD_READER_STAT *stat); 20 20 21 int get_best_reader( ushort caid, ulong prid, ushort srvid);21 int get_best_reader(GET_READER_STAT *grs); -
branches/threaded/oscam-config.c
r2700 r2734 3438 3438 } 3439 3439 } 3440 // new code for multiple aes key per reader 3441 if (!strcmp(token, "aeskeys")) { 3442 parse_aes_keys(rdr,value); 3443 return; 3444 } 3440 3445 3441 3446 if (token[0] != '#') … … 3844 3849 } 3845 3850 3851 -
branches/threaded/oscam-reader.c
r2715 r2734 134 134 } 135 135 136 int network_tcp_connection_open() 137 { 138 cs_log("connecting to %s", reader[client[cs_idx].ridx].device); 136 int hostResolve() 137 { 139 138 pthread_mutex_lock(&gethostbyname_lock); 140 139 struct addrinfo hints, *res = NULL; … … 150 149 ((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr; 151 150 client[cs_idx].ip = cs_inet_order(client[cs_idx].udp_sa.sin_addr.s_addr); 151 152 if (client[client[cs_idx].idx].ip != last_ip) { 153 uchar *ip = (uchar*) &client[cs_idx].ip; 154 cs_debug("%s: resolved ip=%d.%d.%d.%d", reader[client[cs_idx].ridx].device, ip[3], ip[2], ip[1], ip[0]); 155 } 152 156 } 153 157 else { 158 client[cs_idx].udp_sa.sin_addr.s_addr = 0; 154 159 cs_log("can't resolve %s", reader[client[cs_idx].ridx].device); 155 160 } 156 161 if (res) freeaddrinfo(res); 157 162 pthread_mutex_unlock(&gethostbyname_lock); 158 159 if (!client[cs_idx].udp_sa.sin_addr.s_addr)160 return -1;161 163 162 if (client[client[cs_idx].idx].ip != last_ip) { 163 uchar *ip = (uchar*) &client[cs_idx].ip; 164 cs_debug("%s: resolved ip=%d.%d.%d.%d", reader[client[cs_idx].ridx].device, ip[3], ip[2], ip[1], ip[0]); 165 } 166 //----------- 167 164 return (client[cs_idx].udp_sa.sin_addr.s_addr) ? 1 : 0; 165 } 166 167 int network_tcp_connection_open() 168 { 169 cs_log("connecting to %s", reader[client[cs_idx].ridx].device); 170 171 if (!hostResolve()) 172 return -1; 173 168 174 int sd = client[cs_idx].udp_fd; 169 175 if (connect(sd, (struct sockaddr *)&client[cs_idx].udp_sa, sizeof(client[cs_idx].udp_sa)) == 0) 170 176 return sd; 171 177 172 178 if (errno == EINPROGRESS || errno == EALREADY) { 173 174 175 uint l = sizeof(r);176 if (getsockopt(sd, SOL_SOCKET, SO_ERROR, &r, (socklen_t*)&l) == 0) {177 if (r == 0) return sd;178 179 179 if (network_select(0, DEFAULT_CONNECT_TIMEOUT) > 0) { 180 int r = -1; 181 uint l = sizeof(r); 182 if (getsockopt(sd, SOL_SOCKET, SO_ERROR, &r, (socklen_t*)&l) == 0) { 183 if (r == 0) return sd; 184 } 185 } 180 186 } 181 187 else if (errno == EBADF || errno == ENOTSOCK) { … … 221 227 222 228 if (client[cs_idx].ecmtask) { 223 224 225 226 229 for (i = 0; i < CS_MAXPENDING; i++) { 230 client[cs_idx].ecmtask[i].idx = 0; 231 client[cs_idx].ecmtask[i].rc = 0; 232 } 227 233 } 228 234 -
branches/threaded/oscam-simples.c
r2715 r2734 22 22 for(i=0; i<n; i+=16) 23 23 AES_encrypt(buf+i, buf+i, &client[idx].aeskey); 24 } 25 26 void add_aes_entry(struct s_reader *rdr, ushort caid, uint32 ident, int keyid, uchar *aesKey) 27 { 28 AES_ENTRY *new_entry; 29 AES_ENTRY *next,*current; 30 31 // create de AES key entry for the linked list 32 new_entry=malloc(sizeof(AES_ENTRY)); 33 if(!new_entry) { 34 cs_log("Error alocation memory for AES key entry"); 35 return; 36 } 37 38 new_entry->caid=caid; 39 new_entry->ident=ident; 40 new_entry->keyid=keyid; 41 AES_set_decrypt_key((const unsigned char *)aesKey, 128, &(new_entry->key)); 42 new_entry->next=NULL; 43 44 //if list is empty, new_entry is the new head 45 if(!rdr->aes_list) { 46 rdr->aes_list=new_entry; 47 return; 48 } 49 50 //happend it to the list 51 current=rdr->aes_list; 52 next=current->next; 53 while(next) { 54 current=next; 55 next=current->next; 56 } 57 58 current->next=new_entry; 59 60 } 61 62 void parse_aes_entry(struct s_reader *rdr,char *value) { 63 ushort caid; 64 uint32 ident; 65 int len; 66 char *tmp; 67 int nb_keys,key_id; 68 uchar aes_key[16]; 69 char *save=NULL; 70 71 tmp=strtok_r(value,"@",&save); 72 caid=a2i(tmp,2); 73 tmp=strtok_r(NULL,":",&save); 74 ident=a2i(tmp,3); 75 76 // now we need to split the key ane add the entry to the reader. 77 nb_keys=0; 78 key_id=0; 79 while((tmp=strtok_r(NULL,",",&save))) { 80 len=strlen(tmp); 81 if(len!=32) { 82 if(len!=1) 83 cs_log("AES key length error .. not adding"); 84 key_id++; 85 continue; 86 } 87 nb_keys++; 88 key_atob(tmp,aes_key); 89 // now add the key to the reader... TBD 90 add_aes_entry(rdr,caid,ident,key_id,aes_key); 91 key_id++; 92 } 93 94 cs_log("%d AES key(s) added on reader %s for %04x:%06x", nb_keys, rdr->label, caid, ident); 95 } 96 97 void parse_aes_keys(struct s_reader *rdr,char *value) 98 { 99 // value format is caid1@ident1:key0,key1;caid2@indent2:key0,key1 100 char *entry; 101 char *save=NULL; 102 103 rdr->aes_list=NULL; 104 for (entry=strtok_r(value, ";",&save); entry; entry=strtok_r(NULL, ";",&save)) { 105 cs_debug("AES key entry=%s",entry); 106 parse_aes_entry(rdr,entry); 107 } 108 109 /* 110 AES_ENTRY *current; 111 current=rdr->aes_list; 112 while(current) { 113 cs_log("**************************"); 114 cs_log("current = %p",current); 115 cs_log("CAID = %04x",current->caid); 116 cs_log("IDENT = %06x",current->ident); 117 cs_log("keyID = %d",current->keyid); 118 cs_log("next = %p",current->next); 119 cs_log("**************************"); 120 current=current->next; 121 } 122 */ 123 } 124 125 int aes_decrypt_from_list(AES_ENTRY *list, ushort caid, uint32 provid,int keyid, uchar *buf, int n) 126 { 127 int OK=1; 128 int ERROR=0; 129 AES_ENTRY *current; 130 int i; 131 current=list; 132 while(current) { 133 if(current->caid==caid && current->ident==provid && current->keyid==keyid) 134 break; 135 current=current->next; 136 } 137 138 if(!current) { 139 cs_log("AES Decrypt : key id %d not found for CAID %04X , provider %06x",keyid,caid,provid); 140 return ERROR; // we don't have the key to decode this buffer. 141 } 142 else { 143 // decode the key 144 for(i=0; i<n; i+=16) 145 AES_decrypt(buf+i, buf+i, &(current->key)); 146 } 147 return OK; // all ok, key decoded. 24 148 } 25 149 -
branches/threaded/oscam.c
r2720 r2734 1292 1292 int write_to_pipe(int fd, int id, uchar *data, int n) 1293 1293 { 1294 // check is write to pipe ready if fails check 1295 // one more time and give up if fails 1294 // check is write to pipe ready 1296 1295 if (!pipe_WaitToWrite(fd, 100)) 1297 1296 return -1; … … 1987 1986 1988 1987 //receive best reader from master process. Call this function from client! 1989 int recv_best_reader(ECM_REQUEST *er )1988 int recv_best_reader(ECM_REQUEST *er, int *reader_avail) 1990 1989 { 1991 1990 if (!cfg->reader_auto_loadbalance) … … 1997 1996 grs.srvid = er->srvid; 1998 1997 grs.cidx = cs_idx; 1998 memcpy(grs.reader_avail, reader_avail, sizeof(int)*CS_MAXREADER); 1999 1999 cs_debug_mask(D_TRACE, "requesting client %s best reader for %04X/%04X/%04X", username(cs_idx), grs.caid, grs.prid, grs.srvid); 2000 2000 write_to_pipe(fd_c2m, PIP_ID_BES, (uchar*)&grs, sizeof(GET_READER_STAT)); … … 2187 2187 2188 2188 if (cfg->reader_auto_loadbalance) { 2189 int best_ridx = recv_best_reader(er); 2189 int reader_avail[CS_MAXREADER]; 2190 for (i =0; i < CS_MAXREADER; i++) 2191 reader_avail[i] = matching_reader(er, &reader[i]); 2192 2193 int best_ridx = recv_best_reader(er, reader_avail); 2190 2194 for (i = m = 0; i < CS_MAXREADER; i++) 2191 if ( matching_reader(er, &reader[i])) {2195 if (reader_avail[i]) { 2192 2196 //When autobalance enabled, all other readers are fallbacks: 2193 2197 m|=er->reader[i] = (best_ridx >= 0 && best_ridx != i)? 2: 1; … … 2401 2405 if (er->stage) { 2402 2406 er->rc=5; // timeout 2407 if (cfg->reader_auto_loadbalance) { 2408 int r; 2409 for (r=0; r<CS_MAXREADER; r++) 2410 if (er->reader[r]) 2411 send_reader_stat(r, er, 5); 2412 } 2403 2413 send_dcw(er); 2404 2414 continue; … … 2486 2496 { 2487 2497 //cs_debug_mask(D_TRACE, "got request for best reader for %04X/%04X/%04X", grs->caid, grs->prid, grs->srvid); 2488 int ridx = get_best_reader(grs ->caid, grs->prid, grs->srvid);2498 int ridx = get_best_reader(grs); 2489 2499 //cs_debug_mask(D_TRACE, "sending best reader %d", ridx); 2490 2500 write_to_pipe(client[grs->cidx].fd_m2c, PIP_ID_BES, (uchar*)&ridx, sizeof(ridx)); -
branches/threaded/reader-cryptoworks.c
r2667 r2734 505 505 { 506 506 filter[0]=0xFF; 507 filter[1]= 3;507 filter[1]=4; 508 508 509 509 filter[2]=GLOBAL; … … 552 552 filter[72+12] = 0x05; 553 553 filter[72+12+16] = 0xFF; 554 555 filter[104]=GLOBAL; 556 filter[105]=0; 557 558 filter[106+0] = 0x86; 559 filter[106+16] = 0xFF; 554 560 555 561 return; -
branches/threaded/reader-viaccess.c
r2533 r2734 227 227 const uchar *ecm88Data=er->ecm+4; //XXX what is the 4th byte for ?? 228 228 int ecm88Len=SCT_LEN(er->ecm)-4; 229 ulong provid ;229 ulong provid=0; 230 230 int rc=0; 231 231 int hasD2 = 0; … … 235 235 uchar keyToUse=0; 236 236 uchar DE04[256]; 237 int D2KeyID=0; 237 238 memset(DE04, 0, sizeof(DE04)); //fix dorcel de04 bug 238 239 … … 257 258 // FIXME: use the d2 arguments 258 259 int len = ecm88Data[1] + 2; 260 D2KeyID=ecm88Data[3]; 259 261 ecm88Data += len; 260 262 ecm88Len -= len; … … 378 380 379 381 if (hasD2) { 380 aes_decrypt(er->cw, 16); 382 if(reader->aes_list) { 383 cs_debug("Decoding CW : using AES key id %d for provider %06x",D2KeyID,provid); 384 rc=aes_decrypt_from_list(reader->aes_list,0x500, (uint32) provid, D2KeyID,er->cw, 16); 385 } 386 else 387 aes_decrypt(er->cw, 16); 381 388 } 382 389 … … 418 425 { 419 426 filter[0]=0xFF; 420 filter[1]= 3;427 filter[1]=2; 421 428 422 429 filter[2]=GLOBAL; … … 424 431 425 432 filter[4+0] = 0x8D; 426 filter[4+0+16] = 0xF F;427 filter[4+1] = 0xFF; // FIXME: dummy, flood client with EMM's428 filter[4+1+16] = 0xFF;433 filter[4+0+16] = 0xFE; 434 //filter[4+6] = 0xA0; // FIXME: dummy, flood client with EMM's 435 //filter[4+6+16] = 0xF0; 429 436 430 437
Note:
See TracChangeset
for help on using the changeset viewer.