Changeset 5163
- Timestamp:
- 05/02/11 14:58:16 (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/globals.h
r5149 r5163 596 596 void * origin_card; //CCcam preferred card! 597 597 598 void *src_data; 599 598 600 struct s_ecm *ecmcacheptr; //Pointer to ecm-cw-rc-cache! 599 601 -
trunk/module-gbox.c
r5087 r5163 50 50 int32_t ecm_idx; 51 51 int32_t hello_expired; 52 int32_t hello_initial; 52 53 uchar cws[16]; 53 54 struct gbox_peer peer; … … 56 57 sem_t sem; 57 58 LLIST *local_cards; 59 }; 60 61 struct gbox_ecm_info { 62 uint16_t peer, 63 extra; 64 uchar version, 65 type, 66 slot, 67 unknwn1, 68 unknwn2, 69 ncards; 70 uchar checksums[14]; 58 71 }; 59 72 … … 253 266 } 254 267 255 uint32_t ecm_getcrc(ECM_REQUEST *er, int32_t ecmlen)268 uint32_t gbox_get_ecmchecksum(ECM_REQUEST *er) 256 269 { 257 270 … … 259 272 int32_t counter; 260 273 261 uchar ecm[ 0xFF];274 uchar ecm[255]; 262 275 memcpy(ecm, er->ecm, er->l); 263 276 264 checksum[3] = ecm[0];265 checksum[2] = ecm[1];266 checksum[1] = ecm[2];267 checksum[0] = ecm[3];268 269 for (counter=1; counter < (ecmlen/4) - 4; counter++) {270 checksum[3] ^= ecm[counter*4];271 checksum[2] ^= ecm[counter*4+1];272 checksum[1] ^= ecm[counter*4+2];273 checksum[0] ^= ecm[counter*4+3];274 } 275 276 return checksum[3] << 24 | checksum[2] <<16 | checksum[1]<<8 | checksum[0];277 checksum[3] = ecm[0]; 278 checksum[2] = ecm[1]; 279 checksum[1] = ecm[2]; 280 checksum[0] = ecm[3]; 281 282 for (counter=1; counter < (er->l/4) - 4; counter++) { 283 checksum[3] ^= ecm[counter*4]; 284 checksum[2] ^= ecm[counter*4+1]; 285 checksum[1] ^= ecm[counter*4+2]; 286 checksum[0] ^= ecm[counter*4+3]; 287 } 288 289 return checksum[3] << 24 | checksum[2] << 16 | checksum[1] << 8 | checksum[0]; 277 290 } 278 291 … … 392 405 } 393 406 407 /* 408 // TODO send on serious error 409 static void gbox_send_goodbye(struct s_client *cli) 410 { 411 struct gbox_data *gbox = cli->gbox; 412 413 uchar buf[20]; 414 415 gbox_code_cmd(buf, MSG_GOODBYE); 416 memcpy(buf + 2, gbox->peer.key, 4); 417 memcpy(buf + 6, gbox->key, 4); 418 419 cs_debug_mask(D_READER, "gbox: send goodbye:", cs_hexdump(0, buf, 10)); 420 421 gbox_send(cli, buf, 11); 422 } 423 */ 424 394 425 static void gbox_send_hello(struct s_client *cli) 395 426 { … … 414 445 memcpy(buf + 2, gbox->peer.key, 4); 415 446 memcpy(buf + 6, gbox->key, 4); 416 buf[10] = 1;447 buf[10] = gbox->hello_initial ^ 1; // initial HELLO = 0, subsequent = 1 417 448 buf[11] = 0x80; // TODO this needs adjusting to allow for packet splitting 418 449 … … 451 482 452 483 if (++gbox->peer.hello_count == 2) gbox->peer.hello_count = 0; 484 gbox->hello_initial = 0; 453 485 454 486 gbox_send(cli, buf, len); … … 642 674 643 675 cs_debug_mask(D_READER, "gbox: received cws=%s, peer=%04x, ecm_pid=%d, sid=%d", 644 data[10] << 8 | data[11], data[6] << 8 | data[7], data[8] << 8 | data[9], cs_hexdump(0, gbox->cws, 16));676 cs_hexdump(0, gbox->cws, 16), data[10] << 8 | data[11], data[6] << 8 | data[7], data[8] << 8 | data[9]); 645 677 break; 646 678 case MSG_CHECKCODE: … … 648 680 cs_debug_mask(D_READER, "gbox: received checkcode=%s", cs_hexdump(0, gbox->peer.checkcode, 7)); 649 681 break; 650 /*case MSG_GSMS: 682 /*case MSG_GSMS: // TODO 651 683 //gbox_handle_gsms(peerid, gsms); 652 684 break; 653 685 */ 654 686 case MSG_ECM: //TODO: 687 { 688 // TODO: This is !!DIRTY!! 689 cli->typ = 'c'; 690 cli->ctyp = 6; 691 692 struct s_auth *account; 693 int32_t ok=0; 694 for (ok=0, account=cfg.account; (account) && (!ok); account=account->next) 695 if( (ok=!strcmp(cli->reader->r_usr, account->usr)) ) 696 break; 697 cs_auth_client(cli, ok ? account : (struct s_auth *)(-1), "gbox"); 698 699 ECM_REQUEST *er = get_ecmtask(); 700 701 struct gbox_ecm_info *ei = calloc(1, sizeof( struct gbox_ecm_info)); 702 er->src_data = ei; 703 704 cli->typ = 'r'; 705 706 static uchar ecm_idx = 0; 707 uchar *ecm = data + 18; 708 709 er->idx = ++ecm_idx; 710 er->l = ecm[2] + 3; 711 er->pid = data[10] << 8 | data[11]; 712 er->srvid = data[12] << 8 | data[13]; 713 ei->extra = data[14] << 8 | data[15]; 714 memcpy(er->ecm, data + 18, er->l); 715 716 ei->ncards = data[16]; 717 718 ei->peer = ecm[er->l] << 8 | ecm[er->l + 1]; 719 ei->version = ecm[er->l + 2]; 720 ei->type = ecm[er->l + 4]; 721 er->caid = ecm[er->l + 5] << 8 | ecm[er->l + 6]; 722 er->prid = ecm[er->l + 7] << 8 | ecm[er->l + 8]; 723 ei->slot = ecm[er->l + 12]; 724 ei->unknwn1 = ecm[er->l + 3]; 725 ei->unknwn2 = ecm[er->l + 13]; 726 memcpy(ei->checksums, ecm + er->l + 14, 14); 727 728 cs_log("gbox: ecm received, caid=%04x. provid=%x, sid=%04x, len=%d, peer=%04x", er->caid, er->prid, er->srvid, er->l, ei->peer); 729 get_cw(cli, er); 730 } 655 731 break; 656 732 default: … … 664 740 static void gbox_send_dcw(struct s_client *cli, ECM_REQUEST *er) 665 741 { 666 // TODO 742 struct gbox_data *gbox = cli->gbox; 743 744 if( er->rc >= E_NOTFOUND ) { 745 cs_log("gbox: unable to decode!"); 746 //TODO: send something back?? 747 return; 748 } 749 750 uchar buf[45]; 751 uint32_t crc = gbox_get_ecmchecksum(er); 752 struct gbox_ecm_info *ei = er->src_data; 753 754 memset(buf, 0, sizeof(buf)); 755 756 gbox_code_cmd(buf, MSG_CW); 757 memcpy(buf + 2, gbox->peer.key, 4); 758 buf[6] = er->pid; 759 buf[7] = er->pid; 760 buf[8] = er->srvid >> 8; 761 buf[9] = er->srvid & 0xff; 762 buf[10] = gbox->id >> 8; 763 buf[11] = gbox->id & 0xff; 764 buf[12] = 0x10 | (er->ecm[0] & 1); 765 buf[13] = er->caid >> 8; 766 memcpy(buf + 14, er->cw, 16); 767 buf[30] = crc >> 24; 768 buf[31] = crc >> 16; 769 buf[32] = crc >> 8; 770 buf[33] = crc & 0xff; 771 buf[34] = er->caid >> 8; 772 buf[35] = er->caid & 0xff; 773 buf[36] = ei->ncards; 774 buf[37] = ei->extra >> 8; 775 buf[38] = ei->extra & 0xff; 776 buf[39] = ei->peer; 777 buf[40] = ei->peer; 778 buf[41] = er->pid >> 8; 779 buf[42] = er->pid & 0xff; 780 buf[43] = ei->unknwn1; 781 782 gbox_send(cli, buf, 45); 667 783 } 668 784 … … 773 889 774 890 gbox->hello_expired = 1; 891 gbox->hello_initial = 1; 775 892 776 893 gbox_send_hello(cli);
Note:
See TracChangeset
for help on using the changeset viewer.